UNPKG

gh-cdn

Version:

A simple cli tool to upload images to github and use github as a mini cdn.

76 lines (49 loc) 2.31 kB
# gh-cdn `gh-cdn` is a command-line tool that simplifies uploading images to your GitHub repositories. I use GitHub as a mini cdn for my personal blog. ## Features * Uploads local image files directly to a specified GitHub repository. * Provides both the jsDelivr CDN URL and the raw GitHub URL for the uploaded image. ## Prerequisites Before using `gh-cdn`, you need to have the following installed and configured: * **Node.js:** Make sure you have Node.js installed on your system. * **GitHub CLI (`gh`):** Install the GitHub CLI and authenticate it by running `gh auth login`. `gh-cdn` relies on the GitHub CLI to get your authentication token. ## Installation You can install `gh-cdn` globally via npm: ```bash npm install -g gh-cdn ``` ## Usage To upload an image, run the `gh-cdn` command followed by the repository path and the local path to your image file: ```bash gh-cdn <repo_path> <image_path> ``` ----- ### Arguments * **`<repo_path>` (Required):** The name of your GitHub repository in the format `username/reponame`. * *Example:* `my-username/my-repo` * **`<image_path>` (Required):** The local path to the image file you want to upload. * *Example:* `./docs/images/picture.png` or `~/Pictures/screenshot.png` ----- ### Examples Upload an image to your `my-blog` repository: ```bash gh-cdn your-username/my-blog ./content/images/my-awesome-image.jpg ``` Upload a screenshot from your home directory: ```bash gh-cdn another-user/project-docs ~/Screenshots/dashboard-screenshot.png ``` ----- ### Output Upon successful upload, `gh-cdn` will print a JSON object containing various URLs and SHAs related to the uploaded image: ```json { "url": "https://github.com/your-username/your-repo/blob/main/path/to/your/image.jpg", "raw_github_url": "https://raw.githubusercontent.com/your-username/your-repo/main/path/to/your/image.jpg", "download_url": "https://raw.githubusercontent.com/your-username/your-repo/main/path/to/your/image.jpg", "jsdelivr_url": "https://cdn.jsdelivr.net/gh/your-username/your-repo@main/path/to/your/image.jpg", "sha": "a1b2c3d4e5f6...", "commit_sha": "x1y2z3a4b5c6..." } ``` You can then use the `jsdelivr_url` for a fast CDN-backed image, or `raw_github_url` for direct access to the file on GitHub.