0
我正在研究一個插件來解析所有帖子,並將它們收集到JSON文件中以供搜索機制使用。 我怎樣才能訪問這個帖子的文本,沒有標記?我目前訪問site.posts
,然後例如page.content
循環。這將返回帖子的內容,但包含換行符標記(\n
)和Markdown語法。從Jekyll插件訪問無標記帖子和頁面內容
我看到有人想要get Markdown processed content in a Jekyll tag plugin的另一個問題,但我的情況是不同的:我根本不需要任何標記,只是文章的純文本,沒有格式應用。
以下是我目前實施的關鍵def
。
def generate(site)
target = File.open('js/searchcontent.js', 'w')
target.truncate(target.size)
target.puts('var tipuesearch = {"pages": [')
all_but_last, last = site.posts[0..-2], site.posts.last
# Process all posts but the last one
all_but_last.each do |page|
tp_page = TipuePage.new(
page.data['title'],
"#{page.data['tags']} #{page.data['categories']}",
page.url,
page.content
)
target.puts(tp_page.to_json + ',')
end
# Do the last post
tp_page = TipuePage.new(
last.data['title'],
"#{last.data['tags']} #{last.data['categories']}",
last.url,
last.content
)
target.puts(tp_page.to_json)
target.puts(']};')
target.close
end
這些是液體過濾器,無法從插件Ruby腳本訪問。我需要完全在此插件文件中完成此操作。 – Tohuw 2015-02-23 14:32:31