Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
fix default redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
JingleH committed Jun 26, 2023
1 parent 621d6eb commit acfcd31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
17 changes: 17 additions & 0 deletions express/scripts/content-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getMetadata,
titleCase,
createTag,
getHelixEnv,
} from './scripts.js';
import fetchAllTemplatesMetadata from './all-templates-metadata.js';

Expand Down Expand Up @@ -215,3 +216,19 @@ await (async function updateMetadataForTemplates() {
browseByCat.remove();
}
}());

(function validatePage() {
const env = getHelixEnv();
const title = document.querySelector('title');
if ((env && env.name !== 'stage') && getMetadata('live') === 'N') {
window.location.replace('/express/templates/');
}

if (title && title.innerText.match(/{{(.*?)}}/)) {
window.location.replace('/404');
}

if (env && env.name !== 'stage' && window.location.pathname.endsWith('/express/templates/default')) {
window.location.replace('/404');
}
}());
18 changes: 1 addition & 17 deletions express/scripts/template-redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,14 @@
* governing permissions and limitations under the License.
*/

import { getHelixEnv, getLocale, getMetadata } from './scripts.js';
import { getLocale } from './scripts.js';
import fetchAllTemplatesMetadata from './all-templates-metadata.js';

async function existsTemplatePage(url) {
const allTemplatesMetadata = await fetchAllTemplatesMetadata();
return allTemplatesMetadata.some((e) => e.url === url);
}

(function validatePage() {
const env = getHelixEnv();
const title = document.querySelector('title');
if ((env && env.name !== 'stage') && getMetadata('live') === 'N') {
window.location.replace('/express/templates/');
}

if (title && title.innerText.match(/{{(.*?)}}/)) {
window.location.replace('/404');
}

if (env && env.name !== 'stage' && window.location.pathname.endsWith('/express/templates/default')) {
window.location.replace('/404');
}
}());

(async function redirectToExistingPage() {
// TODO: check if the search query points to an existing page. If so, redirect.
const params = new Proxy(new URLSearchParams(window.location.search), {
Expand Down

0 comments on commit acfcd31

Please sign in to comment.