slugify override and default

This commit is contained in:
yuki 2025-10-18 02:56:07 -03:00
parent 8f8d7c317b
commit 96e180703b
Signed by: yuki
GPG key ID: 0C98E6FF04EC3915

View file

@ -1,8 +1,7 @@
module.exports = {
eleventyComputed: {
// TODO: handle titles as slugs instead of filenames
permalink: (data) => {
// get the file path stem, e.g., "/es/blog/2025/2025-10-18-my-post"
permalink: function (data) {
// get the file path stem
let stem = data.page.filePathStem;
// extract the year from the path
@ -12,14 +11,14 @@ module.exports = {
// check for slug_override first
if (data.slug_override) {
return `/es/blog/${year}/${data.slug_override}/index.html`; // ie /es/blog/2025/post-localizado/index.html
return `/es/blog/${year}/${this.slugify(data.slug_override)}/index.html`;
}
// handle blog posts with date prefix: /es/blog/[year]/[year-month-day]-slug
const blogPostMatch = stem.match(/^\/es\/blog\/(\d{4})\/\d{4}-\d{2}-\d{2}-(.+)$/);
if (blogPostMatch) {
const [, , slug] = blogPostMatch;
return `/es/blog/${year}/${this.slugify(slug)}/index.html`; // ie /es/blog/2025/my-post/index.html
return `/es/blog/${year}/${this.slugify(slug)}/index.html`;
}
}