mirror of
https://github.com/wavetermdev/docusaurus-og.git
synced 2026-08-05 13:46:35 -07:00
Merge pull request #87 from acid-info/fathom-plugin
feat: implement fathom
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# Change Log
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@acid-info/docusaurus-fathom",
|
||||
"version": "1.0.0-alpha.1",
|
||||
"description": "Docusaurus fathom plugin",
|
||||
"main": "lib/index.js",
|
||||
"types": "src/plugin.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/acid-info/logos-docusaurus-plugins.git",
|
||||
"directory": "packages/docusaurus-fathom"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc --build",
|
||||
"watch": "tsc --build --watch",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "^2.4.1",
|
||||
"@docusaurus/module-type-aliases": "^2.4.1",
|
||||
"@docusaurus/types": "^2.4.1",
|
||||
"@docusaurus/utils": "^2.4.1",
|
||||
"@docusaurus/utils-common": "^2.4.1",
|
||||
"@docusaurus/utils-validation": "^2.4.1",
|
||||
"lodash": "^4.17.21",
|
||||
"node-html-parser": "^6.1.5",
|
||||
"object-hash": "^3.0.0",
|
||||
"satori": "^0.10.1",
|
||||
"sharp": "^0.32.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.186"
|
||||
},
|
||||
"gitHead": "d2ee08c6c0678f78ad70f5d04183f7f781d11563"
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
SITE_ID,
|
||||
SCRIPT_URL,
|
||||
} from '@generated/docusaurus-fathom/default/options'
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'
|
||||
import { ClientModule } from '@docusaurus/types/src/clientModule'
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
fathom: any
|
||||
}
|
||||
}
|
||||
|
||||
if (ExecutionEnvironment.canUseDOM) {
|
||||
;(function (f: any, a: any, t: string, h: string) {
|
||||
a[h] =
|
||||
a[h] ||
|
||||
function () {
|
||||
;(a[h].q = a[h].q || []).push(arguments)
|
||||
}
|
||||
const o = f.createElement('script')
|
||||
const m = f.getElementsByTagName('script')[0]
|
||||
o.async = 1
|
||||
o.src = t
|
||||
o.id = 'fathom-script'
|
||||
m.parentNode.insertBefore(o, m)
|
||||
})(document, window, SCRIPT_URL, 'fathom')
|
||||
|
||||
const { fathom } = window as any
|
||||
fathom('set', 'siteId', SITE_ID)
|
||||
fathom('trackPageview')
|
||||
}
|
||||
|
||||
export const onRouteDidUpdate: ClientModule['onRouteDidUpdate'] = ({
|
||||
location,
|
||||
previousLocation,
|
||||
}) => {
|
||||
if (location.pathname !== previousLocation?.pathname) {
|
||||
window.fathom('trackPageview')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export type PluginOptions = {
|
||||
siteId: string
|
||||
scriptUrl: string
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare module '@generated/docusaurus-fathom/default/options'
|
||||
declare module '@docusaurus/ExecutionEnvironment'
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { LoadContext, Plugin } from '@docusaurus/types'
|
||||
import { PluginOptions } from './client/types/plugin.types'
|
||||
import path from 'path'
|
||||
import fs from 'fs-extra'
|
||||
|
||||
export default function fathomPlugin(
|
||||
context: LoadContext,
|
||||
options: PluginOptions,
|
||||
): Plugin<undefined> {
|
||||
const { siteId, scriptUrl } = options
|
||||
const dir = path.join(context.generatedFilesDir, 'docusaurus-fathom/default')
|
||||
fs.ensureDirSync(dir)
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(dir, 'options.ts'),
|
||||
`export const SITE_ID = "${siteId}"\nexport const SCRIPT_URL = "${scriptUrl}"`,
|
||||
)
|
||||
|
||||
return {
|
||||
name: 'docusaurus-fathom',
|
||||
getClientModules: () => [path.resolve(__dirname, './client/index.js')],
|
||||
}
|
||||
}
|
||||
|
||||
export { type PluginOptions }
|
||||
+1
@@ -0,0 +1 @@
|
||||
export type * from './index'
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"composite": true,
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo-client",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib",
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"lib": ["DOM"]
|
||||
},
|
||||
"include": ["src/client", "src/*.d.ts"],
|
||||
"exclude": ["**/__tests__/**"]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"references": [{ "path": "./tsconfig.client.json" }],
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"incremental": true,
|
||||
"tsBuildInfoFile": "./lib/.tsbuildinfo",
|
||||
"rootDir": "src",
|
||||
"outDir": "lib",
|
||||
"lib": ["DOM"]
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["src/theme", "**/__tests__/**"]
|
||||
}
|
||||
@@ -69,6 +69,13 @@ const config = {
|
||||
authorsMapPath: 'authors.yml',
|
||||
}),
|
||||
],
|
||||
[
|
||||
'@acid-info/docusaurus-fathom',
|
||||
{
|
||||
siteId: 'FUTMI',
|
||||
scriptUrl: 'https://fathom.status.im/tracker.js',
|
||||
},
|
||||
],
|
||||
],
|
||||
|
||||
themeConfig:
|
||||
|
||||
Reference in New Issue
Block a user