Skip to content

Instantly share code, notes, and snippets.

@Addono
Last active October 10, 2020 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Addono/20952a1d45e2957e55d726b93224d2fd to your computer and use it in GitHub Desktop.
Save Addono/20952a1d45e2957e55d726b93224d2fd to your computer and use it in GitHub Desktop.
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