@dominikcz/greg 0.9.27

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.
Files changed (183) hide show
  1. package/README.md +397 -0
  2. package/bin/greg.js +241 -0
  3. package/bin/init.js +351 -0
  4. package/bin/templates/docs/getting-started.md +47 -0
  5. package/bin/templates/docs/index.md +11 -0
  6. package/bin/templates/greg.config.js +39 -0
  7. package/bin/templates/greg.config.ts +38 -0
  8. package/bin/templates/index.html +16 -0
  9. package/bin/templates/src/App.svelte +5 -0
  10. package/bin/templates/src/app.css +20 -0
  11. package/bin/templates/src/main.js +9 -0
  12. package/bin/templates/svelte.config.js +1 -0
  13. package/bin/templates/tsconfig.json +21 -0
  14. package/bin/templates/vite.config.js +23 -0
  15. package/docs/__partials/markdown/examples/basic.md +4 -0
  16. package/docs/__partials/markdown/examples/diff.md +10 -0
  17. package/docs/__partials/markdown/examples/focus.md +5 -0
  18. package/docs/__partials/markdown/examples/language-title.md +3 -0
  19. package/docs/__partials/markdown/examples/line-highlighting.md +5 -0
  20. package/docs/__partials/markdown/examples/line-numbers.md +5 -0
  21. package/docs/__partials/note.md +4 -0
  22. package/docs/guide/__shared-warning.md +4 -0
  23. package/docs/guide/asset-handling.md +88 -0
  24. package/docs/guide/deploying.md +162 -0
  25. package/docs/guide/getting-started.md +334 -0
  26. package/docs/guide/index.md +23 -0
  27. package/docs/guide/localization.md +290 -0
  28. package/docs/guide/markdown/code.md +95 -0
  29. package/docs/guide/markdown/components-and-mermaid.md +43 -0
  30. package/docs/guide/markdown/containers.md +110 -0
  31. package/docs/guide/markdown/header-anchors.md +34 -0
  32. package/docs/guide/markdown/includes.md +84 -0
  33. package/docs/guide/markdown/index.md +20 -0
  34. package/docs/guide/markdown/inline-attributes.md +21 -0
  35. package/docs/guide/markdown/links-and-toc.md +64 -0
  36. package/docs/guide/markdown/math.md +54 -0
  37. package/docs/guide/markdown/syntax-highlighting.md +75 -0
  38. package/docs/guide/routing.md +150 -0
  39. package/docs/guide/using-svelte.md +88 -0
  40. package/docs/guide/versioning.md +281 -0
  41. package/docs/incompatibilities.md +48 -0
  42. package/docs/index.md +43 -0
  43. package/docs/reference/badge.md +100 -0
  44. package/docs/reference/carbon-ads.md +46 -0
  45. package/docs/reference/code-group.md +126 -0
  46. package/docs/reference/home-page.md +232 -0
  47. package/docs/reference/index.md +18 -0
  48. package/docs/reference/markdowndocs.md +275 -0
  49. package/docs/reference/outline.md +79 -0
  50. package/docs/reference/search.md +263 -0
  51. package/docs/reference/steps.md +200 -0
  52. package/docs/reference/team-page.md +189 -0
  53. package/docs/reference/theme.md +150 -0
  54. package/fakeDocsGenerator/generate_docs.js +310 -0
  55. package/package.json +92 -0
  56. package/scripts/build-versions.js +609 -0
  57. package/scripts/generate-static.js +79 -0
  58. package/scripts/render-markdown.js +420 -0
  59. package/src/lib/MarkdownDocs/AiChat.svelte +936 -0
  60. package/src/lib/MarkdownDocs/BackToTop.svelte +68 -0
  61. package/src/lib/MarkdownDocs/Breadcrumb.svelte +68 -0
  62. package/src/lib/MarkdownDocs/DocsNavigation.svelte +149 -0
  63. package/src/lib/MarkdownDocs/DocsSiteHeader.svelte +758 -0
  64. package/src/lib/MarkdownDocs/DocsVersionSwitcher.svelte +103 -0
  65. package/src/lib/MarkdownDocs/MarkdownDocs.svelte +2115 -0
  66. package/src/lib/MarkdownDocs/MarkdownRenderer.svelte +487 -0
  67. package/src/lib/MarkdownDocs/Outline.svelte +238 -0
  68. package/src/lib/MarkdownDocs/PrevNext.svelte +115 -0
  69. package/src/lib/MarkdownDocs/SearchModal.svelte +1241 -0
  70. package/src/lib/MarkdownDocs/TreeView.svelte +32 -0
  71. package/src/lib/MarkdownDocs/TreeViewItem.svelte +219 -0
  72. package/src/lib/MarkdownDocs/VersionOutdatedNotice.svelte +72 -0
  73. package/src/lib/MarkdownDocs/__tests__/codeDirectives.test.js +54 -0
  74. package/src/lib/MarkdownDocs/__tests__/common.test.js +41 -0
  75. package/src/lib/MarkdownDocs/__tests__/docsExamplesLint.test.js +77 -0
  76. package/src/lib/MarkdownDocs/__tests__/fixtures/docs/markdown/__partial-basic.md +3 -0
  77. package/src/lib/MarkdownDocs/__tests__/fixtures/docs/markdown/snippet.js +9 -0
  78. package/src/lib/MarkdownDocs/__tests__/fixtures/includes/part.md +11 -0
  79. package/src/lib/MarkdownDocs/__tests__/fixtures/includes/wrapper.md +5 -0
  80. package/src/lib/MarkdownDocs/__tests__/fixtures/snippets/sample.js +8 -0
  81. package/src/lib/MarkdownDocs/__tests__/fixtures/snippets/sample.md +5 -0
  82. package/src/lib/MarkdownDocs/__tests__/helpers.js +67 -0
  83. package/src/lib/MarkdownDocs/__tests__/localeUtils.test.js +204 -0
  84. package/src/lib/MarkdownDocs/__tests__/markdown.test.js +704 -0
  85. package/src/lib/MarkdownDocs/__tests__/markdownRendererRuntime.test.js +65 -0
  86. package/src/lib/MarkdownDocs/__tests__/searchIndexBuilder.test.js +117 -0
  87. package/src/lib/MarkdownDocs/__tests__/sqliteStore.test.js +202 -0
  88. package/src/lib/MarkdownDocs/__tests__/useRouter.test.js +16 -0
  89. package/src/lib/MarkdownDocs/ai/adapters/customAdapter.js +14 -0
  90. package/src/lib/MarkdownDocs/ai/adapters/customAdapter.ts +43 -0
  91. package/src/lib/MarkdownDocs/ai/adapters/ollamaAdapter.js +81 -0
  92. package/src/lib/MarkdownDocs/ai/adapters/ollamaAdapter.ts +116 -0
  93. package/src/lib/MarkdownDocs/ai/adapters/openaiAdapter.js +92 -0
  94. package/src/lib/MarkdownDocs/ai/adapters/openaiAdapter.ts +137 -0
  95. package/src/lib/MarkdownDocs/ai/aiProvider.ts +31 -0
  96. package/src/lib/MarkdownDocs/ai/characters.js +52 -0
  97. package/src/lib/MarkdownDocs/ai/characters.ts +69 -0
  98. package/src/lib/MarkdownDocs/ai/chunkStore.ts +25 -0
  99. package/src/lib/MarkdownDocs/ai/chunker.js +85 -0
  100. package/src/lib/MarkdownDocs/ai/chunker.ts +135 -0
  101. package/src/lib/MarkdownDocs/ai/docLinker.js +26 -0
  102. package/src/lib/MarkdownDocs/ai/docLinker.ts +36 -0
  103. package/src/lib/MarkdownDocs/ai/promptBuilder.js +33 -0
  104. package/src/lib/MarkdownDocs/ai/promptBuilder.ts +53 -0
  105. package/src/lib/MarkdownDocs/ai/ragPipeline.js +54 -0
  106. package/src/lib/MarkdownDocs/ai/ragPipeline.ts +106 -0
  107. package/src/lib/MarkdownDocs/ai/stores/memoryStore.js +88 -0
  108. package/src/lib/MarkdownDocs/ai/stores/memoryStore.ts +112 -0
  109. package/src/lib/MarkdownDocs/ai/stores/sqliteStore.ts +372 -0
  110. package/src/lib/MarkdownDocs/ai/types.ts +71 -0
  111. package/src/lib/MarkdownDocs/aiServer.js +288 -0
  112. package/src/lib/MarkdownDocs/codeDirectives.js +191 -0
  113. package/src/lib/MarkdownDocs/codeFenceInfo.js +45 -0
  114. package/src/lib/MarkdownDocs/codeGroup.ts +46 -0
  115. package/src/lib/MarkdownDocs/common.ts +47 -0
  116. package/src/lib/MarkdownDocs/docsUtils.js +281 -0
  117. package/src/lib/MarkdownDocs/index.plugins.js +22 -0
  118. package/src/lib/MarkdownDocs/layouts/LayoutDoc.svelte +8 -0
  119. package/src/lib/MarkdownDocs/layouts/LayoutHome.svelte +58 -0
  120. package/src/lib/MarkdownDocs/layouts/LayoutPage.svelte +9 -0
  121. package/src/lib/MarkdownDocs/loadGregConfig.js +82 -0
  122. package/src/lib/MarkdownDocs/localeUtils.ts +682 -0
  123. package/src/lib/MarkdownDocs/markdownRendererRuntime.ts +314 -0
  124. package/src/lib/MarkdownDocs/mermaidThemes.js +319 -0
  125. package/src/lib/MarkdownDocs/navigationUtils.js +22 -0
  126. package/src/lib/MarkdownDocs/rehypeCodeGroup.js +326 -0
  127. package/src/lib/MarkdownDocs/rehypeCodeTitle.js +96 -0
  128. package/src/lib/MarkdownDocs/rehypeToc.js +170 -0
  129. package/src/lib/MarkdownDocs/remarkCodeMeta.js +22 -0
  130. package/src/lib/MarkdownDocs/remarkContainers.js +329 -0
  131. package/src/lib/MarkdownDocs/remarkCustomAnchors.js +42 -0
  132. package/src/lib/MarkdownDocs/remarkEscapeSvelte.js +33 -0
  133. package/src/lib/MarkdownDocs/remarkGlobalComponents.js +65 -0
  134. package/src/lib/MarkdownDocs/remarkImports.js +461 -0
  135. package/src/lib/MarkdownDocs/remarkImportsBrowser.js +349 -0
  136. package/src/lib/MarkdownDocs/remarkInlineAttrs.js +95 -0
  137. package/src/lib/MarkdownDocs/remarkMathToHtml.js +138 -0
  138. package/src/lib/MarkdownDocs/searchIndexBuilder.js +497 -0
  139. package/src/lib/MarkdownDocs/searchServer.js +263 -0
  140. package/src/lib/MarkdownDocs/treeViewTypes.ts +11 -0
  141. package/src/lib/MarkdownDocs/useRouter.svelte.ts +114 -0
  142. package/src/lib/MarkdownDocs/useSplitter.svelte.ts +33 -0
  143. package/src/lib/MarkdownDocs/versioningDefaults.js +20 -0
  144. package/src/lib/MarkdownDocs/vitePluginAiServer.js +204 -0
  145. package/src/lib/MarkdownDocs/vitePluginCopyDocs.js +153 -0
  146. package/src/lib/MarkdownDocs/vitePluginFrontmatter.js +109 -0
  147. package/src/lib/MarkdownDocs/vitePluginGregConfig.js +108 -0
  148. package/src/lib/MarkdownDocs/vitePluginSearchIndex.js +57 -0
  149. package/src/lib/MarkdownDocs/vitePluginSearchServer.js +190 -0
  150. package/src/lib/components/Badge.svelte +59 -0
  151. package/src/lib/components/Button.svelte +138 -0
  152. package/src/lib/components/CarbonAds.svelte +99 -0
  153. package/src/lib/components/CodeGroup.svelte +102 -0
  154. package/src/lib/components/Feature.svelte +209 -0
  155. package/src/lib/components/Features.svelte +123 -0
  156. package/src/lib/components/Hero.svelte +399 -0
  157. package/src/lib/components/Image.svelte +128 -0
  158. package/src/lib/components/Link.svelte +105 -0
  159. package/src/lib/components/SocialLink.svelte +84 -0
  160. package/src/lib/components/SocialLinks.svelte +33 -0
  161. package/src/lib/components/Steps.svelte +143 -0
  162. package/src/lib/components/TeamMember.svelte +273 -0
  163. package/src/lib/components/TeamMembers.svelte +81 -0
  164. package/src/lib/components/TeamPage.svelte +65 -0
  165. package/src/lib/components/TeamPageSection.svelte +108 -0
  166. package/src/lib/components/TeamPageTitle.svelte +89 -0
  167. package/src/lib/components/index.js +24 -0
  168. package/src/lib/portal/context.js +12 -0
  169. package/src/lib/portal/index.js +3 -0
  170. package/src/lib/portal/portal.svelte +14 -0
  171. package/src/lib/portal/slot.svelte +8 -0
  172. package/src/lib/scss/__code.scss +128 -0
  173. package/src/lib/scss/__containers.scss +99 -0
  174. package/src/lib/scss/__markdown.scss +447 -0
  175. package/src/lib/scss/__scrollbar.scss +60 -0
  176. package/src/lib/scss/__steps.scss +100 -0
  177. package/src/lib/scss/__theme.scss +238 -0
  178. package/src/lib/scss/__toc.scss +55 -0
  179. package/src/lib/scss/__utilities.scss +7 -0
  180. package/src/lib/scss/greg.scss +9 -0
  181. package/src/lib/spinner/spinner.svelte +42 -0
  182. package/svelte.config.js +146 -0
  183. package/types/index.d.ts +456 -0
