Created
October 20, 2021 15:28
-
-
Save aeadedoyin/e044ef6a355529a4fad895d2d75a8212 to your computer and use it in GitHub Desktop.
Quickly scaffold for meta block in html head tag of a page (VueJS or NuxtJS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Utils file can be found here https://gist.github.com/aeadedoyin/f9fb0817762bc49ad8a856cd0b16ca97 | |
// Just download and keep in same folder as this.(i.e meta-utils.js) | |
import { withHttp } from './utils' | |
// This util makes it faster to implement meta:Open Graph, Twitter | |
// All these variable are overbidden if passed with meta param | |
const type = 'Website' | |
let url = process.env.SITE_URL // From env | |
const title = 'SiteTitle and Short Description Goes Here' | |
const siteName = 'SiteTitle or ShortName' | |
const description = 'Long Description Goes Here' | |
let mainImage = '/webclip.png' // grab from the url | |
const twitterCard = 'summary' // summary, summary_large_image, app, or player. | |
const twitterHandle = '@sitetwitterhandle' | |
export default (meta) => { | |
url = meta && meta.url ? withHttp(meta.url) : withHttp(url) | |
if (!(mainImage.includes('http://') || mainImage.includes('https://'))) { | |
mainImage = | |
meta && meta.mainImage ? withHttp(meta.mainImage) : url + mainImage | |
} | |
return [ | |
{ | |
charset: 'utf-8' | |
}, | |
{ | |
name: 'viewport', | |
content: 'width=device-width, initial-scale=1' | |
}, | |
{ | |
name: 'theme-color', | |
property: 'theme-color', | |
content: '#37A476' | |
}, | |
{ | |
hid: 'description', | |
name: 'description', | |
content: (meta && meta.description) || description | |
}, | |
{ | |
hid: 'og:type', | |
property: 'og:type', | |
content: (meta && meta.type) || type | |
}, | |
{ | |
hid: 'og:url', | |
property: 'og:url', | |
content: url | |
}, | |
{ | |
name: 'og:site_name', | |
property: 'og:site_name', | |
content: (meta && meta.site_name) || siteName | |
}, | |
{ | |
hid: 'og:title', | |
property: 'og:title', | |
content: (meta && meta.title) || title | |
}, | |
{ | |
hid: 'og:description', | |
property: 'og:description', | |
content: (meta && meta.description) || description | |
}, | |
{ | |
hid: 'og:image', | |
property: 'og:image', | |
content: mainImage | |
}, | |
{ | |
name: 'twitter:card', | |
content: (meta && meta.twitterCard) || twitterCard | |
}, | |
{ | |
name: 'twitter:site', | |
content: (meta && meta.twitterSite) || twitterHandle | |
}, | |
{ | |
hid: 'twitter:url', | |
name: 'twitter:url', | |
content: url | |
}, | |
{ | |
hid: 'twitter:title', | |
name: 'twitter:title', | |
content: (meta && meta.title) || title | |
}, | |
{ | |
hid: 'twitter:description', | |
name: 'twitter:description', | |
content: (meta && meta.description) || description | |
}, | |
{ | |
hid: 'twitter:image', | |
name: 'twitter:image', | |
content: mainImage | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment