-
Notifications
You must be signed in to change notification settings - Fork 2
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
8c0d5ee
commit 966c6b3
Showing
13 changed files
with
177 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Change Log |
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,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" | ||
} |
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,33 @@ | ||
import { SITE_ID, SCRIPT_URL } from './options' | ||
|
||
declare global { | ||
interface Window { | ||
fathom: any | ||
} | ||
} | ||
|
||
;(function (f: any, a: Window, 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') | ||
|
||
console.log('PLUGIN_SITE_ID', SITE_ID) | ||
|
||
export function onRouteDidUpdate({ location, previousLocation }) { | ||
if (location.pathname !== previousLocation?.pathname) { | ||
fathom('trackPageview') | ||
} | ||
} |
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,2 @@ | ||
export const SITE_ID = '' | ||
export const SCRIPT_URL = '' |
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,4 @@ | ||
export type PluginOptions = { | ||
siteId: string | ||
scriptUrl: string | ||
} |
Empty file.
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,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 } |
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 @@ | ||
export type * from './index' |
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,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__/**"] | ||
} |
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,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__/**"] | ||
} |
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,33 @@ | ||
const SCRIPT_URL = '//fathom.status.im/tracker.js' | ||
const SITE_ID = 'FUTMI' | ||
|
||
declare global { | ||
interface Window { | ||
fathom: any | ||
} | ||
} | ||
|
||
;(function (f: any, a: Window, 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 function onRouteDidUpdate({ location, previousLocation }) { | ||
console.log('vvxcvxcv') | ||
if (location.pathname !== previousLocation?.pathname) { | ||
fathom('trackPageview') | ||
} | ||
} |
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