diff --git a/apps/synapse-portal-framework/sitemap/generate-sitemap.cjs b/apps/synapse-portal-framework/sitemap/generate-sitemap.cjs index a2a7a646cf..e36b772d49 100644 --- a/apps/synapse-portal-framework/sitemap/generate-sitemap.cjs +++ b/apps/synapse-portal-framework/sitemap/generate-sitemap.cjs @@ -23,19 +23,39 @@ fs.readFile(`src/config/${fileName}`, (err, data) => { ) } - const baseUrl = `https://${args[0]}.synapse.org` + // strip surrounding double quotes (if exist) + const portalName = args[0].replace(/^"|"$/g, '') + const baseUrl = `https://${portalName}.synapse.org` const now = new Date().toISOString() let fileContent = '\n\n' - var regex = /path[:]\s*\'(.*)\'/g + var regex = /^(\s*)path:\s*'(.*)'/gm var m - + // Discover the paths by relying on the linter to set up the spaces correctly, then we find all of the "path" entries in the routesConfig file + var currentNestedPath = new Array(100) + var previousNestingSpaceCount = -1 do { m = regex.exec(routesConfigContent) + // m[1] contains the leading spaces + // m[2] contains the target path if (m) { - // assuming hash router - let path = `${m[1]}` - fileContent += `\t\n\t\t${baseUrl}/${path}\n\t\t${now}\n\t\n` + const spaceCount = m[1].length + let newPath = `${m[2]}`.replaceAll(' ', '%20') + if (spaceCount <= previousNestingSpaceCount) { + //reset from space count + currentNestedPath.forEach((_value, index) => { + if (index >= spaceCount) { + currentNestedPath[index] = undefined; + } + }) + currentNestingSpaceCount = 0 + } + previousNestingSpaceCount = spaceCount + currentNestedPath[spaceCount] = newPath + const currentPath = currentNestedPath.filter(value => value !== undefined).join('/') + if (!newPath.match('^[:]slug.*')) { + fileContent += `\t\n\t\t${baseUrl}/${currentPath}\n\t\t${now}\n\t\n` + } } } while (m) fileContent += ''