Skip to content

Instantly share code, notes, and snippets.

@Addono

Addono/plugin.js

Last active Oct 10, 2020
Embed
What would you like to do?
Docusaurus in-project plugin
module.exports = function (context) {
const { siteConfig } = context // Siteconfig is the content of docusaurus.config.js
const { themeConfig } = siteConfig
if (!themeConfig.goatcounter) {
throw new Error(
'You need to specify `goatcounter` object in `themeConfig` '
+ 'with `code` field in it to use docusaurus-plugin-goatcounter'
)
}
if (!themeConfig.goatcounter.code) {
throw new Error(
'You specified the `goatCounter` object in `themeConfig`, '
+ 'but the `code` field was missing. '
)
}
const analyticsDomain = `https://${themeConfig.goatcounter.code}.goatcounter.com`
return {
name: 'docusaurus-plugin-goatcounter',
injectHtmlTags: () => { // Adds additional HTLM to every page
return {
headTags: [
{
tagName: 'script',
attributes: {
async: true,
src: '//gc.zgo.at/count.js',
'data-goatcounter': `${analyticsDomain}/count`,
},
},
],
}
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment