npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hexo-deployer-git-ksh

v0.0.2

Published

Git deployer plugin of Hexo.

Downloads

9

Readme

hexo-deployer-git

CI NPM version Coverage Status

Git deployer plugin for Hexo.

Notice: Fatal HttpRequestException Error on pushing to GitHub?

Update Git for Windows to the latest version. (Details)

Installation

$ npm install hexo-deployer-git --save

Options

You can configure this plugin in _config.yml.

# You can use this:
deploy:
  type: git
  repo: <repository url>
  branch: [branch]
  token: ''
  message: [message]
  name: [git user]
  email: [git email]
  extend_dirs: [extend directory]
  ignore_hidden: false # default is true
  ignore_pattern: regexp  # whatever file that matches the regexp will be ignored when deploying

# or this:
deploy:
  type: git
  message: [message]
  repo: <repository url>[,branch]
  extend_dirs:
    - [extend directory]
    - [another extend directory]
  ignore_hidden:
    public: false
    [extend directory]: true
    [another extend directory]: false
  ignore_pattern:
    [folder]: regexp  # or you could specify the ignore_pattern under a certain directory

# Multiple repositories
deploy:
  repo:
    # Either syntax is supported
    [repo_name]: <repository url>[,branch]
    [repo_name]:
      url: <repository url>
      branch: [branch]
  • repo: Repository settings, or plain url of your repo
    • url: Url of your repositury to pull from and push to. If you've configured SSH key authentication for git, ensure you use the SSH protocol format (for example, [email protected]:) for your repository URL to avoid password prompts or access denial due to security policies.
    • branch: Optional git branch to deploy the static site to.
      • Defaults to gh-pages on GitHub.
      • Defaults to coding-pages on Coding.net.
      • Otherwise defaults to master.
    • token: Optional token value to authenticate with the repo. Prefix with $ to read token from environment variable (recommended). Repo must be a http(s) url. More details.
    • repo_name: Unique name when deploying to multiple repositories.
      • Example:
      deploy:
        repo:
          # Either syntax is supported
          github: https://github.com/user/project.git,branch
          gitee:
            url: https://gitee.com/user/project.git
            branch: branch_name
  • branch: Git branch to deploy the static site to. Branch name specified in repo: takes priority.
  • message: Commit message. Defaults to Site updated: {{ now("yyyy-MM-dd HH:mm:ss") }}.
  • name and email: User info for committing the change, overrides global config. This info is independent of git login.
  • extend_dirs: Additional directories to publish. e.g demo, examples
  • ignore_hidden (Boolean|Object): whether ignore hidden files to publish. GitHub requires the .nojekyll in root.
    • Boolean: for all dirs.
    • Object: for public dir and extend dir:
      • public: the public dir defaults.
      • [extend directory]
  • ignore_pattern (Object|RegExp): Choose the ignore pattern when deploying
    • RegExp: for all dirs.
    • Object: specify the ignore pattern under certain directory. For example, if you want to push the source files and generated files at the same time to two different branches. The option should be like
    # _config.yaml
    deploy:
      - type: git
        repo: [email protected]:<username>/<username>.github.io.git
        branch: master
      - type: git
        repo: [email protected]:<username>/<username>.github.io.git
        branch: src
        extend_dirs: /
        ignore_hidden: false
        ignore_pattern:
            public: .

Deploy with token

While this plugin can parse authentication token from the config, only use this method if you are sure the config will not be committed, including to a private repo. A more secure approach is to add it to the CI as an environment variable, then simply add the name of the environment variable to this plugin's config (e.g. $GITHUB_TOKEN).

Additional guides:

  • Create a GitHub Personal Access Token. [Link]
  • Add authentication token to Travis CI. [Link]

Important Notice: Force Push Behavior

The hexo-deployer-git plugin employs a force push (git push --force) strategy when deploying updates to your site. This approach ensures that the remote repository aligns exactly with your local deployment, providing a clean, consistent state for each update. However, it comes with an important consideration regarding custom modifications.

Impact of Force Push

Using force push means that any changes made directly in the remote repository (e.g., via GitHub's web interface or through a separate git workflow) will be overwritten when the next deployment occurs. This is because force push does not merge changes; it replaces the remote content with the local version entirely.

How to Safely Manage Your Site

To prevent unintended loss of work, we strongly advise adhering to the following best practices:

  1. Centralize Changes in Your Hexo Source: Make all content and configuration changes within your local Hexo root directory. This ensures all modifications are included in the deployment process and preserved in your source control.

  2. Avoid Direct Remote Modifications: Refrain from directly editing files in the GitHub repository through the web interface or other git methods. Doing so could lead to these changes being lost on the next deployment.

Custom Domain Issue with CNAME File

If you are using a custom domain with GitHub Pages, you might have encountered an issue where your custom domain configuration gets lost after deploying updates to your site. This problem occurs due to the overwritten / deletion of the CNAME file in the root of the deployed directory during the git commit and push process performed by the hexo-deployer-git plugin.

GitHub requires the CNAME file to be present in your repository to associate your custom domain with your GitHub Pages site. When this file is missing, GitHub resets the custom domain setting, leading to the site being accessible only through the default github.io domain.

Solution

To ensure your custom domain remains active with each deployment, you need to include the CNAME file in your blog's source/ directory. Here's how you can do it:

  1. Create a CNAME File: In the root of your blog's source/ directory, create a file named CNAME. Inside this file, enter your custom domain name. For example, if your custom domain is example.com, the content of the CNAME file should be:
    example.com
  2. Deploy Your Site: Use the hexo-deployer-git plugin to deploy your site as usual. Run hexo g -d command, the plugin will now include the CNAME file in the deployment, and your custom domain configuration will remain intact.

How it works

hexo-deployer-git works by generating the site in .deploy_git and force pushing to the repo(es) in config. If .deploy_git does not exist, a repo will initialized (git init). Otherwise the curent repo (with its commit history) will be used.

Users can clone the deployed repo to .deploy_git to keep the commit history.

git clone <gh-pages repo> .deploy_git

Reset

Remove .deploy_git folder.

$ rm -rf .deploy_git

License

MIT