diff --git a/build/index.js b/build/index.js index 610781d..cac8297 100755 --- a/build/index.js +++ b/build/index.js @@ -1,5 +1,10 @@ #!/usr/bin/env node +// todo: use import assertions once they're supported by Node.js & ESLint +// https://github.com/tc39/proposal-import-assertions +import {createRequire} from 'module' +const require = createRequire(import.meta.url) + import {dirname, join} from 'node:path' import {pipeline} from 'node:stream/promises' import {createReadStream, createWriteStream} from 'node:fs' @@ -12,6 +17,8 @@ const { } = _technicalDocsCli import {generateMarkdownApiDocs} from './api-docs.js' +const pkg = require('../package.json') + const BASE_URL = new URL('..', import.meta.url).href const API_DOCS_DEST = 'docs/api.md' const DOCS_TO_RENDER = [ @@ -35,6 +42,23 @@ const SYNTAX_STYLESHEET_DEST = 'docs/syntax.css' const markdownRenderingCfg = { syntaxStylesheetUrl: SYNTAX_STYLESHEET_URL, + additionalHeadChildren: (h) => { + if (!pkg.goatCounterUrl) return [] + return [ + // https://72afc0822cce0642af90.goatcounter.com/help/skip-dev#skip-loading-staging-beta-sites-312 + h('script', ` +if (window.location.host !== ${JSON.stringify(config.hostname)}) { + window.goatcounter = {no_onload: true} +} +`), + // https://72afc0822cce0642af90.goatcounter.com/help/start + h('script', { + src: '//gc.zgo.at/count.js', + async: true, + 'data-goatcounter': pkg.goatCounterUrl, + }), + ] + }, } for (const [src, dest] of DOCS_TO_RENDER) { console.info(`rendering Markdown file ${src} to HTML file ${dest}`) diff --git a/package.json b/package.json index ee78d9d..f536367 100644 --- a/package.json +++ b/package.json @@ -50,5 +50,6 @@ "start": "node index.js", "lint": "eslint .", "test": "node test/index.js | tap-min" - } + }, + "goatCounterUrl": "https://37462fdee48390778258.goatcounter.com/count" } diff --git a/readme.md b/readme.md index b19bda6..64ce0b7 100644 --- a/readme.md +++ b/readme.md @@ -34,6 +34,8 @@ git clone https://github.com/derhuerst/db-rest.git cd db-rest git checkout 6 npm install + +export HOSTNAME='my-vbb-rest-api.example.org' npm run build redis-server &