我正在尝试为我的 Middleman 网站创建一个索引文件,并希望在该文件中包含我页面的原始“内容”。即
/source/mypage.md:
---
title: My Page
---
# This is my page
With *my markdown*
和
/source/myotherpage.md:
---
title: My Other Page
---
# Here is my other page
我想要位于 /source/site_index.json.erb
的第三个页面,输出如下所示:
[
{'title': 'My Page', 'body': '#This is my page\nWith *my markdown\n'},
{'title': 'My Other Page', 'body': '#Here is my other page\n'}
]
我可以使用类似的方法获取标题等,但我不知道如何获取原始正文:
[
<% sitemap.resources.select{|resource| resource.content_type == 'text/html; charset=utf-8' unless resource.data.ignore }.each do |resource| %>
{
"title": <%= resource.data.title.to_json %>,
"body": <%= nil %>
} ,
<% end %>
]
最佳答案
以前从未使用过 Middleman,但您尝试过 resource.render
吗?
根据http://rubydoc.info/gems/middleman-core/Middleman/Sitemap/Resource#render-instance_method处的文档看起来应该可以。
另一个潜在的线索是以下对 raw_body_content
的引用:https://github.com/middleman/middleman-sitemap-api/blob/master/lib/middleman-sitemap-api/extension.rb#L122
希望这有帮助
关于ruby - 如何从所有页面获取原始 "content",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25219509/