hack了hexo-renderer-pandoc的一个疑似错误

故事背景

博客终于重新开张了。兴冲冲地配置好最新版的hexo-theme-NexT, 并把hexo的markdown渲染引擎按照wzpan的Customization的方法进行配置,发现总是出现错误。我也不懂nodejs,只能用笨方法逐项排查,最后发现是extra这一项出现了错误。

解决方法

按照作者wzpan的方法,我的配置文件原本应该是:

1
2
3
4
5
6
7
8
9
# hexo-renderer-pandoc
pandoc:
filters:
- pandoc-crossref
- pandoc-citeproc
extra:
bibliography: "/home/nirvana6/workspace/blog/blog.bib"
meta:
- link-citations: true

可是,无论如何,当我编译markdown时,总是报错。这时候,不懂nodejs和javascript等一些列网页前端知识的,靠着强大的逻辑, 调试、解决了这个问题。装逼过程如下:

1. wzpan在前文给出extra的配置是:

1
2
extra:
- key: valu

而在后文给出的demo却是:

1
2
extra:
bibliography: "/path/to/bibfile.bib"

bibliography前面怎么少了一个-?有蹊跷!

2. 解决办法是啥?

man pandoc读了一会儿帮助文件,忽然发现这么一段:

–bibliography=FILE

Set the bibliography field in the document’s metadata to FILE, overriding any value set in the metadata, and process citations using pan‐ doc-citeproc. (This is equivalent to –metadata bibliography=FILE –filter pandoc-citeproc.) If –natbib or –biblatex is also supplied, pan‐ doc-citeproc is not used, making this equivalent to –metadata bibliography=FILE. If you supply this argument multiple times, each FILE will be added to bibliography.

也就是说,除了hexo-renderer-pandoc所示例的(将bibliography当作mapping),还可以把bibliography这一项当成metadata。而wzpan的 meta就是干这个的。于是,就有了下面这个配置.

1
2
3
4
5
6
7
8
9
# hexo-renderer-pandoc
pandoc:
filters:
- pandoc-crossref
- pandoc-citeproc
extra:
meta:
- bibliography: "/home/nirvana6/workspace/blog/blog.bib"
- link-citations: true

作为示范,我这里引用了一个文献(Ford, Pitt Ford, and Babinsky 2012)。完美!

References

Ford, Charles Pitt, Charles Pitt Ford, and Holger Babinsky. 2012. “Lift and the Leading Edge Vortex.” In 50th Aiaa Aerospace Sciences Meeting Including the New Horizons Forum and Aerospace Exposition. Aerospace Sciences Meetings. Nashville, Tennessee: American Institute of Aeronautics; Astronautics. https://doi.org/doi:10.2514/6.2012-911.

Donate comment here
Show comments from Gitment