Website: Follow up to strip leading slashes (#6843)
* Website: Follow up to strip leading slashes re https://github.com/fleetdm/fleet/pull/6796#issuecomment-1193054810 * remove log * Verified: whitespace trim not needed And leading slash trim is only needed if using a regex route (not something I recommend most of the time). But since we are using one, I included it, and put it in all three places for consistency. (It doesn't ever hurt)
This commit is contained in:
@@ -45,8 +45,8 @@ module.exports = {
|
||||
: SECTION_URL_PREFIX + '/' + pageUrlSuffix// « individual content page
|
||||
)
|
||||
});
|
||||
if (!thisPage) {// If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with internal slashes deduped, and any trailing slash or whitespace trimmed
|
||||
let revisedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(/\/+/g, '/').replace(/^\/+\s*|\/+\s*$/,'');
|
||||
if (!thisPage) {// If there's no EXACTLY matching content page, try a revised version of the URL suffix that's lowercase, with all slashes deduped, and any leading or trailing slash removed (leading slashes are only possible if this is a regex, rather than "/*" route)
|
||||
let revisedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(/\/+/g, '/').replace(/^\/+/,'').replace(/\/+$/,'');
|
||||
thisPage = _.find(sails.config.builtStaticContent.markdownPages, { url: SECTION_URL_PREFIX + '/' + revisedPageUrlSuffix });
|
||||
if (thisPage) {// If we matched a page with the revised suffix, then redirect to that rather than rendering it, so the URL gets cleaned up.
|
||||
throw {redirect: thisPage.url};
|
||||
|
||||
Reference in New Issue
Block a user