Skip to content

Commit

Permalink
Move getCurrentSiteurl() in helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 16, 2020
1 parent 04f5b24 commit 2e3bbd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
19 changes: 15 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ const { app, files } = require('../config');
const PUBLIC_DIR = path.join(__dirname, '../public/');
const SRI_CACHE = {};

function capitalize(str) {
if (typeof str !== 'string') {
return '';
}

return str.charAt(0).toUpperCase() + str.slice(1);
}

function generateSri(file, fromString) {
if (typeof SRI_CACHE[file] === 'undefined') {
file = fromString ? file : fs.readFileSync(path.join(PUBLIC_DIR, file));
Expand Down Expand Up @@ -70,12 +78,14 @@ function generateDataJson() {
return data;
}

function capitalize(str) {
if (typeof str !== 'string') {
return '';
function getCurrentSiteurl(req) {
let proto = req.get('x-forwarded-proto');

if (typeof proto === 'undefined') {
proto = req.protocol;
}

return str.charAt(0).toUpperCase() + str.slice(1);
return `${proto}://${req.hostname}`;
}

function getPageTitle(pageTitle) {
Expand Down Expand Up @@ -103,6 +113,7 @@ module.exports = {
get: getTheme,
selected: selectedTheme
},
getCurrentSiteurl,
getPageTitle,
generateBodyClass,
generateSri
Expand Down
15 changes: 4 additions & 11 deletions routes/appendLocals.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
'use strict';

const { app, files } = require('../config');
const { generateBodyClass } = require('../lib/helpers');

function getCurrentSiteurl(req) {
let proto = req.get('x-forwarded-proto');

if (typeof proto === 'undefined') {
proto = req.protocol;
}

return `${proto}://${req.hostname}`;
}
const {
getCurrentSiteurl,
generateBodyClass
} = require('../lib/helpers');

function getThemeQuery(req) {
const totalThemes = files.bootswatch4.themes.length;
Expand Down

0 comments on commit 2e3bbd3

Please sign in to comment.