@brillout/docpress 0.16.24 → 0.16.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/+config.ts CHANGED
@@ -2,7 +2,7 @@ export { config as default }
2
2
 
3
3
  import type { Config } from 'vike/types'
4
4
  import { viteConfig } from './vite.config.js'
5
- import type { Config as DocpressConfig, ChoicesConfig } from './types/Config.js'
5
+ import type { Config as DocpressConfig } from './types/Config.js'
6
6
  import type { PageSection } from './parsePageSections.js'
7
7
  import type { Resolved } from './resolvePageContext.js'
8
8
 
@@ -21,10 +21,6 @@ const config = {
21
21
  env: { server: true, client: true, config: true },
22
22
  global: true,
23
23
  },
24
- choices: {
25
- env: { server: true, client: true, config: true },
26
- global: true,
27
- },
28
24
  },
29
25
  prefetch: {
30
26
  staticAssets: 'hover',
@@ -41,11 +37,9 @@ declare global {
41
37
  }
42
38
  interface Config {
43
39
  docpress?: DocpressConfig
44
- choices?: ChoicesConfig
45
40
  }
46
41
  interface ConfigResolved {
47
42
  docpress: DocpressConfig
48
- choices: ChoicesConfig
49
43
  pageSectionsExport: PageSection[] | undefined
50
44
  }
51
45
  }
@@ -111,7 +111,7 @@ function generateChoiceGroupCode(choiceNodes: ChoiceNode[], parent?: Parent): Md
111
111
  }
112
112
 
