Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include subdirectory as part of Jekyll's post URL

Tags:

I am building a blog in both English and Spanish languages. My intention is to access the default content, in Spanish, directly from the base url: http://blog/ and the English content from http://blog/en.

I already have all the code to loop through posts only in English or Spanish when paginating by checking the locale variable that I set in every post front matter. Although my blog posts don't have the same filename, I link them using another variable in the front matter called ref.

So for post A, in Spanish, and post B, in English, I'll have something like this:

2018-01-01-post-A.md

---
locale: en
ref: my-ref
---
foo

2019-01-04-post-B.md:

---
locale: es
ref: my-ref
---
bar

My question is: where do I put my English posts so that they can be accessed through http://blog/en/post-name/?

Those posts already have their categories apart from their language, so putting them inside /en/_posts wouldn't work, as when specifying the permalink in _config.yml to something like permalink: /:categories/:year/:month/:title/ would make the url look like http://blog/en/category-1/category-2/post-name.

Defining a permalink in each English post is also not an option, since I'd like them to be generated from the post data (date and title).

Is there something that I'm missing that would let me use /en/ as part of the URL as I want?

Both the menu language selector and the pagination work, displaying only posts in the selected language. However, when hovering over the posts in english, although I put them inside _posts/en, the subfolder doesn't become part of the url. The same happens when I try the opposite, creating a new folder in the project root named en and adding all the English posts inside it, leaving me with something like en/_posts/

like image 945
Samer Avatar asked Jan 14 '19 21:01

Samer


1 Answers

You could set a frontmatter default for your english pages.

# _config.yml

defaults:
-
    scope:
      locale: "en" # To sort by locale. You could also sort by path.
      type: "posts"
    values:
      permalink: en/:categories/:year/:month/:title/
like image 136
Robert Buchberger Avatar answered Jan 29 '23 18:01

Robert Buchberger