slugify override and default
This commit is contained in:
parent
8f8d7c317b
commit
96e180703b
1 changed files with 4 additions and 5 deletions
|
|
@ -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`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue