specra 0.2.63 → 0.2.65
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/svelte-config.js +6 -0
- package/dist/components/docs/Card.svelte +6 -1
- package/dist/components/docs/MdxContent.svelte +17 -1
- package/dist/components/docs/SidebarMenuItems.svelte +4 -3
- package/dist/components/docs/TableOfContents.svelte +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inline.d.ts +1 -0
- package/dist/inline.js +32 -0
- package/package.json +1 -1
package/config/svelte-config.js
CHANGED
|
@@ -166,6 +166,12 @@ export function specraConfig(options = {}) {
|
|
|
166
166
|
kit: {
|
|
167
167
|
...options.kit,
|
|
168
168
|
paths: {
|
|
169
|
+
// Absolute (base-prefixed) links rather than relative ones. Under a
|
|
170
|
+
// subpath deployment, relative links (the SvelteKit default) interact
|
|
171
|
+
// badly with the prerender crawler and produce wrong targets; absolute
|
|
172
|
+
// `${base}/...` links resolve and crawl correctly. Override via
|
|
173
|
+
// options.kit.paths.relative if a site truly needs relative output.
|
|
174
|
+
relative: false,
|
|
169
175
|
...options.kit?.paths,
|
|
170
176
|
base: basePath,
|
|
171
177
|
},
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { ArrowRight, ExternalLink } from 'lucide-svelte';
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import Icon from './Icon.svelte';
|
|
5
|
+
import { link } from '../../links.js';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
8
|
title: string;
|
|
@@ -13,6 +14,10 @@
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
let { title, description, href, icon, external = false, children }: Props = $props();
|
|
17
|
+
|
|
18
|
+
// Apply the deployment base path to internal absolute hrefs (e.g. /docs/...),
|
|
19
|
+
// since rehype only rewrites plain markdown links, not component props.
|
|
20
|
+
const resolvedHref = $derived(href && href.startsWith('/') ? link(href) : href);
|
|
16
21
|
</script>
|
|
17
22
|
|
|
18
23
|
{#snippet cardContent(isLink: boolean)}
|
|
@@ -49,7 +54,7 @@
|
|
|
49
54
|
|
|
50
55
|
{#if href}
|
|
51
56
|
<a
|
|
52
|
-
{
|
|
57
|
+
href={resolvedHref}
|
|
53
58
|
class="card-link group block h-full p-4 rounded-xl border border-border hover:border-primary/50 hover:bg-muted/50 transition-all"
|
|
54
59
|
target={external ? '_blank' : undefined}
|
|
55
60
|
rel={external ? 'noopener noreferrer' : undefined}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import MdxContent from './MdxContent.svelte';
|
|
3
3
|
import type { Component } from 'svelte';
|
|
4
4
|
import type { MdxNode } from '../../mdx.js';
|
|
5
|
+
import { base } from '$app/paths';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
8
|
nodes: MdxNode[];
|
|
@@ -9,11 +10,26 @@
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
let { nodes, components }: Props = $props();
|
|
13
|
+
|
|
14
|
+
// Prefix absolute href/src in raw content HTML with the deployment base path.
|
|
15
|
+
// The content nodes are pre-rendered HTML emitted via {@html}, which bypasses
|
|
16
|
+
// rehypeBasePath, so links like /docs/... would otherwise be base-less under a
|
|
17
|
+
// subpath deployment. Skips protocol-relative (//) and already-based URLs.
|
|
18
|
+
function withBase(html: string): string {
|
|
19
|
+
if (!base || !html) return html;
|
|
20
|
+
return html.replace(
|
|
21
|
+
/(href|src)="(\/[^"]*)"/g,
|
|
22
|
+
(m, attr, p) =>
|
|
23
|
+
p.startsWith('//') || p === base || p.startsWith(base + '/')
|
|
24
|
+
? m
|
|
25
|
+
: `${attr}="${base}${p}"`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
12
28
|
</script>
|
|
13
29
|
|
|
14
30
|
{#each nodes as node}
|
|
15
31
|
{#if node.type === 'html'}
|
|
16
|
-
{@html node.content}
|
|
32
|
+
{@html withBase(node.content)}
|
|
17
33
|
{:else if node.type === 'component' && node.name}
|
|
18
34
|
{@const Comp = components[node.name]}
|
|
19
35
|
{#if Comp}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { SpecraConfig } from '../../config.types.js';
|
|
6
6
|
import Icon from './Icon.svelte';
|
|
7
7
|
import { sortSidebarItems, sortSidebarGroups } from '../../sidebar-utils.js';
|
|
8
|
+
import { renderInlineCode } from '../../inline.js';
|
|
8
9
|
|
|
9
10
|
interface DocItem {
|
|
10
11
|
title: string;
|
|
@@ -302,7 +303,7 @@
|
|
|
302
303
|
{#if group.icon}
|
|
303
304
|
<Icon icon={group.icon} size={16} className="shrink-0" />
|
|
304
305
|
{/if}
|
|
305
|
-
{group.label}
|
|
306
|
+
{@html renderInlineCode(group.label)}
|
|
306
307
|
</a>
|
|
307
308
|
|
|
308
309
|
{#if hasContent && group.collapsible && config.navigation?.collapsibleSidebar}
|
|
@@ -342,7 +343,7 @@
|
|
|
342
343
|
{#if item.doc.meta?.icon}
|
|
343
344
|
<Icon icon={item.doc.meta.icon} size={16} className="shrink-0" />
|
|
344
345
|
{/if}
|
|
345
|
-
{item.doc.title}
|
|
346
|
+
{@html renderInlineCode(item.doc.title)}
|
|
346
347
|
{#if item.doc.meta?.isProtected}
|
|
347
348
|
<Lock size={14} class="shrink-0 text-muted-foreground ml-auto" />
|
|
348
349
|
{/if}
|
|
@@ -369,7 +370,7 @@
|
|
|
369
370
|
{#if doc.meta?.icon}
|
|
370
371
|
<Icon icon={doc.meta.icon} size={16} className="shrink-0" />
|
|
371
372
|
{/if}
|
|
372
|
-
{doc.title}
|
|
373
|
+
{@html renderInlineCode(doc.title)}
|
|
373
374
|
{#if doc.meta?.isProtected}
|
|
374
375
|
<Lock size={14} class="shrink-0 text-muted-foreground ml-auto" />
|
|
375
376
|
{/if}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { browser } from '$app/environment';
|
|
3
3
|
import type { SpecraConfig } from '../../config.types.js';
|
|
4
4
|
import type { TOCItem } from '../../toc.js';
|
|
5
|
+
import { renderInlineCode } from '../../inline.js';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
8
|
items: TOCItem[];
|
|
@@ -84,7 +85,7 @@
|
|
|
84
85
|
? 'text-primary font-medium'
|
|
85
86
|
: 'text-foreground hover:bg-accent/50'}"
|
|
86
87
|
>
|
|
87
|
-
{item.title}
|
|
88
|
+
{@html renderInlineCode(item.title)}
|
|
88
89
|
</a>
|
|
89
90
|
{/each}
|
|
90
91
|
</nav>
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type * from './api.types.js';
|
|
|
12
12
|
export type { ApiParam, ApiHeader, ApiResponse as SpecraApiResponse, ApiEndpointSpec, SpecraApiSpec } from './api-parser.types.js';
|
|
13
13
|
export * from './utils.js';
|
|
14
14
|
export * from './links.js';
|
|
15
|
+
export * from './inline.js';
|
|
15
16
|
export * from './sidebar-utils.js';
|
|
16
17
|
export * from './category.js';
|
|
17
18
|
export * from './redirects.js';
|
package/dist/index.js
CHANGED
package/dist/inline.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderInlineCode(text: string): string;
|
package/dist/inline.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render a plain label string that may contain inline-code markdown
|
|
3
|
+
* (backtick-delimited spans) into safe HTML, turning `` `code` `` into
|
|
4
|
+
* `<code>code</code>`. Used for TOC entries and sidebar labels, which come from
|
|
5
|
+
* headings / frontmatter titles as raw text - without this they show the literal
|
|
6
|
+
* backticks instead of formatted code.
|
|
7
|
+
*
|
|
8
|
+
* Everything is HTML-escaped (both the surrounding text and the code content),
|
|
9
|
+
* so the result is safe to use with `{@html}`. Only inline code is handled; no
|
|
10
|
+
* other markdown is interpreted.
|
|
11
|
+
*/
|
|
12
|
+
function escapeHtml(s) {
|
|
13
|
+
return s
|
|
14
|
+
.replace(/&/g, '&')
|
|
15
|
+
.replace(/</g, '<')
|
|
16
|
+
.replace(/>/g, '>');
|
|
17
|
+
}
|
|
18
|
+
export function renderInlineCode(text) {
|
|
19
|
+
if (!text)
|
|
20
|
+
return '';
|
|
21
|
+
let out = '';
|
|
22
|
+
let last = 0;
|
|
23
|
+
const re = /`([^`]+)`/g;
|
|
24
|
+
let m;
|
|
25
|
+
while ((m = re.exec(text)) !== null) {
|
|
26
|
+
out += escapeHtml(text.slice(last, m.index));
|
|
27
|
+
out += `<code>${escapeHtml(m[1])}</code>`;
|
|
28
|
+
last = m.index + m[0].length;
|
|
29
|
+
}
|
|
30
|
+
out += escapeHtml(text.slice(last));
|
|
31
|
+
return out;
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "specra",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.65",
|
|
4
4
|
"description": "A modern documentation library for SvelteKit with built-in versioning, API reference generation, full-text search, and MDX support",
|
|
5
5
|
"svelte": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|