是否可以使用asciidoc和hakyll?

mhe*_*rzl 3 haskell asciidoc pandoc hakyll

我按照本教程使用hakyll创建了一个基本的静态网页.它包括从posts目录中的markdown呈现的多个页面,例如2015-08-12-spqr.markdown.

我更喜欢asciidoc到markdown,并尝试2018-01-23_adoc-user-manual.asciidocpost目录中添加asciidoc .但是,hakyll在尝试编译页面时抛出错误:

Initialising...
  Creating store...
  Creating provider...
  Running rules...
Checking for out-of-date items
Compiling
  updated templates/default.html
  updated about.rst
  updated templates/post.html
  updated posts/2015-08-12-spqr.markdown
  updated posts/2015-10-07-rosa-rosa-rosam.markdown
  updated posts/2015-11-28-carpe-diem.markdown
  updated posts/2015-12-07-tu-quoque.markdown
  [ERROR] Hakyll.Web.readPandocWith: I don't know how to read a file of the type Binary for: posts/2018-01-23_adoc-user-manual.asciidoc
CallStack (from HasCallStack):
  error, called at lib/Hakyll/Web/Pandoc.hs:66:31 in hakyll-4.12.5.0-8ZITvFN5YREEKv6B76SCAd:Hakyll.Web.Pandoc
Run Code Online (Sandbox Code Playgroud)

这个问题pandocCompiler无法处理asciidoc吗?是否有可能使用asciidochakyll

ymo*_*nad 8

当前的Pandoc可以编写Asciidoc但无法读取它:问题.

此外,似乎没有用Haskell编写的Asciidoc解析器,因此没有纯Haskell解决方案.

但是,Hakyll有unixFilter,它可以使用从stdin输出的任何命令并输出到stdout.因此,您可以调用asciidoctor命令转换.asciidoc文件.

这是步骤:

1.安装asciidoctor

Ubuntu的

$ apt-get install asciidoctor

Fedora的

$ dnf install asciidoctor

Arch Linux

$ pacman -S asciidoctor

红宝石宝石

$ gem install asciidoctor

2.定义pandocCompilerWithAsciidoctor

添加以下代码 site.hs

pandocCompilerWithAsciidoctor :: Compiler (Item String)
pandocCompilerWithAsciidoctor = do
  extension <- getUnderlyingExtension
  if extension == ".asciidoc" then
    getResourceString >>= withItemBody (unixFilter "asciidoctor" ["-"])
  else
    pandocCompiler
Run Code Online (Sandbox Code Playgroud)

替换pandocCompilersite.hspandocCompilerWithAsciidoctor

3.重新编译

$ stack build
$ stack exec site rebuild
Run Code Online (Sandbox Code Playgroud)

请注意,必须2018-01-23-adoc-user-manual.asciidoc代替文件名2018-01-23_adoc-user-manual.asciidoc,否则会出现错误:[ERROR] Missing field $date$ in context for item posts/2018-01-23_adoc-user-manual.asciidoc