mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-08 11:52:44 +00:00
move metaTag objects to app.js
This commit is contained in:
@@ -1,42 +1,42 @@
|
|||||||
const template = async function(name, title='', props = {}){
|
const template = async function(name, title='', props = {}){
|
||||||
const HOMEBREWERY_PUBLIC_URL=props.config.publicUrl;
|
// const HOMEBREWERY_PUBLIC_URL=props.config.publicUrl;
|
||||||
|
|
||||||
const ogMeta = {
|
// const ogMeta = {
|
||||||
siteName : 'The Homebrewery - Make your Homebrew content look legit!',
|
// siteName : 'The Homebrewery - Make your Homebrew content look legit!',
|
||||||
title : 'The Homebrewery',
|
// title : 'The Homebrewery',
|
||||||
description : 'Homepage',
|
// description : 'Homepage',
|
||||||
thumbnail : `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`,
|
// thumbnail : `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`,
|
||||||
type : 'website'
|
// type : 'website'
|
||||||
};
|
// };
|
||||||
|
|
||||||
if(props.url.match(/\/share\/|\/edit\//)){
|
// if(props.url.match(/\/share\/|\/edit\//)){
|
||||||
Object.assign(ogMeta, {
|
// Object.assign(ogMeta, {
|
||||||
siteName : null,
|
// siteName : null,
|
||||||
title : props.brew.title || 'Homebrewery - Untitled Brew',
|
// title : props.brew.title || 'Homebrewery - Untitled Brew',
|
||||||
description : props.brew.description || 'No description.',
|
// description : props.brew.description || 'No description.',
|
||||||
image : props.brew.thumbnail || null,
|
// image : props.brew.thumbnail || null,
|
||||||
type : 'article'
|
// type : 'article'
|
||||||
});
|
// });
|
||||||
} else if(props.url.match(/\/print\/|\/source\//)){
|
// } else if(props.url.match(/\/print\/|\/source\//)){
|
||||||
Object.assign(ogMeta, {
|
// Object.assign(ogMeta, {
|
||||||
siteName : null,
|
// siteName : null,
|
||||||
title : props.brew.title ? `${props.brew.title} - ${props.url.match(/\/print\/|\/source\//)}` : 'Homebrewery - Untitled Brew',
|
// title : props.brew.title ? `${props.brew.title} - ${props.url.match(/\/print\/|\/source\//)}` : 'Homebrewery - Untitled Brew',
|
||||||
description : props.brew.description || 'No description.',
|
// description : props.brew.description || 'No description.',
|
||||||
image : props.brew.thumbnail || null,
|
// image : props.brew.thumbnail || null,
|
||||||
type : 'article'
|
// type : 'article'
|
||||||
});
|
// });
|
||||||
} else if(props.url.match(/\/user\//)){
|
// } else if(props.url.match(/\/user\//)){
|
||||||
Object.assign(ogMeta, {
|
// Object.assign(ogMeta, {
|
||||||
siteName : null,
|
// siteName : null,
|
||||||
title : `${props.username} - The Homebrewery`,
|
// title : `${props.username} - The Homebrewery`,
|
||||||
description : `${props.username}'s user page.`,
|
// description : `${props.username}'s user page.`,
|
||||||
image : null,
|
// image : null,
|
||||||
type : 'profile'
|
// type : 'profile'
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
const ogTags = [];
|
const ogTags = [];
|
||||||
Object.entries(ogMeta).forEach(([key, value])=>{
|
Object.entries(props.ogMeta).forEach(([key, value])=>{
|
||||||
if(!value) return;
|
if(!value) return;
|
||||||
const tag = `<meta property="og:${key}" content="${value}">`;
|
const tag = `<meta property="og:${key}" content="${value}">`;
|
||||||
ogTags.push(tag);
|
ogTags.push(tag);
|
||||||
|
|||||||
@@ -87,16 +87,32 @@ app.get('/', (req, res, next)=>{
|
|||||||
req.brew = {
|
req.brew = {
|
||||||
text : welcomeText,
|
text : welcomeText,
|
||||||
renderer : 'V3'
|
renderer : 'V3'
|
||||||
|
},
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : 'The Homebrewery - Make your Homebrew content look legit!',
|
||||||
|
title : 'The Homebrewery - Homepage',
|
||||||
|
description : 'Homepage',
|
||||||
|
thumbnail : `${config.get('publicUrl')}/thumbnail.png`,
|
||||||
|
type : 'website'
|
||||||
};
|
};
|
||||||
splitTextStyleAndMetadata(req.brew);
|
splitTextStyleAndMetadata(req.brew);
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
//Home page v3
|
//Home page Legacy
|
||||||
app.get('/legacy', (req, res, next)=>{
|
app.get('/legacy', (req, res, next)=>{
|
||||||
req.brew = {
|
req.brew = {
|
||||||
text : welcomeTextLegacy,
|
text : welcomeTextLegacy,
|
||||||
renderer : 'legacy'
|
renderer : 'legacy'
|
||||||
|
},
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : 'The Homebrewery - Make your Homebrew content look legit!',
|
||||||
|
title : 'The Homebrewery - Homepage (Legacy)',
|
||||||
|
description : 'Homepage',
|
||||||
|
thumbnail : `${config.get('publicUrl')}/thumbnail.png`,
|
||||||
|
type : 'website'
|
||||||
};
|
};
|
||||||
splitTextStyleAndMetadata(req.brew);
|
splitTextStyleAndMetadata(req.brew);
|
||||||
return next();
|
return next();
|
||||||
@@ -107,6 +123,14 @@ app.get('/migrate', (req, res, next)=>{
|
|||||||
req.brew = {
|
req.brew = {
|
||||||
text : migrateText,
|
text : migrateText,
|
||||||
renderer : 'V3'
|
renderer : 'V3'
|
||||||
|
},
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : 'The Homebrewery - Make your Homebrew content look legit!',
|
||||||
|
title : 'The Homebrewery - v3 Migration Guide',
|
||||||
|
description : 'A brief guide to converting Legacy documents to the v3 renderer.',
|
||||||
|
thumbnail : `${config.get('publicUrl')}/thumbnail.png`,
|
||||||
|
type : 'website'
|
||||||
};
|
};
|
||||||
splitTextStyleAndMetadata(req.brew);
|
splitTextStyleAndMetadata(req.brew);
|
||||||
return next();
|
return next();
|
||||||
@@ -118,6 +142,14 @@ app.get('/changelog', async (req, res, next)=>{
|
|||||||
title : 'Changelog',
|
title : 'Changelog',
|
||||||
text : changelogText,
|
text : changelogText,
|
||||||
renderer : 'V3'
|
renderer : 'V3'
|
||||||
|
},
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : 'The Homebrewery - Make your Homebrew content look legit!',
|
||||||
|
title : 'The Homebrewery - Changelog',
|
||||||
|
description : 'Development changelog.',
|
||||||
|
thumbnail : `${config.get('publicUrl')}/thumbnail.png`,
|
||||||
|
type : 'website'
|
||||||
};
|
};
|
||||||
splitTextStyleAndMetadata(req.brew);
|
splitTextStyleAndMetadata(req.brew);
|
||||||
return next();
|
return next();
|
||||||
@@ -129,7 +161,16 @@ app.get('/faq', async (req, res, next)=>{
|
|||||||
title : 'FAQ',
|
title : 'FAQ',
|
||||||
text : faqText,
|
text : faqText,
|
||||||
renderer : 'V3'
|
renderer : 'V3'
|
||||||
|
},
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : 'The Homebrewery - Make your Homebrew content look legit!',
|
||||||
|
title : 'The Homebrewery - FAQ',
|
||||||
|
description : 'Frequently Asked Questions',
|
||||||
|
thumbnail : `${config.get('publicUrl')}/thumbnail.png`,
|
||||||
|
type : 'website'
|
||||||
};
|
};
|
||||||
|
|
||||||
splitTextStyleAndMetadata(req.brew);
|
splitTextStyleAndMetadata(req.brew);
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
@@ -138,6 +179,14 @@ app.get('/faq', async (req, res, next)=>{
|
|||||||
app.get('/source/:id', asyncHandler(getBrew('share')), (req, res)=>{
|
app.get('/source/:id', asyncHandler(getBrew('share')), (req, res)=>{
|
||||||
const { brew } = req;
|
const { brew } = req;
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : null,
|
||||||
|
title : req.brew.title ? `${req.brew.title} - /source/` : 'Homebrewery - Untitled Brew',
|
||||||
|
description : req.brew.description || 'No description.',
|
||||||
|
image : req.brew.thumbnail || null,
|
||||||
|
type : 'article'
|
||||||
|
};
|
||||||
|
|
||||||
const replaceStrings = { '&': '&', '<': '<', '>': '>' };
|
const replaceStrings = { '&': '&', '<': '<', '>': '>' };
|
||||||
let text = brew.text;
|
let text = brew.text;
|
||||||
for (const replaceStr in replaceStrings) {
|
for (const replaceStr in replaceStrings) {
|
||||||
@@ -153,6 +202,14 @@ app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{
|
|||||||
sanitizeBrew(brew, 'share');
|
sanitizeBrew(brew, 'share');
|
||||||
const prefix = 'HB - ';
|
const prefix = 'HB - ';
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : null,
|
||||||
|
title : req.brew.title ? `${req.brew.title} - /download/` : 'Homebrewery - Untitled Brew',
|
||||||
|
description : req.brew.description || 'No description.',
|
||||||
|
image : req.brew.thumbnail || null,
|
||||||
|
type : 'article'
|
||||||
|
};
|
||||||
|
|
||||||
let fileName = sanitizeFilename(`${prefix}${brew.title}`).replaceAll(' ', '');
|
let fileName = sanitizeFilename(`${prefix}${brew.title}`).replaceAll(' ', '');
|
||||||
if(!fileName || !fileName.length) { fileName = `${prefix}-Untitled-Brew`; };
|
if(!fileName || !fileName.length) { fileName = `${prefix}-Untitled-Brew`; };
|
||||||
res.set({
|
res.set({
|
||||||
@@ -224,6 +281,14 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
//Edit Page
|
//Edit Page
|
||||||
app.get('/edit/:id', asyncHandler(getBrew('edit')), (req, res, next)=>{
|
app.get('/edit/:id', asyncHandler(getBrew('edit')), (req, res, next)=>{
|
||||||
req.brew = req.brew.toObject ? req.brew.toObject() : req.brew;
|
req.brew = req.brew.toObject ? req.brew.toObject() : req.brew;
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : null,
|
||||||
|
title : req.brew.title || 'Homebrewery - Untitled Brew',
|
||||||
|
description : req.brew.description || 'No description.',
|
||||||
|
image : req.brew.thumbnail || null,
|
||||||
|
type : 'article'
|
||||||
|
};
|
||||||
sanitizeBrew(req.brew, 'edit');
|
sanitizeBrew(req.brew, 'edit');
|
||||||
splitTextStyleAndMetadata(req.brew);
|
splitTextStyleAndMetadata(req.brew);
|
||||||
res.header('Cache-Control', 'no-cache, no-store'); //reload the latest saved brew when pressing back button, not the cached version before save.
|
res.header('Cache-Control', 'no-cache, no-store'); //reload the latest saved brew when pressing back button, not the cached version before save.
|
||||||
@@ -242,6 +307,14 @@ app.get('/new/:id', asyncHandler(getBrew('share')), (req, res, next)=>{
|
|||||||
app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, res, next)=>{
|
app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, res, next)=>{
|
||||||
const { brew } = req;
|
const { brew } = req;
|
||||||
|
|
||||||
|
req.ogMeta = {
|
||||||
|
siteName : null,
|
||||||
|
title : req.brew.title || 'Homebrewery - Untitled Brew',
|
||||||
|
description : req.brew.description || 'No description.',
|
||||||
|
image : req.brew.thumbnail || null,
|
||||||
|
type : 'article'
|
||||||
|
};
|
||||||
|
|
||||||
if(req.params.id.length > 12 && !brew._id) {
|
if(req.params.id.length > 12 && !brew._id) {
|
||||||
const googleId = req.params.id.slice(0, -12);
|
const googleId = req.params.id.slice(0, -12);
|
||||||
const shareId = req.params.id.slice(-12);
|
const shareId = req.params.id.slice(-12);
|
||||||
@@ -342,7 +415,8 @@ app.use(asyncHandler(async (req, res, next)=>{
|
|||||||
account : req.account,
|
account : req.account,
|
||||||
enable_v3 : config.get('enable_v3'),
|
enable_v3 : config.get('enable_v3'),
|
||||||
enable_themes : config.get('enable_themes'),
|
enable_themes : config.get('enable_themes'),
|
||||||
config : configuration
|
config : configuration,
|
||||||
|
ogMeta : req.ogMeta
|
||||||
};
|
};
|
||||||
const title = req.brew ? req.brew.title : '';
|
const title = req.brew ? req.brew.title : '';
|
||||||
const page = await templateFn('homebrew', title, props)
|
const page = await templateFn('homebrew', title, props)
|
||||||
|
|||||||
Reference in New Issue
Block a user