ruby - 在 Middleman 中移动博客文章位置

标签 ruby blogs middleman

我正在为我的网站使用 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/

相关文章:

ruby-on-rails - rails : Validation in model vs migration

ruby - 错误 : You must `brew link pcre' before nginx can be installed

compass-sass - compass/中间人图片网址不起作用

css - 链接与其附加到 [中间人] css html 的图像分离

ruby-on-rails - Rails 的通用播种数据是否存在?

mysql - rake db :create not working for legacy rails app (2. 3.5) 使用 MySQL (5.5.28)

css - 在 Wordpress 主题(The Fox)上隐藏博客文章作者

php - Laravel 没有将所有数据插入数据库

python - 我怎样才能使我的 Django 应用程序的这篇随机博客文章重定向更有效率

ruby - config.rb 和页面中的中间人变量可见性