fix: normalized slugs for recipes

This commit is contained in:
Leyla Becker 2026-02-22 11:05:52 -06:00
parent 72b26472c3
commit 928e7aecff
21 changed files with 40 additions and 29 deletions

View file

@ -41,6 +41,17 @@ const getPlantBased = (filePath) => {
return null;
}
const slugify = (text) => {
return text
.toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with hyphens
.replace(/[()]/g, '') // Remove parentheses
.replace(/[^\w-]+/g, '') // Remove non-word chars except hyphens
.replace(/--+/g, '-') // Replace multiple hyphens with single hyphen
.replace(/^-+/, '') // Trim hyphens from start
.replace(/-+$/, ''); // Trim hyphens from end
}
const getSlugFromPath = (filePath) => {
// Normalize the path - remove leading ./ if present
const normalizedPath = filePath.startsWith('./') ? filePath.slice(2) : filePath;
@ -54,12 +65,12 @@ const getSlugFromPath = (filePath) => {
const secondPart = parts[1];
// If it's a .md file at the top level (recipes/foo.md), strip the extension
if (secondPart.endsWith('.md')) {
return path.basename(secondPart, '.md');
return slugify(path.basename(secondPart, '.md'));
}
// Otherwise it's a folder name (recipes/bar/v1.md -> bar)
return secondPart;
return slugify(secondPart);
}
return path.basename(filePath, '.md');
return slugify(path.basename(filePath, '.md'));
}
const getTitleFromSlug = (slug) => {