如何在Octopress上启用rdiscount额外降价'generate_toc'

时间:2013-12-08 05:07:37

标签: octopress tableofcontents rdiscount

我尝试通过配置_config.yml使Octopress使用默认的markdown解析器Rdiscount(2.1.7)生成TOC,但它不起作用且rake generate失败。
我在RDiscount :generate_toc with Sinatra尝试过答案,但它对我来说也不适用 所以我想知道是否有办法配置Octopress Rdiscount额外降价语法如下:

markdown: rdiscount
rdiscount: 
  extensions:
    - autolink
    - footnotes
    - smart
    - generate_toc

_config.yml rake generate中设置rdiscount后,我收到了如下构建错误:

sunnogo@a3e420:~/github/octopress$ rake generate
## Generating Site with Jekyll                                                                                                        
identical source/stylesheets/screen.css                                                                                               
Configuration from /home/sunnogo/github/octopress/_config.yml                                                                         
Building site: source -> public                                                                                                       
Liquid Exception: can't convert nil into String in atom.xml                                                                           
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/converters/markdown.rb:139:in `include?'                                            
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/converters/markdown.rb:139:in `convert'                                             
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/filters.rb:25:in `markdownify'                                                      
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/context.rb:58:in `invoke'                                                            
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/variable.rb:43:in `block in render'                                                  
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/variable.rb:38:in `each'                                                             
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/variable.rb:38:in `inject'                                                           
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/variable.rb:38:in `render'                                                           
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:94:in `block in render_all'                                                 
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `collect'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `render_all'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:116:in `block (2 levels) in render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:104:in `each'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:104:in `each_with_index'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:104:in `block in render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/context.rb:91:in `stack'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/tags/for.rb:103:in `render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:94:in `block in render_all'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `collect'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `render_all'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/block.rb:82:in `render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/template.rb:124:in `render'
/var/lib/gems/1.9.1/gems/liquid-2.3.0/lib/liquid/template.rb:132:in `render!'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/convertible.rb:79:in `do_layout'
/home/sunnogo/github/octopress/plugins/post_filters.rb:167:in `do_layout'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/page.rb:100:in `render'
/home/sunnogo/github/octopress/plugins/category_generator.rb:100:in `write_category_index'
/home/sunnogo/github/octopress/plugins/category_generator.rb:111:in `block in write_category_indexes'
/home/sunnogo/github/octopress/plugins/category_generator.rb:110:in `each'
/home/sunnogo/github/octopress/plugins/category_generator.rb:110:in `write_category_indexes'
/home/sunnogo/github/octopress/plugins/category_generator.rb:139:in `generate'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/site.rb:190:in `block in generate'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/site.rb:189:in `each'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/site.rb:189:in `generate'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/lib/jekyll/site.rb:40:in `process'
/var/lib/gems/1.9.1/gems/jekyll-0.12.0/bin/jekyll:264:in `<top (required)>'
/usr/local/bin/jekyll:23:in `load'
/usr/local/bin/jekyll:23:in `<main>'
Build Failed

1 个答案:

答案 0 :(得分:3)

您看到的问题归因于a bug in Jekyll that has since been fixed。具体来说,Jekyll假设如果您指定generate_toc,那么您还指定toc_token,这是您可以在文档中写入的字符串,以使Jekyll插入目录。

更新后的_config.yml如下所示:

markdown: rdiscount
rdiscount: 
  extensions:
    - autolink
    - footnotes
    - smart
    - generate_toc
  toc_token: "!TOC"

然后你会在你想要显示目录的地方的降价文件中插入!TOC