113
113
  function findChoiceGroup(vikeConfig: VikeConfig, choices: string[]) {
114
- const { choices: choicesConfig } = vikeConfig.config
114
+ const { choices: choicesConfig } = vikeConfig.config.docpress
115
115
  const choicesAll = { ...CHOICES_BUILT_IN, ...choicesConfig }
116
116
 
117
117
  const groupName = Object.keys(choicesAll).find((key) => {
@@ -1,3 +1,4 @@
1
- .highlighted {
1
+ .highlighted,
2
+ .highlighted-word {
2
3
  background: rgba(0, 0, 0, 0.1);
3
4
  }
package/dist/+config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { config as default };
2
- import type { Config as DocpressConfig, ChoicesConfig } from './types/Config.js';
2
+ import type { Config as DocpressConfig } from './types/Config.js';
3
3
  import type { PageSection } from './parsePageSections.js';
4
4
  import type { Resolved } from './resolvePageContext.js';
5
5
  declare const config: {
@@ -25,14 +25,6 @@ declare const config: {
25
25
  };
26
26
  global: true;
27
27
  };
28
- choices: {
29
- env: {
30
- server: true;
31
- client: true;
32
- config: true;
33
- };
34
- global: true;
35
- };
36
28
  };
37
29
  prefetch: {
38
30
  staticAssets: "hover";
@@ -48,11 +40,9 @@ declare global {
48
40
  }
49
41
  interface Config {
50
42
  docpress?: DocpressConfig;
51
- choices?: ChoicesConfig;
52
43
  }
53
44
  interface ConfigResolved {
54
45
  docpress: DocpressConfig;
55
- choices: ChoicesConfig;
56
46
  pageSectionsExport: PageSection[] | undefined;
57
47
  }
58
48
  }
package/dist/+config.js CHANGED
@@ -15,10 +15,6 @@ const config = {
15
15
  env: { server: true, client: true, config: true },
16
16
  global: true,
17
17
  },
18
- choices: {
19
- env: { server: true, client: true, config: true },
20
- global: true,
21
- },
22
18
  },
23
19
  prefetch: {
24
20
  staticAssets: 'hover',
@@ -88,7 +88,7 @@ function generateChoiceGroupCode(choiceNodes, parent) {
88
88
  };
89
89
  }
90
90
  function findChoiceGroup(vikeConfig, choices) {
91
- const { choices: choicesConfig } = vikeConfig.config;
91
+ const { choices: choicesConfig } = vikeConfig.config.docpress;
92
92
  const choicesAll = { ...CHOICES_BUILT_IN, ...choicesConfig };
93
93
  const groupName = Object.keys(choicesAll).find((key) => {
94
94
  // get only the values that exist in both choices and choicesAll[key].choices
@@ -1,4 +1,4 @@
1
- export type { Config, ChoicesConfig };
1
+ export type { Config };
2
2
  import type { HeadingDefinition, HeadingDetachedDefinition } from './Heading.js';
3
3
  import type React from 'react';
4
4
  type Config = {
@@ -28,6 +28,7 @@ type Config = {
28
28
  indexName: string;
29
29
  };
30
30
  googleAnalytics?: string;
31
+ umamiId?: string;
31
32
  i18n?: true;
32
33
  pressKit?: true;
33
34
  docsDir?: string;
@@ -38,6 +39,7 @@ type Config = {
38
39
  navLogoStyle?: React.CSSProperties;
39
40
  navLogoTextStyle?: React.CSSProperties;
40
41
  globalNote?: React.ReactNode;
42
+ choices?: Record<string, Choice>;
41
43
  };
42
44
  /** Order in Algolia search results */
43
45
  type Category = string | {
@@ -45,7 +47,6 @@ type Category = string | {
45
47
  /** Hide from Algolia search */
46
48
  hide?: boolean;
47
49
  };
48
- type ChoicesConfig = Record<string, Choice>;
49
50
  type Choice = {
50
51
  choices: string[];
51
52
  default: string;
@@ -5,7 +5,12 @@ import { parsePageSections } from './parsePageSections.js';
5
5
  import rehypePrettyCode from 'rehype-pretty-code';
6
6
  import remarkGfm from 'remark-gfm';
7
7
  import remarkDirective from 'remark-directive';
8
- import { transformerNotationDiff, transformerNotationHighlight } from '@shikijs/transformers';
8
+ import { transformerNotationDiff, transformerNotationWordHighlight } from '@shikijs/transformers';
9
+ // @brillout/shiki-transformers adds color parameter `[!code highlight:#abc]` where #abc is a color
10
+ // https://github.com/shikijs/shiki/issues/1264
11
+ // https://shiki.style/packages/transformers#transformernotationhighlight
12
+ // https://github.com/shikijs/shiki/compare/main...brillout:shiki:brillout/highlight-color-param
13
+ import { transformerNotationHighlight } from '@brillout/shiki-transformers';
9
14
  import { rehypeMetaToProps } from './code-blocks/rehypeMetaToProps.js';
10
15
  import { remarkDetype } from './code-blocks/remarkDetype.js';
11
16
  import { shikiTransformerAutoLinks } from './code-blocks/shikiTransformerAutoLinks.js';
@@ -17,7 +22,12 @@ const prettyCode = [
17
22
  {
18
23
  theme: 'github-light',
19
24
  keepBackground: false,
20
- transformers: [transformerNotationDiff(), transformerNotationHighlight(), shikiTransformerAutoLinks()],
25
+ transformers: [
26
+ transformerNotationDiff(),
27
+ transformerNotationHighlight(),
28
+ transformerNotationWordHighlight(),
29
+ shikiTransformerAutoLinks(),
30
+ ],
21
31
  },
22
32
  ];
23
33
  const rehypePlugins = [prettyCode, [rehypeMetaToProps]];
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.16.24",
3
+ "version": "0.16.26",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",
7
+ "@brillout/shiki-transformers": "^4.0.2",
7
8
  "@docsearch/css": "3.9.0",
8
9
  "@docsearch/react": "3.9.0",
9
10
  "@mdx-js/mdx": "3.0.1",
10
11
  "@mdx-js/react": "3.0.1",
11
12
  "@mdx-js/rollup": "3.0.1",
12
- "@shikijs/transformers": "1.2.0",
13
+ "@shikijs/transformers": "^4.0.2",
13
14
  "@vitejs/plugin-react-swc": "^3.10.2",
14
15
  "detype": "^2.0.2",
15
16
  "estree-util-value-to-estree": "^3.5.0",
@@ -52,6 +52,7 @@ async function onRenderClient(pageContext: PageContextClient) {
52
52
  installSectionUrlHashs()
53
53
  setHydrationIsFinished()
54
54
  initGoogleAnalytics(pageContext)
55
+ initUmami(pageContext)
55
56
 
56
57
  globalObject.isNotFirstRender = true
57
58
  }
@@ -104,3 +105,46 @@ declare global {
104
105
  gtag: (...args: any[]) => void
105
106
  }
106
107
  }
108
+
109
+ async function initUmami(pageContext: PageContextClient) {
110
+ // Only add script tag on first render
111
+ if (globalObject.isNotFirstRender) {
112
+ return
113
+ }
114
+
115
+ // Simple way to plug in umami
116
+ const umamiId = pageContext.config.docpress.umamiId
117
+ if (!umamiId) {
118
+ return
119
+ }
120
+
121
+ try {
122
+ await addScript('https://cloud.umami.is/script.js', {
123
+ 'data-website-id': umamiId,
124
+ })
125
+ } catch {
126
+ // Umami analytics unavailable
127
+ }
128
+ }
129
+
130
+ /** https://umami.is/docs/tracker-functions */
131
+ type Umami = {
132
+ track: {
133
+ (): void
134
+ (eventName: string): void
135
+ (data: object): void
136
+ (eventName: string, data: object): void
137
+ }
138
+ identify: {
139
+ (uniqueId: string): void
140
+ (data: object): string
141
+ (uniqueId: string, data: object): void
142
+ }
143
+ }
144
+
145
+ declare global {
146
+ interface Window {
147
+ /** Script load is not guaranteed */
148
+ umami?: Umami
149
+ }
150
+ }
package/types/Config.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { Config, ChoicesConfig }
1
+ export type { Config }
2
2
 
3
3
  import type { HeadingDefinition, HeadingDetachedDefinition } from './Heading.js'
4
4
  import type React from 'react'
@@ -35,6 +35,7 @@ type Config = {
35
35
  indexName: string
36
36
  }
37
37
  googleAnalytics?: string
38
+ umamiId?: string
38
39
 
39
40
  i18n?: true
40
41
  pressKit?: true
@@ -49,6 +50,7 @@ type Config = {
49
50
  navLogoTextStyle?: React.CSSProperties
50
51
 
51
52
  globalNote?: React.ReactNode
53
+ choices?: Record<string, Choice>
52
54
  }
53
55
 
54
56
  /** Order in Algolia search results */
@@ -60,8 +62,6 @@ type Category =
60
62
  hide?: boolean
61
63
  }
62
64
 
63
- type ChoicesConfig = Record<string, Choice>
64
-
65
65
  type Choice = {
66
66
  choices: string[]
67
67
  default: string
@@ -2,12 +2,17 @@ export { addScript }
2
2
 
3
3
  import { genPromise } from './genPromise.js'
4
4
 
5
- async function addScript(src: string) {
5
+ async function addScript(src: string, attributes?: Record<string, string>) {
6
6
  const { promise, resolve, reject } = genPromise()
7
7
  const script = document.createElement('script')
8
8
  script.onload = () => resolve()
9
9
  script.onerror = () => reject(new Error(`Failed to load script: ${src}`))
10
10
  script.src = src
11
+ if (attributes) {
12
+ for (const [name, value] of Object.entries(attributes)) {
13
+ script.setAttribute(name, value)
14
+ }
15
+ }
11
16
  document.head.appendChild(script)
12
17
  return promise
13
18
  }
package/vite.config.ts CHANGED
@@ -7,7 +7,12 @@ import { parsePageSections } from './parsePageSections.js'
7
7
  import rehypePrettyCode from 'rehype-pretty-code'
8
8
  import remarkGfm from 'remark-gfm'
9
9
  import remarkDirective from 'remark-directive'
10
- import { transformerNotationDiff, transformerNotationHighlight } from '@shikijs/transformers'
10
+ import { transformerNotationDiff, transformerNotationWordHighlight } from '@shikijs/transformers'
11
+ // @brillout/shiki-transformers adds color parameter `[!code highlight:#abc]` where #abc is a color
12
+ // https://github.com/shikijs/shiki/issues/1264
13
+ // https://shiki.style/packages/transformers#transformernotationhighlight
14
+ // https://github.com/shikijs/shiki/compare/main...brillout:shiki:brillout/highlight-color-param
15
+ import { transformerNotationHighlight } from '@brillout/shiki-transformers'
11
16
  import { rehypeMetaToProps } from './code-blocks/rehypeMetaToProps.js'
12
17
  import { remarkDetype } from './code-blocks/remarkDetype.js'
13
18
  import { shikiTransformerAutoLinks } from './code-blocks/shikiTransformerAutoLinks.js'
@@ -20,7 +25,12 @@ const prettyCode = [
20
25
  {
21
26
  theme: 'github-light',
22
27
  keepBackground: false,
23
- transformers: [transformerNotationDiff(), transformerNotationHighlight(), shikiTransformerAutoLinks()],
28
+ transformers: [
29
+ transformerNotationDiff(),
30
+ transformerNotationHighlight(),
31
+ transformerNotationWordHighlight(),
32
+ shikiTransformerAutoLinks(),
33
+ ],
24
34
  },
25
35
  ]
26
36
  const rehypePlugins: any = [prettyCode, [rehypeMetaToProps]]