在Jekyll中获得这种“自定义"永久链接方案的步骤是什么? [英] What are the steps to getting this 'custom' permalink scheme in Jekyll?

查看:80
本文介绍了在Jekyll中获得这种“自定义"永久链接方案的步骤是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Jekyll设置,我想让我的帖子具有以下格式的永久链接:/2013/jan/something-something-in-january.我了解使用香草永久链接无法实现:

I'm writing a Jekyll setup and I'd like to get my posts to have a permalink in the form: /2013/jan/something-something-in-january. I understand that it is impossible with vanilla permalinks to:

  • :month设置为文本形式
  • 使:title以短划线分隔
  • get the :month to be in text form or
  • get the :title to be dash delimited

我记得在某处读到我可以通过编写插件来实现这一目标,但我不确定如何实现.我该怎么办?

I remember reading somewhere that I could achieve this by writing a plugin, but I'm not sure how. How can I do this?

推荐答案

我创建了一个生成器插件:

I created a generator plugin:

module Jekyll
    class PermalinkRewriter < Generator
        safe true
        priority :low

        def generate(site)
            # Until Jekyll allows me to use :slug, I have to resort to this
            site.posts.each do |item|
                item.data['permalink'] = '/' + item.slug + '/'
            end
        end
    end
end

这篇关于在Jekyll中获得这种“自定义"永久链接方案的步骤是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