import { MetaInfo } from 'vue-meta' export type PageType = 'website'|'article' export interface HeadConfig { type?: PageType locale?: string title?: string description?: string image?: string script?: MetaInfo['script'] } const DEFAULT_CONFIG: HeadConfig = { type: 'website' } export default (config: HeadConfig = {}) => { config = { ...DEFAULT_CONFIG, ...config } const { type, locale, title, description, image, script } = config const head: MetaInfo = { meta: [] } if (title) { head.title = title head.meta!.push({ hid: 'og:title', property: 'og:title', content: title }) head.meta!.push({ hid: 'twitter:title', name: 'twitter:title', content: title }) } if (type) { head.meta!.push({ hid: 'og:type', property: 'og:type', content: type }) } if (locale) { head.meta!.push({ hid: 'og:locale', property: 'og:locale', content: locale }) } if (description) { head.meta!.push({ hid: 'description', name: 'description', content: description }) head.meta!.push({ hid: 'og:description', property: 'og:description', content: description }) head.meta!.push({ hid: 'twitter:description', name: 'twitter:description', content: description }) } if (image) { head.meta!.push({ hid: 'og:image', property: 'og:image', content: image }) } if (script) { head.script = script } return head }