mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 17:52:47 +00:00
add fn to change meta tags based on page
This commit is contained in:
@@ -1,28 +1,59 @@
|
|||||||
module.exports = async(name, title = '', props = {})=>{
|
const template = async function(name, title='', props = {}){
|
||||||
const HOMEBREWERY_PUBLIC_URL=props.config.publicUrl;
|
const HOMEBREWERY_PUBLIC_URL=props.config.publicUrl;
|
||||||
|
|
||||||
return `
|
const ogMeta = {
|
||||||
<!DOCTYPE html>
|
siteName : 'The Homebrewery - Make your Homebrew content look legit!',
|
||||||
<html>
|
title : 'The Homebrewery',
|
||||||
<head>
|
description : 'Homepage',
|
||||||
<link href="//use.fontawesome.com/releases/v5.15.1/css/all.css" rel="stylesheet" />
|
thumbnail : `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`,
|
||||||
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
|
type : 'website'
|
||||||
<link href=${`/${name}/bundle.css`} rel='stylesheet' />
|
};
|
||||||
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
|
|
||||||
<meta property="og:title" content="${props.brew.shareId ? (props.brew.title || 'Homebrewery - Untitled Brew') : 'The Homebrewery'}">
|
if(props.url.match(/\/share\/|\/edit\//)){
|
||||||
<meta property="og:url" content="${HOMEBREWERY_PUBLIC_URL}/${props.brew?.shareId ? `share/${props.brew.shareId}` : ''}">
|
Object.assign(ogMeta, {
|
||||||
<meta property="og:image" content="${props.brew?.thumbnail || `${HOMEBREWERY_PUBLIC_URL}/thumbnail.png`}">
|
siteName : null,
|
||||||
<meta property="og:description" content="${props.brew.shareId ? (props.brew.description || 'No description.') : 'Try out the Homebrewery!'}">
|
title : props.brew.title || 'Homebrewery - Untitled Brew',
|
||||||
<meta property="og:site_name" content="The Homebrewery - Make your Homebrew content look legit!">
|
description : props.brew.description || 'No description.',
|
||||||
<meta property="og:type" content="article">
|
thumbnail : props.brew.thumbnail || null,
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
type : 'article'
|
||||||
<title>${title.length ? `${title} - The Homebrewery`: 'The Homebrewery - NaturalCrit'}</title>
|
});
|
||||||
</head>
|
} else if(props.url.match(/\/print\/|\/source\//)){
|
||||||
<body>
|
Object.assign(ogMeta, {
|
||||||
<main id="reactRoot">${require(`../build/${name}/ssr.js`)(props)}</main>
|
siteName : null,
|
||||||
<script src=${`/${name}/bundle.js`}></script>
|
title : `${props.brew.title} - ${props.url.match(/\/print\/|\/source\//)}` || 'Homebrewery - Untitled Brew',
|
||||||
<script>start_app(${JSON.stringify(props)})</script>
|
description : props.brew.description || 'No description.',
|
||||||
</body>
|
thumbnail : props.brew.thumbnail || null,
|
||||||
</html>
|
type : 'article'
|
||||||
`;
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const ogTags = [];
|
||||||
|
Object.entries(ogMeta).forEach(([key, value])=>{
|
||||||
|
if(!value) return;
|
||||||
|
const tag = `<meta property="og:${key}" content="${value}">`;
|
||||||
|
ogTags.push(tag);
|
||||||
|
});
|
||||||
|
const ogMetaTags = ogTags.join('\n');
|
||||||
|
|
||||||
|
|
||||||
|
return `<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link href="//use.fontawesome.com/releases/v5.15.1/css/all.css" rel="stylesheet" />
|
||||||
|
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
|
||||||
|
<link href=${`/${name}/bundle.css`} rel='stylesheet' />
|
||||||
|
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
|
||||||
|
${ogMetaTags}
|
||||||
|
<meta name="twitter:card" content="summary_large_image">
|
||||||
|
<title>${title.length ? `${title} - The Homebrewery`: 'The Homebrewery - NaturalCrit'}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main id="reactRoot">${require(`../build/${name}/ssr.js`)(props)}</main>
|
||||||
|
<script src=${`/${name}/bundle.js`}></script>
|
||||||
|
<script>start_app(${JSON.stringify(props)})</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = template;
|
||||||
Reference in New Issue
Block a user