Skip to content

Commit

Permalink
Partially revert "Fix"
Browse files Browse the repository at this point in the history
This reverts commit f606a5d.

Revert "Partially revert f5c2ddf and f89e10f"

This reverts commit f09a244.
  • Loading branch information
XhmikosR committed Apr 21, 2020
1 parent f606a5d commit ad74409
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,14 @@ function generateBodyClass(pathname) {
}

function selectedTheme(selected) {
if (typeof selected === 'undefined' || selected === '') {
const totalThemes = files.bootswatch4.themes.length;
const theme = Number.parseInt(selected, 10);

if (Number.isNaN(theme) || theme < 0 || theme >= totalThemes) {
return app.theme;
}

const theme = Number.parseInt(selected, 10);

return theme === 0 || theme ?
theme :
app.theme;
return theme;
}

function getTheme(selected) {
Expand All @@ -115,25 +114,13 @@ function getTheme(selected) {
};
}

function getThemeQuery(req) {
const totalThemes = files.bootswatch4.themes.length;
const query = Number.parseInt(req.query.theme, 10);

// Safety checks
if (Number.isNaN(query) || query < 0 || query >= totalThemes) {
return '';
}

return query;
}

function appendLocals(req, res) {
const siteUrl = getCurrentSiteurl(req);
const pageUrl = req.originalUrl;
// OK, hack-ish way...
const pathname = pageUrl.split('?')[0];
const canonicalUrl = new URL(pathname, app.siteurl);
const theme = getThemeQuery(req);
const theme = selectedTheme(req.query.theme);
const bodyClass = generateBodyClass(pathname);

const locals = {
Expand Down

0 comments on commit ad74409

Please sign in to comment.