diff --git a/script.js b/script.js index fb573ae..cbd7a9b 100644 --- a/script.js +++ b/script.js @@ -84,6 +84,16 @@ function applyTranslations() { // =========================== // HELPERS // =========================== +function postSlug(title) { + return title.toLowerCase() + .replace(/[äå]/g, 'a').replace(/ö/g, 'o').replace(/ü/g, 'u') + .replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, ''); +} + +function findPostBySlug(slug) { + return APP.posts.find(p => postSlug(p.title) === slug); +} + function sortSubcategories(subs) { return [...subs].sort((a, b) => { const aM = a.fi.toLowerCase() === 'muut' ? 1 : 0; @@ -343,6 +353,7 @@ async function openPost(id) {