mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 15:42:39 +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 sanitizeFilename = require('sanitize-filename');
|
||||||
const asyncHandler = require('express-async-handler');
|
const asyncHandler = require('express-async-handler');
|
||||||
|
|
||||||
|
const { DEFAULT_BREW } = require('./brewDefaults.js');
|
||||||
|
|
||||||
const splitTextStyleAndMetadata = (brew)=>{
|
const splitTextStyleAndMetadata = (brew)=>{
|
||||||
brew.text = brew.text.replaceAll('\r\n', '\n');
|
brew.text = brew.text.replaceAll('\r\n', '\n');
|
||||||
if(brew.text.startsWith('```metadata')) {
|
if(brew.text.startsWith('```metadata')) {
|
||||||
@@ -405,6 +407,7 @@ if(isLocalEnvironment){
|
|||||||
//Render the page
|
//Render the page
|
||||||
const templateFn = require('./../client/template.js');
|
const templateFn = require('./../client/template.js');
|
||||||
app.use(asyncHandler(async (req, res, next)=>{
|
app.use(asyncHandler(async (req, res, next)=>{
|
||||||
|
const brew = _.defaults(req.brew, DEFAULT_BREW);
|
||||||
// Create configuration object
|
// Create configuration object
|
||||||
const configuration = {
|
const configuration = {
|
||||||
local : isLocalEnvironment,
|
local : isLocalEnvironment,
|
||||||
@@ -414,7 +417,7 @@ app.use(asyncHandler(async (req, res, next)=>{
|
|||||||
const props = {
|
const props = {
|
||||||
version : require('./../package.json').version,
|
version : require('./../package.json').version,
|
||||||
url : req.originalUrl,
|
url : req.originalUrl,
|
||||||
brew : req.brew,
|
brew : brew,
|
||||||
brews : req.brews,
|
brews : req.brews,
|
||||||
googleBrews : req.googleBrews,
|
googleBrews : req.googleBrews,
|
||||||
account : req.account,
|
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 asyncHandler = require('express-async-handler');
|
||||||
const { nanoid } = require('nanoid');
|
const { nanoid } = require('nanoid');
|
||||||
|
|
||||||
// Default brew properties in most cases
|
const { DEFAULT_BREW, DEFAULT_BREW_LOAD } = require('./brewDefaults.js');
|
||||||
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 getTopBrews = (cb) => {
|
// const getTopBrews = (cb) => {
|
||||||
// HomebrewModel.find().sort({ views: -1 }).limit(5).exec(function(err, brews) {
|
// 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???
|
// 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;
|
if(typeof objValue === 'boolean') return objValue;
|
||||||
return objValue || srcValue;
|
return objValue || srcValue;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user