diff --git a/en/blog/blog.11tydata.js b/en/blog/blog.11tydata.js new file mode 100644 index 0000000..5529a94 --- /dev/null +++ b/en/blog/blog.11tydata.js @@ -0,0 +1,30 @@ +module.exports = { + eleventyComputed: { + // TODO: handle titles as slugs instead of filenames + permalink: (data) => { + // get the file path stem ie "/en/blog/2025/2025-10-18-my-post" + let stem = data.page.filePathStem; + + // strip the leading /en/ prefix + if (stem.startsWith("/en/")) { + stem = stem.replace(/^\/en/, ""); + } + + // for blog posts under /blog/[year]/[year-month-day]-blogpost + // extract the year and the blog post slug (remove date prefix) + const blogPostMatch = stem.match(/^\/blog\/(\d{4})\/\d{4}-\d{2}-\d{2}-(.+)$/); + if (blogPostMatch) { + const [, year, slug] = blogPostMatch; + return `/blog/${year}/${slug}/index.html`; // ie /blog/2025/my-post/index.html + } + + // fallback for index or other pages under /blog + if (stem.endsWith("/index")) { + return `${stem}.html`; // ie /blog/index.html + } + + // default for non-index, non-blog-post pages + return `${stem}/index.html`; + } + } +}; diff --git a/es/blog/blog.11tydata.js b/es/blog/blog.11tydata.js new file mode 100644 index 0000000..a73f13b --- /dev/null +++ b/es/blog/blog.11tydata.js @@ -0,0 +1,35 @@ +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 + } + } +}; \ No newline at end of file