@@ -0,0 +1,64 @@
1
+ ---
2
+ title: Links and TOC
3
+ order: 2
4
+ ---
5
+
6
+ # Links and TOC
7
+
8
+ ## Internal links
9
+
10
+ Internal links use SPA navigation and update the page without a full reload:
11
+
12
+ ```md
13
+ [Getting Started](../getting-started)
14
+ [API reference](/reference/api)
15
+ [Back to top](#)
16
+ ```
17
+
18
+ Output:
19
+
20
+ [Getting Started](../getting-started)
21
+ [API reference](/reference/api)
22
+ [Back to top](#)
23
+
24
+ `.md` and `.html` extensions are stripped automatically.
25
+
26
+ ## Fragment links (same page)
27
+
28
+ ```md
29
+ [See the examples below](#examples)
30
+ ```
31
+
32
+ Output:
33
+
34
+ [See the examples below](#examples)
35
+
36
+ Clicking a same-page `#anchor` link scrolls smoothly without a history push.
37
+
38
+ ## External links
39
+
40
+ External links open via the browser's default navigation.
41
+
42
+ ```md
43
+ [Project website](https://example.com)
44
+ ```
45
+
46
+ Output:
47
+
48
+ [Project website](https://example.com)
49
+
50
+ ## Table of contents - `[[toc]]`
51
+
52
+ Insert an inline table of contents at any point in a page:
53
+
54
+ ```md
55
+ [[toc]]
56
+ ```
57
+
58
+ Output:
59
+
60
+ [[toc]]
61
+
62
+ By default h2 and h3 headings are included. The right-side **Outline** panel is
63
+ a persistent alternative. See `outline` prop in the
64
+ [`<MarkdownDocs>` reference](/reference/markdowndocs).
@@ -0,0 +1,54 @@
1
+ ---
2
+ title: Math equations
3
+ order: 6
4
+ ---
5
+
6
+ # Math equations
7
+
8
+ Math rendering via MathJax SVG must be enabled in `svelte.config.js`:
9
+
10
+ ```js
11
+ const gregConfig = {
12
+ markdown: {
13
+ math: true,
14
+ },
15
+ };
16
+ ```
17
+
18
+ Output:
19
+
20
+ ```js
21
+ const gregConfig = {
22
+ markdown: {
23
+ math: true,
24
+ },
25
+ };
26
+ ```
27
+
28
+ ## Inline math
29
+
30
+ ```md
31
+ The quadratic formula is $x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$.
32
+ ```
33
+
34
+ Output:
35
+
36
+ Requires `math: true`.
37
+
38
+ The quadratic formula is $x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$.
39
+
40
+ ## Display math
41
+
42
+ ```md
43
+ $$
44
+ \sum_{i=1}^{n} i = \frac{n(n+1)}{2}
45
+ $$
46
+ ```
47
+
48
+ Output:
49
+
50
+ Requires `math: true`.
51
+
52
+ $$
53
+ \sum_{i=1}^{n} i = \frac{n(n+1)}{2}
54
+ $$
@@ -0,0 +1,75 @@
1
+ ---
2
+ title: Syntax highlighting
3
+ order: 4
4
+ ---
5
+
6
+ ## Syntax highlighting
7
+
8
+ Code blocks are highlighted at build time by [Shiki](https://shiki.style) using
9
+ `github-light` (light mode) and `github-dark` (dark mode):
10
+
11
+ <<< /__partials/markdown/examples/basic.md
12
+
13
+ Output:
14
+
15
+ <!--@include: /__partials/markdown/examples/basic.md-->
16
+
17
+ Supported languages include `javascript`, `typescript`, `bash`, `json`, `html`,
18
+ `css`, `yaml`, `markdown`, `svelte`, `txt`.
19
+
20
+ ## Code highlighting features
21
+
22
+ Greg supports code highlighting directives in both build-time Shiki output and
23
+ runtime rendering.
24
+
25
+ | Feature | Supported |
26
+ | ------------------------------------ | --------- |
27
+ | Language fence (` ```ts `) | ✅ |
28
+ | Title in meta (` ```ts [file.ts] `) | ✅ |
29
+ | Code groups (`::: code-group`) | ✅ |
30
+ | Highlight lines (` ```ts{2,4} `) | ✅ |
31
+ | Focused lines (`// [!code focus]`) | ✅ |
32
+ | Diff markers (`// [!code ++]`, `--`) | ✅ |
33
+
34
+ Language + title (supported):
35
+
36
+ <<< /__partials/markdown/examples/language-title.md
37
+
38
+ Output:
39
+
40
+ <!--@include: /__partials/markdown/examples/language-title.md-->
41
+
42
+ Line highlighting:
43
+
44
+ <<< /__partials/markdown/examples/line-highlighting.md
45
+
46
+ Output:
47
+
48
+ <!--@include: /__partials/markdown/examples/line-highlighting.md-->
49
+
50
+ Line numbers:
51
+
52
+ <<< /__partials/markdown/examples/line-numbers.md
53
+
54
+ Output:
55
+
56
+ <!--@include: /__partials/markdown/examples/line-numbers.md-->
57
+
58
+ Diff markers:
59
+
60
+ <<< /__partials/markdown/examples/diff.md
61
+
62
+ Output:
63
+
64
+ <!--@include: /__partials/markdown/examples/diff.md-->
65
+
66
+ Focused lines:
67
+
68
+ <<< /__partials/markdown/examples/focus.md
69
+
70
+ Output:
71
+
72
+ <!--@include: /__partials/markdown/examples/focus.md-->
73
+
74
+ See [Incompatibilities](/incompatibilities) for areas outside code
75
+ highlighting and platform-level differences.
@@ -0,0 +1,150 @@
1
+ ---
2
+ title: Routing
3
+ order: 3
4
+ ---
5
+
6
+ # Routing
7
+
8
+ ## File-based routing
9
+
10
+ Greg uses **file-based routing**. Every `.md` file inside the `docs/` folder
11
+ becomes a page at the corresponding URL path:
12
+
13
+ ```
14
+ docs/index.md → /
15
+ docs/guide/getting-started.md → /guide/getting-started
16
+ docs/reference/api.md → /reference/api
17
+ ```
18
+
19
+ `index.md` files map to the parent folder URL:
20
+
21
+ ```
22
+ docs/guide/index.md → /guide
23
+ ```
24
+
25
+
26
+ ## Partial files
27
+
28
+ Any file whose name starts with `__` (double underscore) is treated as a
29
+ **partial** — it is excluded from routing and the sidebar, but can be
30
+ included in other pages with the `<!--@include:-->` directive.
31
+
32
+ ```
33
+ docs/guide/__shared-warning.md ← not a page, only includable
34
+ ```
35
+
36
+
37
+ ## Sidebar navigation
38
+
39
+ The sidebar is **generated automatically** from the folder / file structure.
40
+ No manual configuration is required.
41
+
42
+ Rules:
43
+ - Folders become collapsible section headers.
44
+ - Files become leaf links.
45
+ - Names are capitalised automatically (`getting-started` → `Getting-started`).
46
+ - `index.md` files are attached to their parent folder node.
47
+ - The root `index.md` (`docs/index.md`) is hidden from the sidebar.
48
+
49
+ ### Sidebar link targets
50
+
51
+ For manual sidebar entries in `greg.config.js`, links respect the `target`
52
+ attribute:
53
+
54
+ - default is `_self` (same tab)
55
+ - use `target: '_blank'` to open a new tab
56
+
57
+ ```js
58
+ sidebar: [
59
+ { text: 'Guide', auto: '/guide' },
60
+ { text: 'GitHub', link: 'https://github.com/dominikcz/greg' }, // _self
61
+ {
62
+ text: 'GitHub (new tab)',
63
+ link: 'https://github.com/dominikcz/greg',
64
+ target: '_blank',
65
+ rel: 'noopener noreferrer',
66
+ },
67
+ ]
68
+ ```
69
+
70
+ ### Ordering
71
+
72
+ Items within each level are sorted by the frontmatter `order` field (lower
73
+ values appear first). Items without `order` sort after ordered ones; among
74
+ equal-order items, folders come before leaf pages, then alphabetically by label.
75
+
76
+ ```yaml
77
+ ---
78
+ title: Getting Started
79
+ order: 1
80
+ ---
81
+ ```
82
+
83
+ Folders use the `order` from their `index.md`:
84
+
85
+ ```yaml
86
+ # docs/guide/index.md
87
+ ---
88
+ title: Guide
89
+ order: 2
90
+ ---
91
+ ```
92
+
93
+
94
+ ## SPA navigation
95
+
96
+ Greg is a **single-page application** — navigating between pages never triggers
97
+ a full page reload. Internal links are intercepted and handled by the built-in
98
+ router:
99
+
100
+ ```md
101
+ [Getting Started](./getting-started) <!-- relative -->
102
+ [API Reference](/reference/api) <!-- absolute -->
103
+ [Go to anchor](#section-heading) <!-- same-page anchor -->
104
+ [Other page + anchor](./other#some-section) <!-- cross-page anchor -->
105
+ ```
106
+
107
+ Both `.md` and `.html` extensions in links are stripped automatically:
108
+
109
+ ```md
110
+ [link](./page.md) → navigates to /…/page
111
+ [link](./page.html) → navigates to /…/page
112
+ ```
113
+
114
+ External links (starting with `http://`, `https://`, `//`, etc.) open normally
115
+ in the browser.
116
+
117
+ If a Markdown link (or HTML anchor in Markdown) has an explicit `target`, Greg
118
+ respects it.
119
+
120
+
121
+ ## `srcDir` prop
122
+
123
+ The `srcDir` prop of `<MarkdownDocs>` controls docs URL prefix.
124
+ Its default is `/` (root). If your docs are served under a custom prefix,
125
+ pass the new value:
126
+
127
+ ```svelte
128
+ <MarkdownDocs srcDir="/documentation" version="2.0.0" />
129
+ ```
130
+
131
+ The Vite `vitePluginSearchIndex` plug-in must use matching `srcDir` URL prefix:
132
+
133
+ ```js
134
+ // vite.config.js
135
+ vitePluginSearchIndex({ docsDir: 'docs', srcDir: '/documentation' })
136
+ ```
137
+
138
+
139
+ ## 404 behaviour
140
+
141
+ When a URL matches no Markdown file, the engine displays the folder label as
142
+ a heading and renders any `children` snippet passed to `<MarkdownDocs>`:
143
+
144
+ ```svelte
145
+ <MarkdownDocs srcDir="/" version="1.0.0">
146
+ {#snippet children()}
147
+ <p>Select a topic from the sidebar.</p>
148
+ {/snippet}
149
+ </MarkdownDocs>
150
+ ```
@@ -0,0 +1,88 @@
1
+ ---
2
+ title: Using Svelte in Markdown
3
+ order: 4
4
+ ---
5
+
6
+ # Using Svelte in Markdown
7
+
8
+ Greg processes every `.md` file through [mdsvex](https://mdsvex.pngwn.io/), a
9
+ Markdown preprocessor for Svelte. This means you can mix regular Markdown with
10
+ Svelte components, reactive state and template logic anywhere in your pages.
11
+
12
+
13
+ ## Auto-imported components
14
+
15
+ All Greg UI components are automatically available in every Markdown page — no
16
+ `<script>` block needed:
17
+
18
+ ```md
19
+ ### Status <Badge type="tip" text="stable" />
20
+
21
+ <Features features={[
22
+ { title: 'Fast', details: 'Shiki highlights at build time.' },
23
+ { title: 'Searchable', details: 'Fuse.js fuzzy search included.' },
24
+ ]} />
25
+ ```
26
+
27
+ The following components are always in scope:
28
+
29
+ `Badge`, `Button`, `Image`, `Link`, `Feature`, `Features`, `Hero`,
30
+ `SocialLink`, `SocialLinks`, `Steps`, `TeamMember`, `TeamMembers`,
31
+ `TeamPage`, `TeamPageTitle`, `TeamPageSection`
32
+
33
+
34
+ ## Adding a `<script>` block
35
+
36
+ You can add your own `<script>` block to a page:
37
+
38
+ ```md
39
+ <script>
40
+ import { onMount } from 'svelte';
41
+ let now = $state(new Date().toLocaleTimeString());
42
+ onMount(() => setInterval(() => now = new Date().toLocaleTimeString(), 1000));
43
+ </script>
44
+
45
+ Current time: **{now}**
46
+ ```
47
+
48
+ > **Note:** mdsvex does not support `<script module>`. Use a plain `<script>`.
49
+ > The `setup` attribute is stripped automatically if present, so copied snippets
50
+ > using that attribute still work.
51
+
52
+
53
+ ## Template syntax
54
+
55
+ Standard Svelte template syntax works inside Markdown:
56
+
57
+ ```md
58
+ {#each items as item}
59
+ - {item.name}
60
+ {/each}
61
+
62
+ {#if showNote}
63
+ > [!NOTE]
64
+ > This note is conditional.
65
+ {/if}
66
+ ```
67
+
68
+
69
+ ## Escaping `{` and `}`
70
+
71
+ Bare `{…}` expressions in regular Markdown text that are **not** part of Svelte
72
+ syntax may cause parse errors. Escape them with HTML entities:
73
+
74
+ ```md
75
+ Pass an options object like `&#123; key: value &#125;`.
76
+ ```
77
+
78
+ Inside fenced code blocks and backtick inline code, `{` and `}` are escaped
79
+ automatically by the `remarkEscapeSvelte` plugin — no action required.
80
+
81
+
82
+ ## Limitations
83
+
84
+ - `<script module>` is not supported inside `.md` files.
85
+ - `<style>` blocks inside `.md` files are processed by Svelte but are scoped to
86
+ the component — they affect the whole page body.
87
+ - Hot-module replacement works for Markdown content, but adding or removing a
88
+ file requires a server restart (Vite re-globs the module list).
@@ -0,0 +1,281 @@
1
+ ---
2
+ title: Versioning
3
+ order: 4
4
+ ---
5
+
6
+ ## Overview
7
+
8
+ Greg supports multi-version documentation builds with two source strategies:
9
+
10
+ - `branches` (default): reads docs from Git branches/refs
11
+ - `folders`: reads docs from local version directories
12
+
13
+ Both strategies produce the same final artifact (`<outDir>/__versions/<version>` + `versions.json`).
14
+ After build, Greg also syncs the default version to `dist/` so the root output can be hosted directly.
15
+ The difference is where source docs come from and how reproducible each build is.
16
+
17
+ `branches` is commit-oriented: each version is tied to a Git ref and resolved to a SHA.
18
+ This is usually best for released docs because output can be reproduced from repository history and branch build cache can speed up repeated runs.
19
+
20
+ `folders` is workspace-oriented: each version is read from local directories in your current working tree.
21
+ This is usually best when you keep multiple docs trees side-by-side, want quick local iteration, or do not want to depend on Git refs.
22
+
23
+ ### Strategy Philosophy, Pros and Cons
24
+
25
+ `branches`:
26
+
27
+ - Pros:
28
+ - reproducible from Git history (ref -> commit SHA)
29
+ - good fit for release workflow (`main`, `release/*`, tags)
30
+ - cache re-use when the same SHA was already built
31
+ - Cons:
32
+ - requires valid refs and docs content available in those refs
33
+ - more moving parts (snapshot + branch cache)
34
+
35
+ `folders`:
36
+
37
+ - Pros:
38
+ - simple mental model: build exactly what exists in directories now
39
+ - very convenient for local development and migration periods
40
+ - no Git ref resolution required
41
+ - Cons:
42
+ - output depends on current workspace state (less reproducible by default)
43
+ - no commit-based cache reuse per version
44
+
45
+ Recommended choice:
46
+
47
+ - choose `branches` when docs versions should follow repository history and release refs
48
+ - choose `folders` when docs versions are maintained as separate directory trees in one checkout
49
+
50
+ ## Rules
51
+
52
+ 1. Configure versioning in `greg.config.js` (or `greg.config.ts`) under `versioning`.
53
+ 2. Pick one strategy in `versioning.strategy`.
54
+ 3. Define version-to-source mapping:
55
+ - `branches[]`: `version` + `branch`
56
+ - `folders[]`: `version` + `dir`
57
+ 4. Set `default` and optional `aliases` for selector behavior.
58
+
59
+ ## Branch Mode Guide
60
+
61
+ Use branch mode when each docs version should be built from a Git branch/ref.
62
+
63
+ Set:
64
+
65
+ 1. `strategy: "branches"`
66
+ 2. `branches[]` entries with `version`, `branch`, optional `docsDir`, `title`
67
+ 3. `default` and optional `aliases`
68
+
69
+ Example:
70
+
71
+ ```js [greg.config.js]
72
+ export default {
73
+ versioning: {
74
+ strategy: "branches",
75
+ default: "latest",
76
+ aliases: {
77
+ latest: "2.1",
78
+ stable: "2.0"
79
+ },
80
+ branches: [
81
+ { version: "2.1", branch: "main", title: "2.1" },
82
+ { version: "2.0", branch: "release/2.0", title: "2.0" }
83
+ ]
84
+ }
85
+ };
86
+ ```
87
+
88
+ How versioning works in this mode:
89
+
90
+ 1. For every `branches[]` entry, Greg resolves `branch` to a commit SHA.
91
+ 2. Greg creates or reuses a cached docs snapshot for that SHA under `.greg/version-cache/sources/...`.
92
+ 3. Greg builds the site for that snapshot (or reuses cached build output for the same SHA).
93
+ 4. Greg copies final output to `<outDir>/__versions/<version>`.
94
+ 5. After all versions are processed, Greg writes one manifest file to `<outDir>/__versions/versions.json`.
95
+ 6. Greg syncs the default version output to `dist/`.
96
+
97
+ Important: Greg does not checkout branches in your working tree. It reads files directly from Git objects.
98
+
99
+ ## Folder Mode Guide
100
+
101
+ Use folder mode when each docs version should come from a directory in your working tree.
102
+
103
+ Set:
104
+
105
+ 1. `strategy: "folders"`
106
+ 2. `folders[]` entries with `version`, `dir`, optional `srcDir`, `title`
107
+ 3. `default` and optional `aliases`
108
+
109
+ Example:
110
+
111
+ ```js [greg.config.js]
112
+ export default {
113
+ versioning: {
114
+ strategy: "folders",
115
+ default: "latest",
116
+ aliases: {
117
+ latest: "2.1",
118
+ stable: "2.0"
119
+ },
120
+ folders: [
121
+ { version: "2.1", dir: "./docs", title: "2.1" },
122
+ { version: "2.0", dir: "./versions/2.0/docs", title: "2.0" }
123
+ ]
124
+ }
125
+ };
126
+ ```
127
+
128
+ How versioning works in this mode:
129
+
130
+ 1. For every `folders[]` entry, Greg resolves `dir` to an absolute path.
131
+ 2. Greg runs a full Vite build using that directory as docs source.
132
+ 3. The temporary build output is copied to `<outDir>/__versions/<version>`.
133
+ 4. After all versions are processed, Greg writes `<outDir>/__versions/versions.json`.
134
+ 5. Greg syncs the default version output to `dist/`.
135
+
136
+ Important: in folder mode, each configured version is rebuilt from current local files on each run.
137
+
138
+ ## Commands
139
+
140
+ Run commands only after config is in place.
141
+
142
+ Recommended entry point:
143
+
144
+ ```sh
145
+ greg build
146
+ ```
147
+
148
+ If `versioning` is configured, `greg build` automatically runs multi-version build.
149
+ This prevents accidental replacement of versioned output by a single build.
150
+
151
+ VitePress-compatible defaults in this flow:
152
+
153
+ - top-level `greg.config.* > outDir` controls where versions are emitted (`<outDir>/__versions`)
154
+ - top-level `greg.config.* > base` is used to derive default manifest URL prefix
155
+
156
+ Force single-version Vite build (even with versioning configured):
157
+
158
+ ```sh
159
+ greg build --single
160
+ ```
161
+
162
+ Output:
163
+
164
+ - built sites in `<outDir>/__versions/<version>` (default `dist/__versions/<version>`)
165
+ - manifest in `<outDir>/__versions/versions.json`
166
+ - default version copied to `dist/` for direct hosting
167
+
168
+ What exactly happens when Greg runs multi-version build (`greg build` with versioning):
169
+
170
+ 1. Greg loads `greg.config.js` or `greg.config.ts` and validates `versioning` schema.
171
+ 2. Greg selects strategy (`versioning.strategy`, default `branches`).
172
+ 3. Greg prepares working directories: output root (default `<outDir>/__versions`, where `outDir` defaults to `dist`), temporary work root (`.greg/version-build`), and branch cache root (`.greg/version-cache`).
173
+ 4. Greg builds each configured version according to strategy.
174
+ 5. Greg validates uniqueness of version IDs and validates aliases (`alias -> version`).
175
+ 6. Greg resolves default version (configured `default` or first built version).
176
+ 7. Greg writes `versions.json` manifest and reports output paths.
177
+ 8. Greg copies the default version build to hosting root (`dist/` by default).
178
+
179
+ What this command changes on disk:
180
+
181
+ - writes/updates files in `<outDir>/__versions`
182
+ - writes/updates files in `dist` (default version sync)
183
+ - writes/updates internal working data under `.greg/`
184
+ - does not modify your source docs files
185
+ - does not switch your checked out Git branch
186
+
187
+ Optional maintenance flags:
188
+
189
+ - `--clean-cache`: removes `.greg/version-cache` before building
190
+ - `--clean-versions`: removes the versioned output directory before building
191
+ - `--rebuild-all`: rebuilds every configured version and skips branch build cache reuse for this run
192
+
193
+ ## UI Components
194
+
195
+ Greg renders two visual versioning components automatically when a valid manifest is available:
196
+
197
+ - version switcher in the header
198
+ - outdated-version notice when the current version differs from the default
199
+
200
+ You can customize labels/messages with `versioning.ui`:
201
+
202
+ ```js [greg.config.js]
203
+ export default {
204
+ versioning: {
205
+ ui: {
206
+ versionMenuLabel: "Version",
207
+ manifestUnavailableText: "Version selector unavailable",
208
+ showManifestUnavailableStatus: false,
209
+ outdatedVersionMessage: "You are viewing an older version ({current}). Recommended: {default}.",
210
+ outdatedVersionActionLabel: "Go to latest"
211
+ }
212
+ }
213
+ };
214
+ ```
215
+
216
+ Supported placeholders in `outdatedVersionMessage`:
217
+
218
+ - `{current}`
219
+ - `{default}`
220
+
221
+ ### Locale-specific versioning UI
222
+
223
+ If your site uses locale routes, you can override versioning UI text per locale via `versioning.locales`:
224
+
225
+ ```js [greg.config.js]
226
+ export default {
227
+ versioning: {
228
+ locales: {
229
+ "/": {
230
+ ui: {
231
+ versionMenuLabel: "Version"
232
+ }
233
+ },
234
+ "/pl/": {
235
+ ui: {
236
+ versionMenuLabel: "Wersja",
237
+ outdatedVersionActionLabel: "Przejdz do najnowszej"
238
+ }
239
+ }
240
+ }
241
+ }
242
+ };
243
+ ```
244
+
245
+ Text resolution priority:
246
+
247
+ 1. `versioning.locales[active-locale].ui`
248
+ 2. `versioning.ui`
249
+ 3. built-in defaults
250
+
251
+ `showManifestUnavailableStatus` is global-only and must be configured in `versioning.ui`.
252
+
253
+ ## Fallback Behavior
254
+
255
+ If `versions.json` cannot be loaded:
256
+
257
+ - Greg hides the selector
258
+ - Greg shows `manifestUnavailableText` in the header only when `showManifestUnavailableStatus` is not `false`
259
+
260
+ This keeps docs usable even if a deployment serves only a single version.
261
+
262
+ ## Manifest Shape
263
+
264
+ ```json
265
+ {
266
+ "default": "latest",
267
+ "versions": [
268
+ { "version": "2.1", "title": "2.1", "path": "/__versions/2.1/" },
269
+ { "version": "2.0", "title": "2.0", "path": "/__versions/2.0/" }
270
+ ],
271
+ "aliases": {
272
+ "latest": "2.1",
273
+ "stable": "2.0"
274
+ }
275
+ }
276
+ ```
277
+
278
+ `aliases` is a map (`alias -> version`), so alias targets are always unambiguous.
279
+
280
+
281
+