Github generator for hexo.
JavaScript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
README_zh.md
index.js
package.json

README.md

hexo-generator-github

Build Status node npm downloads npm version GitHub release

Github generator for Hexo.

Installation

$ npm install hexo-generator-github --save

Usage

hexo-generator-github can be used as helper/generator/console plugin. hexo server and hexo generate will call the generator of this plugin; A console command is provided to run this generator.

$ hexo github [-r --replace]

If -r or --replace option assigned, the generator will call github api and replace the existing github cache.

Config

github:
  debug: true
  cache_dir: gh_cache
  user: Jamling
  repos: 
    - hexo-theme-nova
    - hexo-generator-github
    - hexo-generator-i18n
  • debug: Whether print debug info
  • cache_dir: Github response cache dir
  • user: Github user name
  • repos: Result repositories, return all repositories of user if undefined in _config.yml

Front-matter

A gh front-matter is nessary in your page to generate github response.

  • gh.user the github user, default is github.user in _config.yml, see gh_opts
  • gh.repo the github repo, default is fetched from url, see gh_opts
  • gh.type
    • get_repos get repositories from github, see gh_repos
    • get_contents get markdown file under repository, see gh_contents
    • get_releases get releases under repository, see gh_releases

Helpers

gh_opts

Return full page.gh. If no user assigned in page gh front-matter, the user will set from hexo.config.github.user If no repo assigned in page gh front-matter, the repo will set from page.path Sample:

  • page.path = p/Android-ORM/ => gh.repo = Android-ORM
  • page.path = en/p/Android-ORM/ => gh.repo = Android-ORM (The hexo.config.language must contains en in _config.yml)

gh_repos

Return array of github user's repos

  {% for p in gh_repos() %}
    <!--<div class="col-sx-6 col-sm-6 col-md-6 col-lg-6">-->
      <div class="panel panel-default" id="project">
        <div class="panel-heading">
        
          <h3>
          <a href="https://github.com/{{p.owner.login}}/">{{p.owner.login}}</a>
          /
          <a href="./{{ p.name }}"> {{ p.name }}</a>
          </h3>
        </div>
        <div class="panel-body">
          <p>{{ p.description }}</p>
        </div>
        <div class="panel-footer">
        </div>
      </div>
    <!--</div>-->
  {% endfor %}
Option Description Default
user Github user config.github.user

gh_contents

Return github (markdown file) contents of repository

{% set page.content = gh_contents({path: 'README'}) %}

So the page content will be replaced of content of github.

Option Description Default
user Github user config.github.user
repo Github repo page.gh.repo
path Github content path README
ref Github reference master

gh_edit

Return edit link string of github contents

{{ gh_edit({path: 'README'}) }}
Option Description Default
user Github user config.github.user
repo Github repo page.gh.repo
path Github content path README
ref Github reference master

gh_releases

Return array of github repo releases

{% for p in gh_releases() %}
<div class="release">
  <div class="header">
    <a href="{{p.html_url}}">{{p.name}}</a>
    <a href="{{p.author.html_url}}">{{p.author.login}}</a> released this on {{gh_time(p.published_at)}}
  </div>
  <div class="markdown-body">
    {{markdown(p.body)}}
  </div>
  <h2 class="release-downloads-header">Downloads</h2>
  <ul class="release-downloads">
    {% for d in p.assets %}
    <li><a href="{{d.browser_download_url}}">
      <strong>{{d.name}}</strong> ({{d.download_count}} downloads)</a>
    </li>
    {%- endfor %}
  </ul>
</div>
{% endfor %}
Option Description Default
user Github user config.github.user
repo Github repo page.gh.repo

Reference

License

MIT