-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58ee0c1
commit a80bce3
Showing
4 changed files
with
115 additions
and
66 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Application, JSX, ParameterType, ReflectionKind } from "typedoc"; | ||
|
||
/** | ||
* @param {import("typedoc").Application} app | ||
*/ | ||
export function load(app) { | ||
|
||
// Keywords support | ||
// from https://github.com/matteobruni/typedoc-plugins/blob/main/plugins/keywords/src/index.tsx | ||
app.options.addDeclaration({ | ||
name: "keywords", | ||
type: ParameterType.Array, | ||
help: "Website keywords", | ||
}); | ||
|
||
app.renderer.hooks.on("head.begin", (ctx) => { | ||
/** @type string[] */ | ||
const keywords = ctx.options.getValue("keywords"); | ||
|
||
// convert to JSX.createElement: | ||
return JSX.createElement("meta", { | ||
name: "keywords", | ||
content: keywords.join(", "), | ||
}); | ||
}); | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Application, JSX, ParameterType, ReflectionKind } from "typedoc"; | ||
|
||
const optionSiteName = "plausibleSiteDomain"; | ||
const optionSiteOrigin = "plausibleSiteOrigin"; | ||
|
||
/** | ||
* This plugin is used to load a plugin that throws an error | ||
* @param {import("typedoc").Application} app | ||
*/ | ||
export function load(app) { | ||
|
||
// Plausible support | ||
// from https://gitlab.com/8hobbies/typedoc-plugin-plausible/-/blob/master/index.ts?ref_type=heads | ||
|
||
app.options.addDeclaration({ | ||
name: optionSiteName, | ||
type: ParameterType.String, | ||
help: `Domain name used by Plausible Analytics.`, | ||
}); | ||
app.options.addDeclaration({ | ||
name: optionSiteOrigin, | ||
type: ParameterType.String, | ||
help: `Base URL to get Plausible Analytics script from and report to. Should be everything but 'script.js'`, | ||
defaultValue: "plausible.io/js/", | ||
}); | ||
app.renderer.hooks.on("head.end", (ctx) => { | ||
|
||
const plausibleSiteDomain = ctx.options.getValue(optionSiteName); | ||
if (typeof plausibleSiteDomain !== "string") { | ||
throw TypeError( | ||
`Unexpected ${optionSiteName} type: ${JSON.stringify(plausibleSiteDomain)}`, | ||
); | ||
} | ||
const plausibleSiteOrigin = ctx.options.getValue(optionSiteOrigin); | ||
if (typeof plausibleSiteOrigin !== "string") { | ||
throw TypeError( | ||
`Unexpected ${optionSiteOrigin} type: ${JSON.stringify(plausibleSiteOrigin)}`, | ||
); | ||
} | ||
const plausibleSrc = !plausibleSiteOrigin.endsWith("/") | ||
? `${plausibleSiteOrigin}/` | ||
: plausibleSiteOrigin; | ||
if (plausibleSiteDomain === "") { | ||
// No site specified. | ||
return JSX.createElement(JSX.Fragment, {}); | ||
} | ||
|
||
return [ | ||
JSX.createElement("script", { | ||
defer: true, | ||
"data-domain": plausibleSiteDomain, | ||
src: `https://${plausibleSrc}script.manual.outbound-links.pageview-props.js`, | ||
}), | ||
JSX.createElement("script", null, JSX.createElement(JSX.Raw, { | ||
html: "window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }" | ||
})), | ||
JSX.createElement("script", null, JSX.createElement(JSX.Raw, { | ||
html: ` | ||
// the start of the URL has this form: | ||
// /docs/api/@needle-tools/engine/3.48.3/<actually interesting part> | ||
// so we need to extract the interesting part. | ||
const url = window.location.pathname; | ||
const parts = url.split("/"); | ||
// find index of the part that looks like a version (contains two dots and the first two parts are numbers) | ||
const versionIndex = parts.findIndex((part, index) => { | ||
const subParts = part.split("."); | ||
return subParts.length === 3 && !isNaN(subParts[0]) && !isNaN(subParts[1]); | ||
}); | ||
const interestingPart = parts.slice(versionIndex + 1).join("/"); | ||
const engineVersion = parts[versionIndex]; | ||
console.log("Plausible PageView", interestingPart, engineVersion); | ||
plausible('pageview', { | ||
u: "https://api.needle.tools/" + interestingPart + window.location.search, | ||
props: { version: engineVersion }, | ||
}); | ||
` | ||
}), | ||
), | ||
]; | ||
}); | ||
} |
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