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] 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