【问题标题】:Moving blog articles location in Middleman在 Middleman 中移动博客文章位置
【发布时间】:2013-01-14 12:09:50
【问题描述】:

我正在为我的网站使用 Middleman Blog gem,但默认情况下,博客文章似乎需要位于 /source那里的其他文件(例如模板)。

通过查看文档,我看不出是否有任何方法可以移动博客文章,以便将它们存储在其他位置,例如 blog_articles 文件夹或类似文件夹。

这可能吗?

【问题讨论】:

    标签: ruby blogs middleman


    【解决方案1】:

    将以下内容放入您的 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.permalinksetting 中删除 .html。像这样:

    activate :blog do |blog|
      blog.permalink = ":year-:month-:day-:title"
      blog.sources = "blog_articles/:title.html"
    end
    

    现在您可以通过以下网址查看您的帖子:http://localhost:4567/2012-01-01-example-article

    【讨论】:

    • 最新的中间人和 rails 4 对我来说失败了,feed.xml 失败了,它仍然写入 /posts/* 博客文章
    【解决方案2】:

    我搞砸了中间人博客扩展,但因为它相对不透明而放弃了。但是,在查看the source 时,似乎prefix 选项可能对您有用吗?有点不清楚前缀是 URL 前缀还是本地路径前缀:

    activate :blog do |blog|
      blog.prefix = "/blog_articles"
    end
    

    【讨论】:

    • 嗯,奇怪。源似乎是从 File 对象加载的,这让我认为它适合这里的目的。哦,好吧。
    【解决方案3】:

    通过查看它发生的代码,您可以使用:sources 选项。如果您在源代码中四处寻找,则有一个示例:

    https://github.com/middleman/middleman-blog/tree/master/fixtures/article-dirs-app

    【讨论】:

    • 我看到了,但是很困惑,因为默认的 :sources 选项似乎更多地是关于文件名格式:options.sources ||= ":year-:month-:day-:title.html"
    • 这里也是,直到我看到带有文件夹前缀的灯具,灯泡才亮。
    【解决方案4】:

    当我对永久链接/源配置选项进行以下更改时,上述解决方案对我有用:

    blog.permalink = ":title.html"
    blog.sources   = "posts/:year-:month-:day-:title.html"
    

    永久链接是它将出现在网络浏览器 url 中的位置,其中源是帖子的位置。

    使用中间人 3.2.1

    【讨论】:

      【解决方案5】:

      我在源目录中创建了博客文件夹。然后我创建帖子目录并将我所有的帖子移到那里。来源/博客/帖子/...

      然后在 config.rb 中

      activate :blog do |blog|
      ..........
        blog.permalink = "blog/:year/:month/:day/:title.html"
        blog.sources = "blog/posts/:year-:month-:day-:title.html"
        .........
      end
      

      【讨论】:

      • 现在所有的 url 都以 /blog 为前缀
      猜你喜欢
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      • 2013-08-29
      • 1970-01-01
      • 2016-05-18
      • 1970-01-01
      相关资源
      最近更新 更多