gh-cdn
v1.0.0
Published
A simple cli tool to upload images to github and use github as a mini cdn.
Maintainers
Readme
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 runninggh auth login.gh-cdnrelies on the GitHub CLI to get your authentication token.
Installation
You can install gh-cdn globally via npm:
npm install -g gh-cdnUsage
To upload an image, run the gh-cdn command followed by the repository path and the local path to your image file:
gh-cdn <repo_path> <image_path>Arguments
<repo_path>(Required): The name of your GitHub repository in the formatusername/reponame.- Example:
my-username/my-repo
- Example:
<image_path>(Required): The local path to the image file you want to upload.- Example:
./docs/images/picture.pngor~/Pictures/screenshot.png
- Example:
Examples
Upload an image to your my-blog repository:
gh-cdn your-username/my-blog ./content/images/my-awesome-image.jpgUpload a screenshot from your home directory:
gh-cdn another-user/project-docs ~/Screenshots/dashboard-screenshot.pngOutput
Upon successful upload, gh-cdn will print a JSON object containing various URLs and SHAs related to the uploaded image:
{
"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.
