Node version(node -v): v6.5.0
Hexo and Plugin version(npm ls --depth 0):
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
I have a translation blog powered by Hexo. In many articles I need to provide links to original English pages, and most of them starts with the same prefix. Here is a example:
This [content][1] is available on [GitHub][2].
// in the page end
[1]: https://example.com/blob/master/example
[2]: https://example.com/example
In Jekyll maybe we can use this:
[1]: { site.url }/blob/master/example
[2]: { site.url }/example
I try to define a var named userDefUrl in config.yml and use {% config.userDefUrl %} in the page content(NOT front-matter), and get a render error:
Template render error: (unknown path) [Line 2, Column 160]
unknown block tag: config
at Object.exports.prettifyError...
I've searching for similar issues, and found #2209 , but seems not matching my case. Does Hexo actually support this usage? Thanks!
~以下为中文(貌似Hexo有很多中文大神在维护,因此再用中文描述一遍)~
我尝试使用Hexo为某个项目做翻译站,但是翻译文章需要大量引用原文链接,而原文链接基本上都是开始于同一个网站地址,原项目使用Jekyll, 它的引用方式是 {site.url}/relative_links。我希望在我的Hexo站点上也能这么使用,避免硬编码站点地址,也可以减小译文和原文的差异。
但是我在 #2209 上看到的方式似乎只是在页面模板中使用。请问在Markdown文件中能否套用这种方案(即使需要额外插件也可以)?
谢谢指教!
可以写个tag来实现,但好像目前没有其它好办法,因为Post中以文本信息为主,并不支持编程。
@Muyangmin 是的,通过标签插件访问config参数。
由于md文件主要是用来写文章,如果再加入访问变量参数等功能,会有些混淆,无法很好的分离数据和逻辑。
这里应该还不用插件,只需要脚本即可。
如何使用脚本请参考Hexo自身网站脚本https://github.com/hexojs/site/blob/master/scripts/tags.js
如果还有问题,请尽管提出。
@NoahDragon 问题解决了一半……
我在项目路径下创建了一个目录 scripts,在其中新建了一个site_url.js,以下是内容:
/* global hexo */
'use strict';
hexo.extend.tag.register("site_url", function (args, content) {
return "http://example.com";
})
然后在post文章正文中这么使用:
<!-- 这里尝试直接输出 -->
{% site_url %}
额外添加[``选项(Options)``][2]
[2]: {% site_url %}/somelink
最终结果:
http://example.com
额外添加[选项(Options)][2]
[2]: http://example.com/somelink
可以看到,标签内容确实插入成功了。不过插入时机不能满足我的想法,我希望在Markdown文件解析之前替换,这样[2]的链接才能正确解析,请问可以做到么?
请问你这个问题完美解决了没?我也有类似的需求
@Muyangmin 注册针对before_post_render的filter插件即可,修改data.content就行了
@unnamed42 谢谢 👍
Japanese ! realy ?
Japanese ! realy ?
No, it's chinese :)
But, I pretty much understand what they say. Do you need a help about this issue ?
@YoshinoriN thank you very much! I thought it would be helpful to access some configuration entries from markdown files ex: root
@g13013
Currently hexo can not get _config.yml valuse.
But you can get these valuse using by tag helper make by yourself like this.
At first, create tag helper's JavaScript and put it theme/script.
'use strict';
const config = hexo.config;
hexo.extend.tag.register("site_url",() => {
return config.url;
});
Second, use that tag helper in your post like this.
{% site_url %}
I wrote example. Please see it.
I made a plugin.
Please try it if you'd like.
Most helpful comment
No, it's chinese :)
But, I pretty much understand what they say. Do you need a help about this issue ?