Untitled post in Jekyll

On my Jekyll blog, I would like some posts to have no title. How can I modify the Jekyll codebase to make it so that the messages do not need a header?

+6
source share
3 answers

You do not need to modify jekyll codebase to remove names. This can be done using various layouts with appropriate filters and tags for liquids.

For individual mail pages, simply create a new layout file (for example, "_layouts / no-title-post.html") that does not have the {{ page.title }} tag. In the _posts source file, specify the front YAML task to invoke it. For instance:

 --- layout: no-title-post --- 

Note that the YAML header does not require "title:". If jekyll needs it, the value will be automatically packed from the file name. For example, "_posts / 2012-04-29-a-new-post.md" will automatically change its title variable to "A New Post". If your templates do not call header tags, that doesn't matter. You can include a β€œtitle:” in the front element, and it just won’t display.

You can also display a page without a title on listing / index pages. Check the message layout to determine if the title should be displayed. For example, to display headings on all of your pages except those that have a no-title-post layout, you would do something like this:

 {% for post in paginator.posts %} {% if post.layout != 'no-title-post' %} <h1><a href="{{ post.url }}">{{ post.title }}</a></h1> {% endif %} <div class="postContent"> {{ post.content }} </div> {% endfor %} 

In this case, the link to the page is also deleted. If the page should be an address, you will need to add the link to another location.

+8
source

edemundo solution does not work in all cases with Jekyll 3.

I use the default empty header:

 defaults: - scope: type: "posts" values: layout: "post" title: "" 

Then you can compare the titles with the empty string in your layouts, for example:

 {% if post.title == "" %} {{ post.content | strip_html | truncatewords:5 }} {% else %} {{ post.title }} {% endif %} 

If you like the automatic creation of a header, you can use it as a frontmatter:

 --- title: "" --- 
+2
source

I had the same doubts, then I came across this very simple solution:

 {% if post.title %} <h1><a href="{{ post.url }}">{{ post.title }}</a></h1> {% endif %} 

And then in the message file itself you leave the title variable empty:

 --- layout: post title: --- 

Thus, h1 will not print if the title is empty. I found this method especially useful for message types, such as quotation marks, which most of the time have no names.

+1
source

Source: https://habr.com/ru/post/914430/


All Articles