mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-27 14:15:52 +10:00
26 lines
676 B
JavaScript
26 lines
676 B
JavaScript
module.exports = class SiteDataPlugin {
|
|
constructor (tags = []) {
|
|
this.tags = tags
|
|
}
|
|
|
|
apply (compiler) {
|
|
compiler.hooks.compilation.tap('vuepress-site-data', compilation => {
|
|
compilation.hooks.htmlWebpackPluginAlterAssetTags.tapAsync('vuepress-site-data', (data, cb) => {
|
|
try {
|
|
this.tags.forEach(t => {
|
|
data.head.push({
|
|
tagName: t.tag,
|
|
closeTag: !(t.tag === 'meta' || t.tag === 'link'),
|
|
attributes: t.attributes,
|
|
innerHTML: t.innerHTML || ''
|
|
})
|
|
})
|
|
} catch (e) {
|
|
return cb(e)
|
|
}
|
|
cb(null, data)
|
|
})
|
|
})
|
|
}
|
|
}
|