Skip to content

Commit 57ae3ee

Browse files
authored
Merge pull request #1019 from ExpressionEngine/bug/7.x/page-404
fixes for 404 page
2 parents d62a859 + 0593552 commit 57ae3ee

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/utility.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const bsToFs = (p) => p.replace(/\\/g, '/')
2222
// Gets the folder depth of the specified path
2323
const dirDepth = (myDir) => myDir.split(Path.sep).length
2424

25-
const returnEmbedContents = (match, p1, p2, p3, offset, string) => {
25+
const returnEmbedContents = (match, p1, p2, p3, offset, string) => {
2626
console.log("Found Embed: " + p1);
2727
try {
2828
embedContents = Fs.readFileSync('./docs/'+p1, { encoding: 'utf8' });
@@ -40,18 +40,18 @@ const renderTemplate = (template, vars, currentPageInfo) => {;
4040
template = template.replace(new RegExp('{{\\s*' + key + '\\s*}}', 'gi'), value)
4141
}
4242

43-
43+
4444
template = template.replace(new RegExp('(?<!code>){{embed\:([^"\']*?)}}', 'gi'),returnEmbedContents);
4545

4646
return template
4747
}
4848

49-
// Gets the relative path to the source dir from a docs page
49+
// Gets the relative path to the source dir from a docs page, returning a web-safe path
5050
const getRelativeRootFromPage = (pagePath) => {
5151
let depth = dirDepth(pagePath) - dirDepth(Path.resolve(CONFIG.sourceDir))
52-
let relPath = ('..' + Path.sep).repeat(depth - 1)
53-
54-
return relPath
52+
if (depth <= 1) return './';
53+
let relPath = '../'.repeat(depth - 1);
54+
return relPath.replace(/\/+$/, '') + '/';
5555
}
5656

5757
// Returns a function that will slugify a heading and also handle future duplicate slugs when called again

0 commit comments

Comments
 (0)