Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itpropro/hexo-tag-ghcode
Hexo plugin to insert code from GitHub
https://github.com/itpropro/hexo-tag-ghcode
Last synced: 10 days ago
JSON representation
Hexo plugin to insert code from GitHub
- Host: GitHub
- URL: https://github.com/itpropro/hexo-tag-ghcode
- Owner: itpropro
- License: mit
- Created: 2019-07-08T10:57:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T20:32:22.000Z (about 1 year ago)
- Last Synced: 2024-12-08T19:40:53.771Z (18 days ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hexo-tag-github-code
**Taken over from [hexo-tag-github-code](https://github.com/itpropro/hexo-tag-ghcode), as the author [nkmk](https://github.com/nkmk) has stopped maintaining the repository.**
Insert code from [GitHub](https://github.com/) when static files are generated.
Not embed.
## Install
```sh
$ npm install hexo-tag-github-code --save
```## Usage
```
{% ghcode URL [start_line stop_line] [options] %}
```## Support URL
### GitHub / Gist
- URL of each file page as below
- https://github.com/itpropro/hexo-tag-ghcode/blob/master/index.js
- https://gist.github.com/nkmk/d60cdbcffdb60d624ac01871543f79a2
- https://gist.github.com/nkmk/d60cdbcffdb60d624ac01871543f79a2#file-sample-py
- URL links to raw file as below
- https://raw.githubusercontent.com/itpropro/hexo-tag-ghcode/master/index.js
- https://gist.githubusercontent.com/nkmk/d60cdbcffdb60d624ac01871543f79a2/raw/e7528c00addcdd0b4d00cb9bbd8d225cc132fbfc/sample.py
- URL of github permalink
- https://github.com/itpropro/hexo-tag-ghcode/blob/master/index.js#L5-L16
- https://github.com/itpropro/hexo-tag-ghcode/blob/master/index.js#L116### Other site
If URL links to raw file, it will work.## Options
Set like as `{cap:false,re:true,lang:javascript}`. Please do __NOT__ insert any spaces.
| option | description | default |
| :--- | :--- | :--- |
| cap| `true`: show caption
`false`: no caption | `true` |
| re| `true`: the first line number restart from 1
`false`: the first line number start from original code number | `false` |
| lang| the language to use for highlighting | the extension of the file |### Config setting
You can change default settings in `_config.yml` as below.
```yml
github_code:
cap: false
re: true
```## Examples
### Full code
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js %}
```### Selected lines
Insert code from line 17 to line 22.
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js 17 22 %}
```![Selected lines](https://i.gyazo.com/babfb9ad3851b5a3f4267636ccc8a70d.png)
### Without caption
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js 17 22 {cap:false} %}
```![Without caption](https://i.gyazo.com/d1e0f94c5041371fc26e5bdc9033edf6.png)
### Restart the first line number from 1
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js 17 22 {re:true} %}
```![Restart the first line number from 1](https://i.gyazo.com/dc3611fc637352bbe5c57bf7d94f60f2.png)
### Force the language highlighting to HTML for a JavaScript file
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js 17 22 {lang:html} %}
```