handle new structure to strip dates from urls

This commit is contained in:
yuki 2025-10-18 01:20:39 -03:00
parent ea7cbb0543
commit 32feffab2a
Signed by: yuki
GPG key ID: 0C98E6FF04EC3915
2 changed files with 65 additions and 0 deletions

30
en/blog/blog.11tydata.js Normal file
View file

@ -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`;
}
}
};

35
es/blog/blog.11tydata.js Normal file
View file

@ -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
}
}
};