From bc0ee8138e81e507a2e1b3ea3b2753206a0cd53f Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Mon, 26 Sep 2022 13:03:40 -0500 Subject: [PATCH 1/6] change title and description --- client/template.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/template.js b/client/template.js index 2ebe86094..85e313b94 100644 --- a/client/template.js +++ b/client/template.js @@ -9,10 +9,10 @@ module.exports = async(name, title = '', props = {})=>{ - + - + From b2374564205778ae9675dc757f19c2a0581760c4 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Thu, 20 Oct 2022 11:19:17 -0500 Subject: [PATCH 2/6] add fn to change meta tags based on page --- client/template.js | 81 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/client/template.js b/client/template.js index 85e313b94..6ee7f9d4a 100644 --- a/client/template.js +++ b/client/template.js @@ -1,28 +1,59 @@ -module.exports = async(name, title = '', props = {})=>{ +const template = async function(name, title='', props = {}){ const HOMEBREWERY_PUBLIC_URL=props.config.publicUrl; - return ` - - - - - - - - - - - - - - - ${title.length ? `${title} - The Homebrewery`: 'The Homebrewery - NaturalCrit'} - - -
${require(`../build/${name}/ssr.js`)(props)}
- - - - -`; + const ogMeta = { + siteName : 'The Homebrewery - Make your Homebrew content look legit!', + title : 'The Homebrewery', + description : 'Homepage', + thumbnail : `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`, + type : 'website' + }; + + if(props.url.match(/\/share\/|\/edit\//)){ + Object.assign(ogMeta, { + siteName : null, + title : props.brew.title || 'Homebrewery - Untitled Brew', + description : props.brew.description || 'No description.', + thumbnail : props.brew.thumbnail || null, + type : 'article' + }); + } else if(props.url.match(/\/print\/|\/source\//)){ + Object.assign(ogMeta, { + siteName : null, + title : `${props.brew.title} - ${props.url.match(/\/print\/|\/source\//)}` || 'Homebrewery - Untitled Brew', + description : props.brew.description || 'No description.', + thumbnail : props.brew.thumbnail || null, + type : 'article' + }); + } + + const ogTags = []; + Object.entries(ogMeta).forEach(([key, value])=>{ + if(!value) return; + const tag = ``; + ogTags.push(tag); + }); + const ogMetaTags = ogTags.join('\n'); + + + return ` + + + + + + + ${ogMetaTags} + + ${title.length ? `${title} - The Homebrewery`: 'The Homebrewery - NaturalCrit'} + + +
${require(`../build/${name}/ssr.js`)(props)}
+ + + + + `; }; + +module.exports = template; \ No newline at end of file From bdf1bd1e8b254ff384cda64e50317996eb2596a6 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Thu, 20 Oct 2022 11:40:10 -0500 Subject: [PATCH 3/6] add user page --- client/template.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/template.js b/client/template.js index 6ee7f9d4a..d59b1d29e 100644 --- a/client/template.js +++ b/client/template.js @@ -25,6 +25,14 @@ const template = async function(name, title='', props = {}){ thumbnail : props.brew.thumbnail || null, type : 'article' }); + } else if(props.url.match(/\/user\//)){ + Object.assign(ogMeta, { + siteName : null, + title : `${props.username} - The Homebrewery`, + description : `${props.username}'s user page.`, + thumbnail : null, + type : 'profile' + }); } const ogTags = []; From 5c3f7b1b8220322803e03a8245d5bffa1cf87068 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Thu, 20 Oct 2022 11:46:53 -0500 Subject: [PATCH 4/6] small fixes --- client/template.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/template.js b/client/template.js index d59b1d29e..23758948c 100644 --- a/client/template.js +++ b/client/template.js @@ -14,15 +14,15 @@ const template = async function(name, title='', props = {}){ siteName : null, title : props.brew.title || 'Homebrewery - Untitled Brew', description : props.brew.description || 'No description.', - thumbnail : props.brew.thumbnail || null, + image : props.brew.thumbnail || null, type : 'article' }); } else if(props.url.match(/\/print\/|\/source\//)){ Object.assign(ogMeta, { siteName : null, - 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.', - thumbnail : props.brew.thumbnail || null, + image : props.brew.thumbnail || null, type : 'article' }); } else if(props.url.match(/\/user\//)){ @@ -30,7 +30,7 @@ const template = async function(name, title='', props = {}){ siteName : null, title : `${props.username} - The Homebrewery`, description : `${props.username}'s user page.`, - thumbnail : null, + image : null, type : 'profile' }); } From 672d582caf65e48ec687a36ef5e1efd6439894ca Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Sat, 5 Nov 2022 23:32:30 -0500 Subject: [PATCH 5/6] move metaTag objects to app.js --- client/template.js | 68 ++++++++++++++++++++-------------------- server/app.js | 78 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 110 insertions(+), 36 deletions(-) diff --git a/client/template.js b/client/template.js index f11952126..55034aa08 100644 --- a/client/template.js +++ b/client/template.js @@ -1,42 +1,42 @@ const template = async function(name, title='', props = {}){ - const HOMEBREWERY_PUBLIC_URL=props.config.publicUrl; + // const HOMEBREWERY_PUBLIC_URL=props.config.publicUrl; - const ogMeta = { - siteName : 'The Homebrewery - Make your Homebrew content look legit!', - title : 'The Homebrewery', - description : 'Homepage', - thumbnail : `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`, - type : 'website' - }; + // const ogMeta = { + // siteName : 'The Homebrewery - Make your Homebrew content look legit!', + // title : 'The Homebrewery', + // description : 'Homepage', + // thumbnail : `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`, + // type : 'website' + // }; - if(props.url.match(/\/share\/|\/edit\//)){ - Object.assign(ogMeta, { - siteName : null, - title : props.brew.title || 'Homebrewery - Untitled Brew', - description : props.brew.description || 'No description.', - image : props.brew.thumbnail || null, - type : 'article' - }); - } else if(props.url.match(/\/print\/|\/source\//)){ - Object.assign(ogMeta, { - siteName : null, - title : props.brew.title ? `${props.brew.title} - ${props.url.match(/\/print\/|\/source\//)}` : 'Homebrewery - Untitled Brew', - description : props.brew.description || 'No description.', - image : props.brew.thumbnail || null, - type : 'article' - }); - } else if(props.url.match(/\/user\//)){ - Object.assign(ogMeta, { - siteName : null, - title : `${props.username} - The Homebrewery`, - description : `${props.username}'s user page.`, - image : null, - type : 'profile' - }); - } + // if(props.url.match(/\/share\/|\/edit\//)){ + // Object.assign(ogMeta, { + // siteName : null, + // title : props.brew.title || 'Homebrewery - Untitled Brew', + // description : props.brew.description || 'No description.', + // image : props.brew.thumbnail || null, + // type : 'article' + // }); + // } else if(props.url.match(/\/print\/|\/source\//)){ + // Object.assign(ogMeta, { + // siteName : null, + // title : props.brew.title ? `${props.brew.title} - ${props.url.match(/\/print\/|\/source\//)}` : 'Homebrewery - Untitled Brew', + // description : props.brew.description || 'No description.', + // image : props.brew.thumbnail || null, + // type : 'article' + // }); + // } else if(props.url.match(/\/user\//)){ + // Object.assign(ogMeta, { + // siteName : null, + // title : `${props.username} - The Homebrewery`, + // description : `${props.username}'s user page.`, + // image : null, + // type : 'profile' + // }); + // } const ogTags = []; - Object.entries(ogMeta).forEach(([key, value])=>{ + Object.entries(props.ogMeta).forEach(([key, value])=>{ if(!value) return; const tag = ``; ogTags.push(tag); diff --git a/server/app.js b/server/app.js index 76cd3f8e3..7457d5dc0 100644 --- a/server/app.js +++ b/server/app.js @@ -87,16 +87,32 @@ app.get('/', (req, res, next)=>{ req.brew = { text : welcomeText, 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); return next(); }); -//Home page v3 +//Home page Legacy app.get('/legacy', (req, res, next)=>{ req.brew = { text : welcomeTextLegacy, 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); return next(); @@ -107,6 +123,14 @@ app.get('/migrate', (req, res, next)=>{ req.brew = { text : migrateText, 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); return next(); @@ -118,6 +142,14 @@ app.get('/changelog', async (req, res, next)=>{ title : 'Changelog', text : changelogText, 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); return next(); @@ -129,7 +161,16 @@ app.get('/faq', async (req, res, next)=>{ title : 'FAQ', text : faqText, 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); return next(); }); @@ -138,6 +179,14 @@ app.get('/faq', async (req, res, next)=>{ app.get('/source/:id', asyncHandler(getBrew('share')), (req, res)=>{ 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 = { '&': '&', '<': '<', '>': '>' }; let text = brew.text; for (const replaceStr in replaceStrings) { @@ -153,6 +202,14 @@ app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{ sanitizeBrew(brew, 'share'); 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(' ', ''); if(!fileName || !fileName.length) { fileName = `${prefix}-Untitled-Brew`; }; res.set({ @@ -224,6 +281,14 @@ app.get('/user/:username', async (req, res, next)=>{ //Edit Page app.get('/edit/:id', asyncHandler(getBrew('edit')), (req, res, next)=>{ 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'); 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. @@ -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)=>{ 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) { const googleId = req.params.id.slice(0, -12); const shareId = req.params.id.slice(-12); @@ -342,7 +415,8 @@ app.use(asyncHandler(async (req, res, next)=>{ account : req.account, enable_v3 : config.get('enable_v3'), enable_themes : config.get('enable_themes'), - config : configuration + config : configuration, + ogMeta : req.ogMeta }; const title = req.brew ? req.brew.title : ''; const page = await templateFn('homebrew', title, props) From ed4c090f21c2cba7d9d7f2d3004f855e9381dbf7 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Sun, 6 Nov 2022 12:34:24 -0600 Subject: [PATCH 6/6] finish setting OG tags --- client/template.js | 37 --------------------------------- server/app.js | 51 +++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 63 deletions(-) diff --git a/client/template.js b/client/template.js index 55034aa08..13e09711c 100644 --- a/client/template.js +++ b/client/template.js @@ -1,40 +1,4 @@ const template = async function(name, title='', props = {}){ - // const HOMEBREWERY_PUBLIC_URL=props.config.publicUrl; - - // const ogMeta = { - // siteName : 'The Homebrewery - Make your Homebrew content look legit!', - // title : 'The Homebrewery', - // description : 'Homepage', - // thumbnail : `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`, - // type : 'website' - // }; - - // if(props.url.match(/\/share\/|\/edit\//)){ - // Object.assign(ogMeta, { - // siteName : null, - // title : props.brew.title || 'Homebrewery - Untitled Brew', - // description : props.brew.description || 'No description.', - // image : props.brew.thumbnail || null, - // type : 'article' - // }); - // } else if(props.url.match(/\/print\/|\/source\//)){ - // Object.assign(ogMeta, { - // siteName : null, - // title : props.brew.title ? `${props.brew.title} - ${props.url.match(/\/print\/|\/source\//)}` : 'Homebrewery - Untitled Brew', - // description : props.brew.description || 'No description.', - // image : props.brew.thumbnail || null, - // type : 'article' - // }); - // } else if(props.url.match(/\/user\//)){ - // Object.assign(ogMeta, { - // siteName : null, - // title : `${props.username} - The Homebrewery`, - // description : `${props.username}'s user page.`, - // image : null, - // type : 'profile' - // }); - // } - const ogTags = []; Object.entries(props.ogMeta).forEach(([key, value])=>{ if(!value) return; @@ -43,7 +7,6 @@ const template = async function(name, title='', props = {}){ }); const ogMetaTags = ogTags.join('\n'); - return ` diff --git a/server/app.js b/server/app.js index 7457d5dc0..7d462cf1e 100644 --- a/server/app.js +++ b/server/app.js @@ -91,7 +91,7 @@ app.get('/', (req, res, next)=>{ req.ogMeta = { siteName : 'The Homebrewery - Make your Homebrew content look legit!', - title : 'The Homebrewery - Homepage', + title : 'Homepage', description : 'Homepage', thumbnail : `${config.get('publicUrl')}/thumbnail.png`, type : 'website' @@ -109,7 +109,7 @@ app.get('/legacy', (req, res, next)=>{ req.ogMeta = { siteName : 'The Homebrewery - Make your Homebrew content look legit!', - title : 'The Homebrewery - Homepage (Legacy)', + title : 'Homepage (Legacy)', description : 'Homepage', thumbnail : `${config.get('publicUrl')}/thumbnail.png`, type : 'website' @@ -127,7 +127,7 @@ app.get('/migrate', (req, res, next)=>{ req.ogMeta = { siteName : 'The Homebrewery - Make your Homebrew content look legit!', - title : 'The Homebrewery - v3 Migration Guide', + title : 'v3 Migration Guide', description : 'A brief guide to converting Legacy documents to the v3 renderer.', thumbnail : `${config.get('publicUrl')}/thumbnail.png`, type : 'website' @@ -146,9 +146,9 @@ app.get('/changelog', async (req, res, next)=>{ req.ogMeta = { siteName : 'The Homebrewery - Make your Homebrew content look legit!', - title : 'The Homebrewery - Changelog', + title : 'Changelog', description : 'Development changelog.', - thumbnail : `${config.get('publicUrl')}/thumbnail.png`, + thumbnail : null, type : 'website' }; splitTextStyleAndMetadata(req.brew); @@ -165,7 +165,7 @@ app.get('/faq', async (req, res, next)=>{ req.ogMeta = { siteName : 'The Homebrewery - Make your Homebrew content look legit!', - title : 'The Homebrewery - FAQ', + title : 'FAQ', description : 'Frequently Asked Questions', thumbnail : `${config.get('publicUrl')}/thumbnail.png`, type : 'website' @@ -179,14 +179,6 @@ app.get('/faq', async (req, res, next)=>{ app.get('/source/:id', asyncHandler(getBrew('share')), (req, res)=>{ 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 = { '&': '&', '<': '<', '>': '>' }; let text = brew.text; for (const replaceStr in replaceStrings) { @@ -202,14 +194,6 @@ app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{ sanitizeBrew(brew, 'share'); 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(' ', ''); if(!fileName || !fileName.length) { fileName = `${prefix}-Untitled-Brew`; }; res.set({ @@ -224,6 +208,14 @@ app.get('/download/:id', asyncHandler(getBrew('share')), (req, res)=>{ app.get('/user/:username', async (req, res, next)=>{ const ownAccount = req.account && (req.account.username == req.params.username); + req.ogMeta = { + siteName : 'The Homebrewery - Make your Homebrew content look legit!', + title : `${req.params.username}'s Collection`, + description : 'View my collection of homebrew on the Homebrewery.', + image : null, + type : 'website' // or 'profile'? + }; + const fields = [ 'googleId', 'title', @@ -283,8 +275,8 @@ app.get('/edit/:id', asyncHandler(getBrew('edit')), (req, res, next)=>{ req.brew = req.brew.toObject ? req.brew.toObject() : req.brew; req.ogMeta = { - siteName : null, - title : req.brew.title || 'Homebrewery - Untitled Brew', + siteName : 'The Homebrewery - Make your Homebrew content look legit!', + title : req.brew.title || 'Untitled Brew', description : req.brew.description || 'No description.', image : req.brew.thumbnail || null, type : 'article' @@ -300,6 +292,13 @@ app.get('/new/:id', asyncHandler(getBrew('share')), (req, res, next)=>{ sanitizeBrew(req.brew, 'share'); splitTextStyleAndMetadata(req.brew); req.brew.title = `CLONE - ${req.brew.title}`; + req.ogMeta = { + siteName : 'The Homebrewery - Make your Homebrew content look legit!', + title : 'New', + description : 'Start crafting your homebrew on the Homebrewery!', + image : null, + type : 'website' + }; return next(); }); @@ -308,8 +307,8 @@ app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, r const { brew } = req; req.ogMeta = { - siteName : null, - title : req.brew.title || 'Homebrewery - Untitled Brew', + siteName : 'The Homebrewery - Make your Homebrew content look legit!', + title : req.brew.title || 'Untitled Brew', description : req.brew.description || 'No description.', image : req.brew.thumbnail || null, type : 'article'