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/
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With