在Jekyll中,如何更改大写规则以将文件名转换为博客文章标题? [英] In Jekyll, how to change the capitalization rules for converting a file name into a blog post title?

查看:133
本文介绍了在Jekyll中,如何更改大写规则以将文件名转换为博客文章标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图更改Jekyll中博客文章标题的大小写,而不必每次都在yaml标题字段中键入.默认情况下,jekyll将文件2016-02-22-my-blog-title转换为标题我的博客标题",而我希望它成为我的博客标题".

I am trying to change the capitalization of my blog posts titles in Jekyll, without having to type it in the yaml title field every time. By default, jekyll convert the file 2016-02-22-my-blog-title to the title "My Blog Title", and I want it to be "My blog title".

我注意到我可以通过修改_layouts/post.html并更改行来实现此功能

I have noticed that I can achieve this behavior by modifying _layouts/post.html, and changing the line

<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>

<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title | downcase | capitalize}}</a>

但是,这使得无法通过在需要时向yaml字段添加自定义标题来覆盖大写规则.例如,不可能将不是标题的第一个单词的专有名词大写.是否可以更改从文件名生成默认标题的方式,同时仍然允许在yaml fron主题中指定标题时覆盖该默认标题?

However, this makes it impossible to override the capitalization rules by adding a custom title to the yaml field when needed. For example, it is not possible to capitalize a proper noun that is not the first word of the title. Is it possible to change how the default title is generated from the file name, while still allowing this to be overridden when a title is specified in the yaml fron matter?

推荐答案

您必须使用覆盖Jekyll如何生成帖子标题的插件.

You have to use a plugin that overrides how Jekyll generates a title for posts.

这可以通过重写Jekyll Utils模块来完成.

This can be done by overriding Jekyll Utils module.

创建一个包含以下内容的 _plugins/titleize_overrride.rb 文件:

Create a _plugins/titleize_overrride.rb file containing :

module Jekyll
  module Utils
    def titleize_slug(slug)
      slug.split(/[_-]/).join(' ').capitalize
    end
  end
end

这篇关于在Jekyll中,如何更改大写规则以将文件名转换为博客文章标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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