reallysimpledocs 1.0.0-beta.4 → 1.0.0-beta.5
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/README.md +35 -35
- package/package.json +10 -13
- package/src/astro/index.js +46 -98
- package/src/astro/preview-source.js +90 -0
- package/src/components/index.js +1 -0
- package/src/css/custom.css +252 -33
- package/src/css/styles/luma.css +11 -0
- package/src/css/styles/lyra.css +11 -0
- package/src/css/styles/maia.css +11 -0
- package/src/css/styles/mira.css +11 -0
- package/src/css/styles/nova.css +11 -0
- package/src/css/styles/rhea.css +11 -0
- package/src/css/styles/sera.css +11 -0
- package/src/css/styles/vega.css +11 -0
- package/src/runtime/components/BaseLayout.astro +20 -27
- package/src/runtime/components/CommandDialog.astro +30 -32
- package/src/runtime/components/DefaultContentHeader.astro +0 -17
- package/src/runtime/components/DefaultHead.astro +120 -0
- package/src/runtime/components/DefaultHeadContent.astro +2 -0
- package/src/runtime/components/DefaultSidebarHeader.astro +1 -1
- package/src/runtime/components/DocsLayout.astro +114 -165
- package/src/runtime/components/DropdownMenu.astro +1 -1
- package/src/runtime/components/ThemeToggle.astro +21 -0
- package/src/runtime/components/mdx/Callout.astro +2 -32
- package/src/runtime/components/mdx/Card.astro +3 -8
- package/src/runtime/components/mdx/CardGrid.astro +1 -1
- package/src/runtime/components/mdx/Code.astro +2 -16
- package/src/runtime/components/mdx/CodeGroup.astro +7 -11
- package/src/runtime/components/mdx/Preview.astro +7 -13
- package/src/runtime/components/mdx/Steps.astro +1 -5
- package/src/runtime/components/mdx/Tab.astro +6 -0
- package/src/runtime/components/mdx/Tabs.astro +7 -7
- package/src/runtime/lib/docs.js +130 -102
- package/src/runtime/lib/highlight.js +1 -14
- package/src/runtime/lib/macros.js +10 -5
- package/src/runtime/lib/markdown-export.js +134 -171
- package/src/runtime/pages/doc.astro +1 -3
- package/src/runtime/pages/llms-full.txt.ts +2 -2
- package/src/runtime/pages/llms.txt.ts +2 -2
- package/src/runtime/pages/markdown.ts +2 -2
- package/src/runtime/pages/search-index.ts +12 -3
- package/CHANGELOG.md +0 -35
- package/src/css/overrides.css +0 -1
- package/src/css/sources.css +0 -1
- package/src/runtime/lib/markdown-exporters/index.js +0 -144
- package/src/runtime/lib/mdx-source.js +0 -19
- package/src/runtime/lib/preview-source-plugin.js +0 -33
- package/src/runtime/scripts/copy-code.js +0 -130
- package/src/site/ContentHeader.astro +0 -33
package/src/css/custom.css
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
@source "../runtime/**/*.{astro,js,ts}";
|
|
2
|
+
|
|
1
3
|
@theme {
|
|
2
4
|
--color-search-highlight: oklch(90.5% 0.182 98.111);
|
|
3
5
|
}
|
|
@@ -23,28 +25,24 @@
|
|
|
23
25
|
> h1:first-child {
|
|
24
26
|
@apply hidden;
|
|
25
27
|
}
|
|
26
|
-
> p
|
|
27
|
-
>
|
|
28
|
-
> :is(ol, ul) a,
|
|
28
|
+
> p a,
|
|
29
|
+
> li a,
|
|
29
30
|
> dl a,
|
|
30
|
-
> table a
|
|
31
|
+
> table td a,
|
|
32
|
+
> table th a {
|
|
31
33
|
@apply underline underline-offset-2 decoration-muted-foreground/50 hover:decoration-foreground/50 transition-all;
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
> blockquote code:not(pre > code),
|
|
35
|
-
> :is(ol, ul) code:not(pre > code),
|
|
36
|
-
> dl code:not(pre > code),
|
|
37
|
-
> table code:not(pre > code) {
|
|
35
|
+
code:not(pre > code) {
|
|
38
36
|
@apply relative rounded-md bg-muted px-[0.3rem] py-[0.2rem] font-mono text-[13px];
|
|
39
37
|
}
|
|
40
|
-
|
|
38
|
+
pre {
|
|
41
39
|
@apply rounded-lg;
|
|
42
40
|
}
|
|
43
|
-
|
|
41
|
+
pre > code {
|
|
44
42
|
@apply block min-w-full w-max px-4 py-3 text-[13px];
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
@apply max-w-full overflow-x-auto;
|
|
44
|
+
pre:has(> code) {
|
|
45
|
+
@apply scrollbar max-w-full overflow-x-auto;
|
|
48
46
|
}
|
|
49
47
|
> blockquote {
|
|
50
48
|
@apply border-l-4 border-border pl-4;
|
|
@@ -78,16 +76,8 @@
|
|
|
78
76
|
@apply mt-4 border-b-0 pb-0 pl-8 my-0;
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
> blockquote b,
|
|
84
|
-
> blockquote strong,
|
|
85
|
-
> :is(ol, ul) b,
|
|
86
|
-
> :is(ol, ul) strong,
|
|
87
|
-
> dl b,
|
|
88
|
-
> dl strong,
|
|
89
|
-
> table b,
|
|
90
|
-
> table strong {
|
|
79
|
+
b,
|
|
80
|
+
strong {
|
|
91
81
|
@apply font-semibold;
|
|
92
82
|
}
|
|
93
83
|
> p,
|
|
@@ -133,7 +123,11 @@
|
|
|
133
123
|
.shiki,
|
|
134
124
|
.astro-code {
|
|
135
125
|
@apply bg-muted/50;
|
|
136
|
-
background-color: color-mix(
|
|
126
|
+
background-color: color-mix(
|
|
127
|
+
in oklab,
|
|
128
|
+
var(--color-muted) 50%,
|
|
129
|
+
transparent
|
|
130
|
+
) !important;
|
|
137
131
|
color: var(--shiki-light);
|
|
138
132
|
}
|
|
139
133
|
|
|
@@ -152,22 +146,247 @@ html.dark .astro-code span {
|
|
|
152
146
|
color: var(--shiki-dark);
|
|
153
147
|
}
|
|
154
148
|
|
|
155
|
-
|
|
156
|
-
@apply
|
|
149
|
+
[data-search] .command a[role="menuitem"] {
|
|
150
|
+
@apply h-auto min-h-0 flex-col items-start gap-1 overflow-visible whitespace-normal py-2;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
[data-search] .command a[role="menuitem"] > strong {
|
|
154
|
+
@apply w-full font-medium leading-5;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
[data-search] .command a[role="menuitem"] > span {
|
|
158
|
+
@apply text-muted-foreground line-clamp-2 w-full text-sm font-normal leading-5;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.command mark {
|
|
162
|
+
@apply bg-search-highlight/50 text-foreground dark:bg-search-highlight/25;
|
|
157
163
|
}
|
|
158
164
|
|
|
159
|
-
|
|
160
|
-
@apply
|
|
165
|
+
.docs-card {
|
|
166
|
+
@apply block w-full rounded-lg border bg-card p-3 text-card-foreground no-underline;
|
|
161
167
|
}
|
|
162
168
|
|
|
163
|
-
|
|
169
|
+
.docs-card > h3 {
|
|
164
170
|
@apply font-medium;
|
|
165
171
|
}
|
|
166
172
|
|
|
167
|
-
|
|
168
|
-
@apply
|
|
173
|
+
.docs-card > p {
|
|
174
|
+
@apply mt-1 text-sm text-muted-foreground;
|
|
169
175
|
}
|
|
170
176
|
|
|
171
|
-
.
|
|
172
|
-
@apply bg-
|
|
177
|
+
.docs-card-link {
|
|
178
|
+
@apply transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.alert[data-variant="warning"] > svg,
|
|
182
|
+
.alert[data-variant="warning"] > h3,
|
|
183
|
+
.alert[data-variant="warning"] > section {
|
|
184
|
+
@apply text-amber-700 dark:text-amber-300;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.code-block {
|
|
188
|
+
@apply relative my-6 w-full max-w-full overflow-hidden rounded-lg;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.code-block > header,
|
|
192
|
+
.code-group > header,
|
|
193
|
+
.preview > header {
|
|
194
|
+
@apply flex h-10 items-center gap-2 border-b border-border bg-muted/50 px-3 text-sm font-medium;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.code-block > header > :first-child,
|
|
198
|
+
.code-group > header > :first-child,
|
|
199
|
+
.preview > header > :first-child {
|
|
200
|
+
@apply mr-auto;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.code-block > pre {
|
|
204
|
+
@apply scrollbar my-0 max-w-full overflow-x-auto rounded-none border-0;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.code-block > pre > code {
|
|
208
|
+
@apply block min-w-full w-max px-4 py-3 text-[13px];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.code-block > .shiki {
|
|
212
|
+
@apply my-0 rounded-none border-0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.code-block > button {
|
|
216
|
+
@apply absolute right-2.5 top-2.5 z-10;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.code-block button,
|
|
220
|
+
.code-group button[aria-label="Copy code"],
|
|
221
|
+
.preview button[aria-label="Copy code"] {
|
|
222
|
+
@apply flex size-6 shrink-0 items-center justify-center rounded-md text-muted-foreground outline-none hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.code-block > button {
|
|
226
|
+
@apply bg-background/80 shadow-xs backdrop-blur-sm hover:bg-accent/80 dark:bg-background/60 dark:hover:bg-accent/70;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.code-block > header > button,
|
|
230
|
+
.code-group > header > button,
|
|
231
|
+
.preview > header > button {
|
|
232
|
+
@apply ml-auto;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.code-group {
|
|
236
|
+
@apply relative my-6 w-full max-w-full overflow-hidden rounded-lg;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
.code-group > header > .tabs {
|
|
240
|
+
@apply my-0 min-w-0 max-w-full gap-0;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.code-group > header > .tabs > nav {
|
|
244
|
+
@apply h-full justify-start rounded-none bg-transparent p-0;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.code-group > [role="tabpanel"] {
|
|
248
|
+
@apply border-t-0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.code-group .code-block {
|
|
252
|
+
@apply my-0 min-w-0 rounded-none;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.code-group .code-block > header {
|
|
256
|
+
@apply hidden;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.preview {
|
|
260
|
+
@apply relative my-6 max-w-full overflow-visible rounded-lg;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.preview::before {
|
|
264
|
+
@apply pointer-events-none absolute inset-0 z-10 border border-border;
|
|
265
|
+
border-radius: inherit;
|
|
266
|
+
content: "";
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.preview > header > .tabs {
|
|
270
|
+
@apply my-0 min-w-0 max-w-full gap-0;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.preview > header {
|
|
274
|
+
@apply relative z-0 rounded-t-[inherit];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.preview > header > .tabs > nav {
|
|
278
|
+
@apply h-full justify-start rounded-none bg-transparent p-0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.preview > [role="tabpanel"] {
|
|
282
|
+
@apply border-t-0;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.preview > [data-code-panel] {
|
|
286
|
+
@apply overflow-hidden rounded-b-[inherit];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.preview > [data-code-panel] .code-block {
|
|
290
|
+
@apply my-0 min-w-0 rounded-none;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.preview > header > button[aria-label="Copy code"] {
|
|
294
|
+
display: none;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.preview:has(> [data-code-panel]:not([hidden]))
|
|
298
|
+
> header
|
|
299
|
+
> button[aria-label="Copy code"] {
|
|
300
|
+
display: flex;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.preview > [data-preview-panel] {
|
|
304
|
+
@apply flex min-h-64 items-center justify-center p-6;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.preview > [data-preview-panel] :where(ul, ol) {
|
|
308
|
+
@apply m-0;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
.preview > [data-preview-panel] :where(li) {
|
|
312
|
+
@apply mt-0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
.steps {
|
|
316
|
+
@apply mb-12 mt-6 md:ml-4 md:border-l md:pl-8;
|
|
317
|
+
counter-reset: step;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.steps > section {
|
|
321
|
+
counter-increment: step;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.steps > section + section {
|
|
325
|
+
@apply mt-6;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.steps > section > h3 {
|
|
329
|
+
@apply relative mt-12 scroll-m-28 text-lg font-medium tracking-tight;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.steps > section + section > h3 {
|
|
333
|
+
@apply mt-0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.steps > section:first-child > h3 {
|
|
337
|
+
@apply mt-0;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.steps > section > h3::before {
|
|
341
|
+
@apply mr-4 inline-flex size-7 items-center justify-center rounded-full bg-muted text-sm font-medium text-muted-foreground;
|
|
342
|
+
content: counter(step);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
@media (width >= 48rem) {
|
|
346
|
+
.steps > section > h3::before {
|
|
347
|
+
position: absolute;
|
|
348
|
+
left: 0;
|
|
349
|
+
top: 0;
|
|
350
|
+
margin-right: 0;
|
|
351
|
+
transform: translateX(-2.875rem);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
.steps > section > * + * {
|
|
356
|
+
@apply mt-6;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.steps > section > h3 + * {
|
|
360
|
+
@apply mt-4;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.steps > section > * {
|
|
364
|
+
@apply leading-relaxed;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
.steps > section > *:first-child {
|
|
368
|
+
@apply mt-0;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
.steps > section > *:last-child {
|
|
372
|
+
@apply mb-0;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
.prose > .alert,
|
|
376
|
+
.prose > .docs-card,
|
|
377
|
+
.prose > .grid,
|
|
378
|
+
.prose > .tabs {
|
|
379
|
+
@apply my-6;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
.command [role="menu"][data-loading]::before {
|
|
383
|
+
content: none;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.command [role="menu"] > [data-rsd-command-loading] {
|
|
387
|
+
@apply flex min-h-16 items-center justify-center gap-2 py-6 text-center text-sm text-muted-foreground;
|
|
388
|
+
|
|
389
|
+
svg {
|
|
390
|
+
@apply size-4 animate-spin;
|
|
391
|
+
}
|
|
173
392
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
import "virtual:reallysimpledocs/styles.css";
|
|
3
2
|
import config from "virtual:reallysimpledocs/config";
|
|
3
|
+
import Head from "virtual:reallysimpledocs/components/Head";
|
|
4
|
+
import DefaultHead from "./DefaultHead.astro";
|
|
4
5
|
import { getSite } from "../lib/site.js";
|
|
5
6
|
|
|
6
7
|
const { title, description, pagePath = "/" } = Astro.props;
|
|
@@ -27,28 +28,24 @@ const absoluteAssetUrl = (value) => {
|
|
|
27
28
|
<!doctype html>
|
|
28
29
|
<html lang="en">
|
|
29
30
|
<head>
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
apply(mode === "dark" ? true : mode === "light" ? false : !document.documentElement.classList.contains("dark"));
|
|
49
|
-
});
|
|
50
|
-
})();
|
|
51
|
-
</script>
|
|
31
|
+
<DefaultHead
|
|
32
|
+
config={config}
|
|
33
|
+
site={site}
|
|
34
|
+
title={title}
|
|
35
|
+
description={metaDescription}
|
|
36
|
+
pagePath={pagePath}
|
|
37
|
+
metaTitle={metaTitle}
|
|
38
|
+
absoluteUrl={absoluteUrl}
|
|
39
|
+
/>
|
|
40
|
+
<Head
|
|
41
|
+
config={config}
|
|
42
|
+
site={site}
|
|
43
|
+
title={title}
|
|
44
|
+
description={metaDescription}
|
|
45
|
+
pagePath={pagePath}
|
|
46
|
+
metaTitle={metaTitle}
|
|
47
|
+
absoluteUrl={absoluteUrl}
|
|
48
|
+
/>
|
|
52
49
|
<meta charset="utf-8" />
|
|
53
50
|
<meta http-equiv="Content-Language" content="en" />
|
|
54
51
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
@@ -72,10 +69,6 @@ const absoluteAssetUrl = (value) => {
|
|
|
72
69
|
<meta name="twitter:description" content={metaDescription} />
|
|
73
70
|
{socialImage && <meta name="twitter:image" content={absoluteAssetUrl(socialImage)} />}
|
|
74
71
|
{site.author?.x && <meta name="twitter:creator" content={site.author.x} />}
|
|
75
|
-
<script>
|
|
76
|
-
import "basecoat-css/all.min";
|
|
77
|
-
import "../scripts/copy-code.js";
|
|
78
|
-
</script>
|
|
79
72
|
</head>
|
|
80
73
|
<body>
|
|
81
74
|
<slot />
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
---
|
|
2
|
+
import config from "virtual:reallysimpledocs/config";
|
|
2
3
|
import { renderCommandDialog } from "../lib/macros.js";
|
|
4
|
+
import { routeFilePath } from "../lib/paths.js";
|
|
5
|
+
import LoaderCircle from "lucide-static/icons/loader-circle.svg?raw";
|
|
6
|
+
import lunrUrl from "lunr/lunr.min.js?url";
|
|
3
7
|
|
|
4
|
-
const { indexUrl } = Astro.props;
|
|
8
|
+
const { indexUrl = routeFilePath(config.routeBase, "search-index.json") } = Astro.props;
|
|
5
9
|
---
|
|
6
10
|
|
|
7
11
|
<div data-search data-index-url={indexUrl}>
|
|
@@ -15,9 +19,8 @@ const { indexUrl } = Astro.props;
|
|
|
15
19
|
/>
|
|
16
20
|
</div>
|
|
17
21
|
|
|
18
|
-
<script>
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
<script src={lunrUrl}></script>
|
|
23
|
+
<script is:inline define:vars={{ loadingIcon: LoaderCircle }}>
|
|
21
24
|
const root = document.querySelector("[data-search]");
|
|
22
25
|
const indexUrl = root?.getAttribute("data-index-url");
|
|
23
26
|
const dialog = document.getElementById("command-search");
|
|
@@ -26,7 +29,6 @@ const { indexUrl } = Astro.props;
|
|
|
26
29
|
const menu = dialog?.querySelector('[role="menu"]');
|
|
27
30
|
const state = {
|
|
28
31
|
loadPromise: null,
|
|
29
|
-
lunrPromise: null,
|
|
30
32
|
index: null,
|
|
31
33
|
documents: [],
|
|
32
34
|
bySlug: new Map(),
|
|
@@ -131,8 +133,8 @@ const { indexUrl } = Astro.props;
|
|
|
131
133
|
return space > -1 ? space : end;
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
function
|
|
135
|
-
const text = String(
|
|
136
|
+
function snippetFromText(value, ranges) {
|
|
137
|
+
const text = String(value || "");
|
|
136
138
|
if (!text || !ranges.length) return "";
|
|
137
139
|
|
|
138
140
|
const first = ranges[0];
|
|
@@ -149,25 +151,36 @@ const { indexUrl } = Astro.props;
|
|
|
149
151
|
|
|
150
152
|
function resultView(result, query) {
|
|
151
153
|
const doc = result.doc || result;
|
|
154
|
+
const displayTitle = doc.breadcrumb || doc.title;
|
|
152
155
|
if (!query.trim()) {
|
|
153
156
|
return {
|
|
154
157
|
path: doc.path,
|
|
155
|
-
title: escapeHtml(
|
|
158
|
+
title: escapeHtml(displayTitle),
|
|
156
159
|
snippet: "",
|
|
157
160
|
};
|
|
158
161
|
}
|
|
159
162
|
|
|
160
|
-
|
|
163
|
+
let titleRanges = rangesFromMatch(result.match, "breadcrumb");
|
|
164
|
+
if (!titleRanges.length) {
|
|
165
|
+
const titleOffset = String(displayTitle).lastIndexOf(doc.title);
|
|
166
|
+
titleRanges = rangesFromMatch(result.match, "title").map(([start, end]) => [
|
|
167
|
+
titleOffset > -1 ? titleOffset + start : start,
|
|
168
|
+
titleOffset > -1 ? titleOffset + end : end,
|
|
169
|
+
]);
|
|
170
|
+
}
|
|
171
|
+
titleRanges = refineRanges(displayTitle, titleRanges, query);
|
|
161
172
|
const bodyRanges = refineRanges(doc.body, rangesFromMatch(result.match, "body"), query);
|
|
173
|
+
const codeRanges = refineRanges(doc.code, rangesFromMatch(result.match, "code"), query);
|
|
162
174
|
return {
|
|
163
175
|
path: doc.path,
|
|
164
|
-
title: highlightRanges(
|
|
165
|
-
snippet:
|
|
176
|
+
title: highlightRanges(displayTitle, titleRanges),
|
|
177
|
+
snippet: snippetFromText(doc.body, bodyRanges) || snippetFromText(doc.code, codeRanges),
|
|
166
178
|
};
|
|
167
179
|
}
|
|
168
180
|
|
|
169
181
|
function renderItems(items, label, query = "") {
|
|
170
182
|
if (!menu) return;
|
|
183
|
+
delete menu.dataset.loading;
|
|
171
184
|
if (!items.length) {
|
|
172
185
|
menu.innerHTML = "";
|
|
173
186
|
refreshCommand();
|
|
@@ -191,37 +204,22 @@ const { indexUrl } = Astro.props;
|
|
|
191
204
|
|
|
192
205
|
function renderLoading() {
|
|
193
206
|
if (!menu) return;
|
|
194
|
-
menu.
|
|
195
|
-
|
|
196
|
-
<
|
|
207
|
+
menu.dataset.loading = "true";
|
|
208
|
+
menu.innerHTML = `<div role="status" aria-live="polite" data-rsd-command-loading>
|
|
209
|
+
<span aria-hidden="true">${loadingIcon}</span>
|
|
210
|
+
<span>Loading...</span>
|
|
197
211
|
</div>`;
|
|
198
212
|
refreshCommand();
|
|
199
213
|
}
|
|
200
214
|
|
|
201
|
-
function loadLunr() {
|
|
202
|
-
if (window.lunr) return Promise.resolve(window.lunr);
|
|
203
|
-
if (!state.lunrPromise) {
|
|
204
|
-
state.lunrPromise = new Promise((resolve, reject) => {
|
|
205
|
-
const script = document.createElement("script");
|
|
206
|
-
script.src = lunrUrl;
|
|
207
|
-
script.async = true;
|
|
208
|
-
script.onload = () => (window.lunr ? resolve(window.lunr) : reject(new Error("Failed to load lunr.")));
|
|
209
|
-
script.onerror = () => reject(new Error("Failed to load lunr."));
|
|
210
|
-
document.head.appendChild(script);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
return state.lunrPromise;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
215
|
async function loadIndex() {
|
|
217
216
|
if (state.index) return state;
|
|
218
|
-
if (!indexUrl) throw new Error("Missing
|
|
217
|
+
if (!indexUrl) throw new Error("Missing ReallySimpleDocs search index URL.");
|
|
219
218
|
if (!state.loadPromise) {
|
|
220
219
|
renderLoading();
|
|
221
220
|
state.loadPromise = fetch(indexUrl)
|
|
222
221
|
.then((response) => response.json())
|
|
223
|
-
.then(
|
|
224
|
-
const lunr = await loadLunr();
|
|
222
|
+
.then((data) => {
|
|
225
223
|
state.documents = data.documents || [];
|
|
226
224
|
state.bySlug = new Map(state.documents.map((doc) => [doc.slug, doc]));
|
|
227
225
|
state.index = lunr.Index.load(data.index);
|
|
@@ -1,19 +1,2 @@
|
|
|
1
1
|
---
|
|
2
|
-
import Moon from "lucide-static/icons/moon.svg?raw";
|
|
3
|
-
import Sun from "lucide-static/icons/sun.svg?raw";
|
|
4
2
|
---
|
|
5
|
-
|
|
6
|
-
<nav class="hidden items-center gap-2 sm:flex">
|
|
7
|
-
<button
|
|
8
|
-
type="button"
|
|
9
|
-
aria-label="Toggle dark mode"
|
|
10
|
-
data-tooltip="Toggle dark mode"
|
|
11
|
-
data-side="bottom"
|
|
12
|
-
data-align="end"
|
|
13
|
-
onclick="document.dispatchEvent(new CustomEvent('basecoat:theme'))"
|
|
14
|
-
class="btn-sm-icon-ghost"
|
|
15
|
-
>
|
|
16
|
-
<span class="hidden dark:block"><Fragment set:html={Sun} /></span>
|
|
17
|
-
<span class="block dark:hidden"><Fragment set:html={Moon} /></span>
|
|
18
|
-
</button>
|
|
19
|
-
</nav>
|