I am trying to localize a date in Jekyll. All information I find seems to be related to plugins that are no longer maintained, don't work, or to something that seems to have existed in Jekyll built-in earlier.
I have post with matter containing a list of dates:
---
events:
- 2023-07-15
---
To display this in a friendly manner, I use:
{% assign friendly_date = e | date: "%A %e %B %Y" %}
This displays the weekday & month in English, but our website is in Dutch.
So how can we force this to be in Dutch?
Can you tell Jekyll to localize by default in Dutch?
Can you force it in the CI/CD pipeline perhaps, that would also work (using GitLab)?
I did find some plugins for multilingual websites, but that all seems overcomplicated since our website is in one single language.
Related
Using Jekyll to build a site, I have discrepancies between my local build and what GitHub pages renders.
I have a .html layout that uses the date property of the page for the title:
<h1>Meeting notes - {{ page.date | date_to_string }}</h1>
and the date is obtained thanks to the page's name YYYY-MM-DD-notes.html.
I then use a for loop to parse through all the meetings I have in site.meetings and display all meeting notes after one another in a meetings.html page.
My last two files are called: 2021-12-07-notes.html and 2022-01-18-notes.html so the first two titles in my meetings page should be:
Meeting notes - 18 Jan 2022
Meeting notes - 07 Dec 2021
Which is indeed what I get in my local build (along with all the previous ones, first meeting being in 2019).
But what GitHub pages renders is:
Meeting notes -
Meeting notes - 07 Dec 2021
As if he couldn't 'see' the 2022 date. Still working fine with all previous dates btw and again, on the local build.
Could someone explain this weird behavior?
Ok this was simply because I didn't have the right file name.
The file was actually called 2022-01-18_notes.md and not 2022-01-18-notes.md which made GitHub pages not recognise the date. Apparently my local jekyll is a bit more tolerant.
What I'm trying to do
Jekyll can use front matter variables like tags and categories and access them with site.tags and site.categories to iterate over them using liquid.
Now my problem is that I can't do this with a custom front matter variable like author (as in site.authors) because Jekyll will not store it in a list format. This makes it very hard to paginate it.
The problem
Every solution I have looked at i.e.
how to handle multiple authors in Jekyll
adding authors to Jekyll
jekyll-author
requires me to hardcode a list of authors to _config.yml or some other .yml (i.e. in _data/authors.yml).
The problem here is that I don't use a fixed list of authors. The authors list needs to get updated when I throw in another post with a front-matter tag author: exampleAuthor or a list of authors (as in multiple authors per post, as currently only possible with categories and tags as well), while the server is running. It works with tags and categories splendidly, but not with custom tags like authors.
The easiest solution would to have a site.authors list to iterate over and just extending it with a ruby plugin.
I haven't found a plugin that provides me with a solution and thinking this was a common problem that I'm probably not the first to have.
What I tried
I then looked at writing my own ruby plugin (Which is hard on it's own because of the lack of documentation. Maybe I'm to dumb to google, but the resources I found where very limited and hardly enough to guide you through the process) but there has to be a reason why this is so hard to do that makes all the existing solutions require hard-coding the author list in a .yml (or .json, but most people go with .yml for some reason).
Doing this is out of the question for me, since I want to only throw in posts with author names in it later on and manipulating a .yml (I am under the impression that .yml-files don't get compiled once the server is started, like _config.yml, correct me if I'm wrong) would be counterproductive because it requires you to restart the server to have them compiled.
Even very advanced plugins like jekyll-paginate-v2 (which I use successfully to paginate posts by tags and categories) don't have a solution to this, as shown by this issue. As per this issue, it is getting recommended to misuse the category variable to paginate by author. In my opinion, that is desperate workaround and too hacky to be considered.
I have found suggestions that it could also be done with collections, but this would again
requiring to hard-coding the author list (again, I don't want that. I don't have a fixed list of authors. All of the author information has to come from the front-matter in the /_posts directory .md files)
As of now I don't see how it can be done with collections.
However I'm open to suggestions.
Edit: I found this dated issue on Jekylls github page which highlights that people are trying to do the same but to no avail.
Has this become viable in the last 4 years?
For someone still looking for a way to
Generate author pages automatically just by dropping author: name to post front matter,
Have pagination on the author pages (a good optimization).
I built a plugin jekyll-auto-authors that works in sync with jekyll-paginate-v2 to enable author auto pages along with pagination.
I wrote this guide and made this video to help with the setup.
The bare minimum setup instructions:
Install the plugin:
group :jekyll_plugins do
# other gems
gem "jekyll-paginate-v2" # reqiured for jekyll-auto-authors to work
gem "jekyll-auto-authors"
end
Enable it:
plugins:
# other plugins
- jekyll-paginate-v2
- jekyll-auto-authors
Make a data file with author data, for example using _data/authors.yml:
johndoe:
name: "John Doe"
bio: "John Doe is a software engineer."
email: "john#example.com"
socials:
github: "john-doe"
twitter: "john_doe"
janedoe:
name: "Jane Doe"
bio: "Jane Doe is a systems engineer."
email: "jane#example.com"
socials:
github: "jane-doe"
twitter: "jane_doe"
Make a layout for the author page, let's say _layout/author.html. Example layout can be taken from the article.
Enable pagination and auto pages for authors in _config.yml file:
pagination:
enabled: true
per_page: 9
permalink: '/page/:num/'
title: ':title - page :num'
sort_field: 'date'
sort_reverse: true
autopages:
enabled: true
# enable auto pages for tags/categories/collections as per need. Disabling for this demo.
tags:
enabled: false
categories:
enabled: false
collections:
enabled: false
authors:
enabled: true # adding false here stops the auto-generation
data: '_data/authors.yml' # Data file with the author details
layouts:
- 'author.html' # We'll define this layout later, will be used for each author
title: 'Posts by :author'
permalink: '/author/:author/'
slugify:
mode: 'default' # choose from [raw, default, pretty, ascii or latin]
cased: true # if true, the uppercase letters in slug will be converted to lowercase ones.
That's the initial setup!
Now drop in the author value in the front matter of posts:
---
# other configs
author: johndoe
---
This will generate a page as defined in the permalink block of the auto pages configuration. If there's pagination enabled, and per_page value is exceeded, the additional pages will be generated in /page/:num/ format.
To render the author values, the plugin exposes page.pagination.author_data value
{% assign author = page.pagination.author_data %}
<!-- Use {{ author.name }} or any such value, as defined inside the data file -->
To show next and previous buttons, you can use this logic that paginator exposes:
{% if paginator.total_pages > 1 %}
<ul>
{% if paginator.previous_page %}
<li>
Newer
</li>
{% endif %}
{% if paginator.next_page %}
<li>
Older
</li>
{% endif %}
</ul>
{% endif %}
The initial setup is overwhelming, but once done you can then just drop in author data inside _data/authors.yml file and add author: value inside post frontmatter and it is fairly easy then!
P.S. I developed this solution for Genics Blog as managing multiple authors got hard. To learn how I've implemented it at Genics, please check out the theme-files repository.
Update
I released v1.0.1 just now, which makes adding the data parameter to author autopage configuration optional.
If data isn't defined, you can still access the author username string with page.pagination.author. You can use it to show the username on the page.
If data is defined, page.pagination.author_data variable is available. This would be a hashmap that has data as defined in the data file.
This means that you just have to:
Add and enable the plugin.
Set up pagination and author pages config.
Make a layout file.
And you can just drop in author: username to post files to generate autopages for them with pagination!
Adding authors to Jekyll posts is easy with collections. Here's a proof of concept for you. Specifically, in this commit I add everything you need for it.
As for your question about pagination, will need to use a pagination plugin (paginate-v2 is good), as I believe the built in pagination only supports the posts collection.
I have a complex Jekyll website. Every change can take a few minutes to generate.
On my local machine I can see the progress that tells me when the re-generation finished.
However on GitHub Pages (Enterprise) how do I know if what I am looking at is the latest version or if it is still generating?
I was thinking maybe Jekyll could print a timestamp somewhere when generating?
You can use <p>Page version : {{ site.time | date: '%B %d, %Y - %H:%M:%S %Z'}}</p> in you footer to print datetime on each page.
Don't forget to set your timezone variable in configuration.
TL;DR: Can I say somehow to generate the content for a {% include %} once and just stamp it out in multiple places without having to regenerate it in every location?
I'm building a fairly big documentation site with Jekyll which has right now a bit over 50 articles on it. It has a sidebar where all articles are listed. the sidebar is built in a separate sidebar.html and then it is included into every page on the site with {% include sidebar.html %} in default.html.
The problem I have is that every single article runs the generation of sidebar.html separately, so I have over 50 generation passes on that piece of code. Every article I add adds another pass to this and make all the passes a bit slower, as generating the sidebar has to parse every single article in the project.
Build time has gone up from basically zero to over 100 seconds already, and if I remove the {% include sidebar.html %} then it drops down to 5 seconds. When I get all the articles in I'd estimate to have around 100-200 of them. Then I should have versioning in the future for all articles which means that there can easily be 1000+ articles in the long run. At that point I wouldn't be suprised if changing one letter in one file would take something like an hour to regenerate files in jekyll serveand jekyll build.
What I would like to do is to build sidebar.html once in the beginning of the build process and just stamp it out to every page when i generate said pages. Is this possible?
Fastest way to do this.
Move _includes/sidebar.html to sidebar-template.html
Add this front matter :
---
layout: null
permalink: sidebar-template.html
---
Create a Rakefile
TPL = "_site/sidebar-template.html"
TST = "_includes/sidebar.html"
task :default => :nav
desc "Generates sidebar then copy it to be used as an include"
task :nav do
if !File.exist?(TST)
puts "Creating dummy #{TST} file"
open(TST, 'w') do |f|
f.puts warning
end
end
puts "Building Jekyll 1st run"
system "jekyll build --trace"
# delete target file (TST) if exist
if File.exist?(TST)
puts "#{TST} exists deleting it"
rm TST
end
# copy generated file as an include
cp(TPL, TST)
puts "Building Jekyll AGAIN"
system "jekyll build --trace"
puts "task END"
end
Just run rake and you have your sidebar include generated.
There is now a better way to do this, thanks to Ben Balter.
instead of: {% include yourtemplate.html %}
use: {% include_cached yourtemplate.html %}
When used on larger items that need to be built once, such as a site hierarchy, the item will be cached. For other items that vary across pages, you'll still want to use the include as you always have done.
It is explained well here: https://github.com/benbalter/jekyll-include-cache
Definitely cuts down on site startup time!
I am trying to set up a blog on github.io using jekyll (site, source)
My problem is that my article in the _posts folder semms to be ignored. I would like to debug the site generation.
I have seen this advice to debug jekyll, but so far I did not understood what is missing.
Can I see if jekyll consider my file or if it is ignored?
In your files names replace underscore by hyphen.
wrong : 2014-11-01_part_of_it.md
good : 2014-11-01-part-of-it.md
the article/post needs a publish date in the front matter
---
date: 2014-11-01 08:57:00 GMT
---
Also keep in mind that your post won't be generated if the publishing date (including the daylight saving time, in my case) is in the future.
date: 2018-07-18 18:00:00 +0100
Reading: _posts/2018-07-18-no-more-ssh-login.markdown
Skipping: _posts/2018-07-18-no-more-ssh-login.markdown has a future date
Had to run bundle exec jekyll serve --verbose to realize it.