Last active
October 10, 2020 13:25
-
-
Save Addono/20952a1d45e2957e55d726b93224d2fd to your computer and use it in GitHub Desktop.
Docusaurus in-project plugin
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
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