-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclarity.ts
55 lines (49 loc) · 1.49 KB
/
clarity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import type {
LoadContext,
OptionValidationContext,
Plugin,
} from "@docusaurus/types";
import { Joi } from "@docusaurus/utils-validation";
export interface PluginOptions {
projectId: string;
}
export type Options = Partial<PluginOptions>;
const pluginOptionsSchema = Joi.object({
projectId: Joi.string().required(),
});
export default async function microsoftClarity(
_: LoadContext,
options: PluginOptions,
): Promise<Plugin> {
return {
name: "@gracefullight/docusaurus-plugin-microsoft-clarity",
injectHtmlTags() {
return {
headTags: [
{
tagName: "link",
attributes: {
rel: "preconnect",
href: "https://www.clarity.ms",
},
},
{
tagName: "script",
innerHTML: `(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", "${options.projectId}");`,
},
]
};
},
};
}
export function validateOptions({
options,
validate,
}: OptionValidationContext<Options, PluginOptions>) {
const validatedOptions = validate(pluginOptionsSchema, options);
return validatedOptions;
}