mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 16:22:44 +00:00
Move default brew to app.js
This commit is contained in:
@@ -15,6 +15,8 @@ const serveCompressedStaticAssets = require('./static-assets.mv.js');
|
||||
const sanitizeFilename = require('sanitize-filename');
|
||||
const asyncHandler = require('express-async-handler');
|
||||
|
||||
const { DEFAULT_BREW } = require('./brewDefaults.js');
|
||||
|
||||
const splitTextStyleAndMetadata = (brew)=>{
|
||||
brew.text = brew.text.replaceAll('\r\n', '\n');
|
||||
if(brew.text.startsWith('```metadata')) {
|
||||
@@ -405,6 +407,7 @@ if(isLocalEnvironment){
|
||||
//Render the page
|
||||
const templateFn = require('./../client/template.js');
|
||||
app.use(asyncHandler(async (req, res, next)=>{
|
||||
const brew = _.defaults(req.brew, DEFAULT_BREW);
|
||||
// Create configuration object
|
||||
const configuration = {
|
||||
local : isLocalEnvironment,
|
||||
@@ -414,7 +417,7 @@ app.use(asyncHandler(async (req, res, next)=>{
|
||||
const props = {
|
||||
version : require('./../package.json').version,
|
||||
url : req.originalUrl,
|
||||
brew : req.brew,
|
||||
brew : brew,
|
||||
brews : req.brews,
|
||||
googleBrews : req.googleBrews,
|
||||
account : req.account,
|
||||
|
||||
24
server/brewDefaults.js
Normal file
24
server/brewDefaults.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
// Default brew properties in most cases
|
||||
const DEFAULT_BREW = {
|
||||
title : 'Untitled Brew',
|
||||
description : '',
|
||||
renderer : 'V3',
|
||||
tags : [],
|
||||
systems : [],
|
||||
thumbnail : '',
|
||||
published : false,
|
||||
pageCount : 1,
|
||||
theme : '5ePHB'
|
||||
};
|
||||
// Default brew properties for loading
|
||||
const DEFAULT_BREW_LOAD = _.defaults({
|
||||
renderer : 'legacy',
|
||||
published : true
|
||||
}, DEFAULT_BREW);
|
||||
|
||||
module.exports = {
|
||||
DEFAULT_BREW,
|
||||
DEFAULT_BREW_LOAD
|
||||
};
|
||||
@@ -9,23 +9,7 @@ const yaml = require('js-yaml');
|
||||
const asyncHandler = require('express-async-handler');
|
||||
const { nanoid } = require('nanoid');
|
||||
|
||||
// Default brew properties in most cases
|
||||
const DEFAULT_BREW = {
|
||||
title : 'Untitled Brew',
|
||||
description : '',
|
||||
renderer : 'V3',
|
||||
tags : [],
|
||||
systems : [],
|
||||
thumbnail : '',
|
||||
published : false,
|
||||
pageCount : 1,
|
||||
theme : '5ePHB'
|
||||
};
|
||||
// Default brew properties for loading
|
||||
const DEFAULT_BREW_LOAD = {
|
||||
renderer : 'legacy',
|
||||
published : true
|
||||
};
|
||||
const { DEFAULT_BREW, DEFAULT_BREW_LOAD } = require('./brewDefaults.js');
|
||||
|
||||
// const getTopBrews = (cb) => {
|
||||
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
|
||||
@@ -89,7 +73,7 @@ const getBrew = (accessType, stubOnly = false)=>{
|
||||
}
|
||||
|
||||
// Use _.assignWith instead of _.defaults - does this need to be replicated at all other uses of _.defaults???
|
||||
_.assignWith(stub, DEFAULT_BREW_LOAD, DEFAULT_BREW, (objValue, srcValue)=>{
|
||||
_.assignWith(stub, DEFAULT_BREW_LOAD, (objValue, srcValue)=>{
|
||||
if(typeof objValue === 'boolean') return objValue;
|
||||
return objValue || srcValue;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user