diff --git a/app.js b/app.js index 6f9a47b..1ea9c7a 100644 --- a/app.js +++ b/app.js @@ -12,7 +12,6 @@ const helmet = require('helmet'); const colors = require('colors'); const common = require('./lib/common'); const mongodbUri = require('mongodb-uri'); - let handlebars = require('express-handlebars'); // Validate our settings schema @@ -66,14 +65,16 @@ const app = express(); // view engine setup app.set('views', path.join(__dirname, '/views')); -app.engine('hbs', handlebars({extname: 'hbs', layoutsDir: path.join(__dirname, 'views', 'layouts'), defaultLayout: 'layout.hbs'})); +app.engine('hbs', handlebars({ + extname: 'hbs', + layoutsDir: path.join(__dirname, 'views', 'layouts'), + defaultLayout: 'layout.hbs', + partialsDir: [ path.join(__dirname, 'views') ] +})); app.set('view engine', 'hbs'); // helpers for the handlebar templating platform handlebars = handlebars.create({ - partialsDir: [ - 'views/partials/' - ], helpers: { perRowClass: function(numProducts){ if(parseInt(numProducts) === 1){ @@ -159,6 +160,12 @@ handlebars = handlebars.create({ } return options.inverse(this); }, + toLower: function (value){ + if(value){ + return value.toLowerCase(); + } + return null; + }, formatDate: function (date, format){ return moment(date).format(format); }, @@ -222,6 +229,7 @@ app.use(session({ // serving static content app.use(express.static(path.join(__dirname, 'public'))); +app.use(express.static(path.join(__dirname, 'views', 'themes'))); // Make stuff accessible to our router app.use((req, res, next) => { diff --git a/lib/common.js b/lib/common.js index 42cf8c5..69bcc6d 100644 --- a/lib/common.js +++ b/lib/common.js @@ -148,7 +148,7 @@ exports.checkDirectorySync = (directory) => { }; exports.getThemes = () => { - return fs.readdirSync(path.join('public', 'themes')).filter(file => fs.statSync(path.join(path.join('public', 'themes'), file)).isDirectory()); + return fs.readdirSync(path.join(__dirname, '../', 'views', 'themes')).filter(file => fs.statSync(path.join(path.join(__dirname, '../', 'views', 'themes'), file)).isDirectory()); }; exports.getImages = (dir, req, res, callback) => { @@ -206,7 +206,7 @@ exports.getConfig = () => { config.theme = 'Cloth'; // Default to Cloth theme } - config.themeViews = '../public/themes/' + config.theme + '/'; + config.themeViews = '../views/themes/' + config.theme + '/'; // if db set to mongodb override connection with MONGODB_CONNECTION_STRING env var config.databaseConnectionString = process.env.MONGODB_CONNECTION_STRING || config.databaseConnectionString; @@ -458,6 +458,10 @@ exports.getData = (req, page, query) => { skip = (page - 1) * numberProducts; } + if(!query){ + query = {}; + } + query['productPublished'] = 'true'; // Run our queries diff --git a/public/themes/Cloth/page.hbs b/public/themes/Cloth/page.hbs deleted file mode 100644 index 4aa7412..0000000 --- a/public/themes/Cloth/page.hbs +++ /dev/null @@ -1,64 +0,0 @@ -