gh-cdn
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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:

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:

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:

gh-cdn your-username/my-blog ./content/images/my-awesome-image.jpg

Upload a screenshot from your home directory:

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:

{
    "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.

Package Sidebar

Install

npm i gh-cdn

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

3.08 kB

Total Files

2

Last publish

Collaborators

  • sammaji15