From 0593552f2d90d2c33558fc627b6d0b45a196b037 Mon Sep 17 00:00:00 2001 From: Yulya Lebed Date: Tue, 29 Jul 2025 09:09:20 +0200 Subject: [PATCH] changes script to return correct 404 page if it deeper the 1 level --- scripts/utility.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/utility.js b/scripts/utility.js index 6e80e76d1..d31ff532b 100644 --- a/scripts/utility.js +++ b/scripts/utility.js @@ -22,7 +22,7 @@ const bsToFs = (p) => p.replace(/\\/g, '/') // Gets the folder depth of the specified path const dirDepth = (myDir) => myDir.split(Path.sep).length -const returnEmbedContents = (match, p1, p2, p3, offset, string) => { +const returnEmbedContents = (match, p1, p2, p3, offset, string) => { console.log("Found Embed: " + p1); try { embedContents = Fs.readFileSync('./docs/'+p1, { encoding: 'utf8' }); @@ -40,18 +40,18 @@ const renderTemplate = (template, vars, currentPageInfo) => {; template = template.replace(new RegExp('{{\\s*' + key + '\\s*}}', 'gi'), value) } - + template = template.replace(new RegExp('(?){{embed\:([^"\']*?)}}', 'gi'),returnEmbedContents); return template } -// Gets the relative path to the source dir from a docs page +// Gets the relative path to the source dir from a docs page, returning a web-safe path const getRelativeRootFromPage = (pagePath) => { let depth = dirDepth(pagePath) - dirDepth(Path.resolve(CONFIG.sourceDir)) - let relPath = ('..' + Path.sep).repeat(depth - 1) - - return relPath + if (depth <= 1) return './'; + let relPath = '../'.repeat(depth - 1); + return relPath.replace(/\/+$/, '') + '/'; } // Returns a function that will slugify a heading and also handle future duplicate slugs when called again