Hexo: what does code_dir for? And how to use it?

Created on 16 Jul 2018  ·  2Comments  ·  Source: hexojs/hexo

Firstly thanks for reading this issue.

In _config.yml, I found there's a setting named code_dir: downloads/code.

My understanding

Is this setting means that the author can put any source_code.tar or some files in. And write a download-link into your post.

Tried but not working

  1. Make sure dir /downloads/code is exist.

  2. Put any file in downloads/code. For example. file.tar

  3. In post, write a download_link. like: [download](/downloads/code/file.tar)

Whatever I use /downloads/code/file.tar or downloads/code/file.tar are not right.

Any variable

Is there any elegant way to use variable like <% balabala.foo.bar %> or something like [file](foo.bar) etc...

Thanks

question

Most helpful comment

@demurgos Merci.
One day ago, It's so easy to do it. No more copy&paste just 2 steps.

  1. put your source code in.
    Make sure dir /source/downloads/code existed. And put your source code file in it.
    bash > ls source/downloads/code/ filename.py
  2. Insert a whole script.
    bash {% include_code filename lang:python filename.py %}
    Voilà it works.

All 2 comments

I just looked up "code_dir" on the repo and got this file:
https://github.com/hexojs/hexo/blob/106980eaba36ac6cdc473792edacddfe32c89d97/lib/plugins/tag/include_code.js#L12-L17

Looks like it insert a block of code and adds a download link. The doc comment gives the syntax, but I am not quite sure which engine it uses or how to enable it. (code_dir is used when resolving path/to/file)

@demurgos Merci.
One day ago, It's so easy to do it. No more copy&paste just 2 steps.

  1. put your source code in.
    Make sure dir /source/downloads/code existed. And put your source code file in it.
    bash > ls source/downloads/code/ filename.py
  2. Insert a whole script.
    bash {% include_code filename lang:python filename.py %}
    Voilà it works.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jo4x962k7JL picture jo4x962k7JL  ·  3Comments

Helihua1992 picture Helihua1992  ·  3Comments

yunTerry picture yunTerry  ·  3Comments

lushijie picture lushijie  ·  3Comments

19uni94 picture 19uni94  ·  3Comments