Update view-basic-handbook.js (#2315)

This commit is contained in:
eashaw 2021-10-01 13:47:44 -05:00 committed by GitHub
parent b8a2da21b2
commit f4a196ae41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,14 +41,25 @@ module.exports = {
let thisPage = _.find(sails.config.builtStaticContent.markdownPages, {
url: _.trimRight(SECTION_URL_PREFIX + '/' + _.trim(pageUrlSuffix, '/'), '/')
});
if (!thisPage) {
throw 'notFound';
}
if (false) {
// TODO: add "redirect" exit and handle mismatched capitalization / extra slashes by redirecting to the correct URL. e.g. "http://localhost:2024/docs//usiNG-fleet///" Partial example of this: https://github.com/sailshq/sailsjs.com/blob/b53c6e6a90c9afdf89e5cae00b9c9dd3f391b0e7/api/controllers/documentation/view-documentation.js#L161-L166
let revisedUrl = 'todo';
throw {redirect: revisedUrl};
// Setting a flag if the pageUrlSuffix doesn't match any existing page, or if the page it matches doesn't exactly match the pageUrlSuffix provided
// Note: because this also handles fleetdm.com/handbook and a pageUrlSuffix might not have provided, we set this flag to false if the url is just '/handbook'
let needsRedirectMaybe = (!thisPage || (thisPage.url !== '/handbook/'+pageUrlSuffix && thisPage.url !== '/handbook'));
if (needsRedirectMaybe) {
// Creating a lower case, repeating-slashless pageUrlSuffix
let multipleSlashesRegex = /\/{2,}/g;
let modifiedPageUrlSuffix = pageUrlSuffix.toLowerCase().replace(multipleSlashesRegex, '/');
// Finding the appropriate page content using the modified pageUrlSuffix.
let revisedPage = _.find(sails.config.builtStaticContent.markdownPages, {
url: _.trimRight(SECTION_URL_PREFIX + '/' + _.trim(modifiedPageUrlSuffix, '/'), '/')
});
if(revisedPage) {
// If we matched a page with the modified pageUrlSuffix, then redirect to that.
throw {redirect: revisedPage.url};
} else {
// If no page was found, throw a 404 error.
throw 'notFound';
}
}
// Setting the meta title for this page.
let pageTitleForMeta;