yuki.k4w411.net/es/blog/blog.11tydata.js

35 lines
No EOL
1.4 KiB
JavaScript

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"
let stem = data.page.filePathStem;
// extract the year from the path
const yearMatch = stem.match(/^\/es\/blog\/(\d{4})\//);
if (yearMatch) {
const year = yearMatch[1];
// 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
}
// 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
}
}
// handle index pages or other non-blog-post pages
if (stem.endsWith("/index")) {
return `${stem}.html`; // ie /es/blog/index.html
}
// default for other pages under /es/blog/
return `${stem}/index.html`; // ie /es/other-page/index.html
}
}
};