我正在为我的网站使用 Middleman Blog gem,但默认情况下,博客文章似乎需要位于 /source
中,这在查看 vim 中的树时并不是特别好并尝试在其中找到其他文件之一(例如模板)。
通过查看文档,我看不出是否有任何方法可以移动博客文章,以便将它们存储在其他地方,例如 blog_articles
文件夹或类似文件夹。
这可能吗?
最佳答案
将以下内容放入您的 config.rb 文件中。
activate :blog do |blog|
blog.permalink = ":year-:month-:day-:title.html"
blog.sources = "blog_articles/:title.html"
end
假设您有一篇文章 2012-01-01-example-article.html.markdown
存储在文件夹 source/blog_articles
中。
您现在应该看到带有此 URL 的帖子:http://localhost:4567/2012-01-01-example-article.html
。 (更改 config.rb
文件时,您可能必须重新启动中间人。)
请注意,我还必须设置 blog.permalink
,单独设置 blog.sources
并不能解决问题。
额外提示:我的 config.rb
文件中有 activate :directory_indexes
。此设置为您提供了漂亮的 URL,没有 .html
部分。
如果您希望对您的博客文章使用相同的内容,您可以从 blog.permalink
设置中删除 .html
。像这样:
activate :blog do |blog|
blog.permalink = ":year-:month-:day-:title"
blog.sources = "blog_articles/:title.html"
end
现在您可以使用此 URL 查看您的帖子:http://localhost:4567/2012-01-01-example-article
。
关于ruby - 在 Middleman 中移动博客文章位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14318174/