@oneie/plugin-docs 0.1.0 → 0.1.2
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/package.json +2 -7
- package/src/DocsIndex.astro +7 -12
- package/src/DocsLayout.astro +32 -16
- package/src/index.ts +36 -8
- package/tsconfig.json +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/plugin-docs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "ONE docs — Astro content collection with sidebar nav, search, code blocks, and versioning",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -15,17 +15,12 @@
|
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"astro": ">=6.0.0",
|
|
18
|
-
"@oneie/frontend": "
|
|
18
|
+
"@oneie/frontend": "^0.1.1",
|
|
19
19
|
"react": ">=19.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"astro": "^6.2.2",
|
|
23
23
|
"react": "^19.0.0",
|
|
24
24
|
"typescript": "^5.7.3"
|
|
25
|
-
},
|
|
26
|
-
"peerDependenciesMeta": {
|
|
27
|
-
"@oneie/frontend": {
|
|
28
|
-
"optional": true
|
|
29
|
-
}
|
|
30
25
|
}
|
|
31
26
|
}
|
package/src/DocsIndex.astro
CHANGED
|
@@ -38,16 +38,12 @@ function folderLabel(key: string): string {
|
|
|
38
38
|
}
|
|
39
39
|
---
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
<head
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{description && <meta name="description" content={description} />}
|
|
48
|
-
<slot name="head" />
|
|
49
|
-
</head>
|
|
50
|
-
<body class="bg-background text-foreground antialiased">
|
|
41
|
+
<!--
|
|
42
|
+
A fragment, not a full document — this composes into the consuming site's
|
|
43
|
+
own <Layout> (nav, <head>, CSS). It has no opinion on chrome, only content.
|
|
44
|
+
Wrap it yourself: <Layout title={title}><DocsIndex title={title} /></Layout>
|
|
45
|
+
-->
|
|
46
|
+
<div class="bg-background text-foreground antialiased">
|
|
51
47
|
<slot name="header" />
|
|
52
48
|
|
|
53
49
|
<!-- Hero -->
|
|
@@ -115,5 +111,4 @@ function folderLabel(key: string): string {
|
|
|
115
111
|
</main>
|
|
116
112
|
|
|
117
113
|
<slot name="footer" />
|
|
118
|
-
|
|
119
|
-
</html>
|
|
114
|
+
</div>
|
package/src/DocsLayout.astro
CHANGED
|
@@ -1,17 +1,38 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type { CollectionEntry, MarkdownHeading } from 'astro:content'
|
|
3
|
+
import { getCollection, render } from 'astro:content'
|
|
3
4
|
import { SidebarDocs } from './SidebarDocs.tsx'
|
|
4
5
|
import { DocSearch } from './DocSearch.tsx'
|
|
5
6
|
|
|
6
7
|
export interface Props {
|
|
7
|
-
entry
|
|
8
|
-
|
|
8
|
+
/** Omit both `entry` and `entries` when this file is used directly as an
|
|
9
|
+
* injected route — it then self-resolves from Astro.params.slug and
|
|
10
|
+
* renders its own <Content/> in place of the default slot. Pass them
|
|
11
|
+
* explicitly when wrapping this layout in your own page. */
|
|
12
|
+
entry?: CollectionEntry<'docs'>
|
|
13
|
+
entries?: CollectionEntry<'docs'>[]
|
|
9
14
|
headings?: MarkdownHeading[]
|
|
10
15
|
editBaseUrl?: string
|
|
11
16
|
sidebar?: Array<{ folder: string; label: string; icon?: string }>
|
|
12
17
|
}
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
let { entry, entries, headings, editBaseUrl, sidebar } = Astro.props
|
|
20
|
+
let Content: (() => any) | undefined
|
|
21
|
+
|
|
22
|
+
if (!entry) {
|
|
23
|
+
const slug = Astro.params.slug as string
|
|
24
|
+
const all = await getCollection('docs')
|
|
25
|
+
const found = all.find((d) => d.id === slug)
|
|
26
|
+
if (!found) return Astro.redirect('/docs')
|
|
27
|
+
entry = found
|
|
28
|
+
entries = all
|
|
29
|
+
const rendered = await render(entry)
|
|
30
|
+
Content = rendered.Content
|
|
31
|
+
headings ??= rendered.headings
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
entries ??= []
|
|
35
|
+
headings ??= []
|
|
15
36
|
|
|
16
37
|
const searchQuery = Astro.url.searchParams.get('search') ?? ''
|
|
17
38
|
|
|
@@ -27,16 +48,12 @@ const editUrl = editBaseUrl ? `${editBaseUrl.replace(/\/$/, '')}/${entry.id}` :
|
|
|
27
48
|
const tocHeadings = headings.filter((h) => h.depth === 2 || h.depth === 3)
|
|
28
49
|
---
|
|
29
50
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<head
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{entry.data.description && <meta name="description" content={entry.data.description} />}
|
|
37
|
-
<slot name="head" />
|
|
38
|
-
</head>
|
|
39
|
-
<body class="h-full bg-background text-foreground antialiased">
|
|
51
|
+
<!--
|
|
52
|
+
A fragment, not a full document — this composes into the consuming site's
|
|
53
|
+
own <Layout> (nav, <head>, CSS). It has no opinion on chrome, only content.
|
|
54
|
+
Wrap it yourself: <Layout title={entry.data.title}><DocsLayout entry={entry} entries={entries}>…</DocsLayout></Layout>
|
|
55
|
+
-->
|
|
56
|
+
<div class="h-full bg-background text-foreground antialiased">
|
|
40
57
|
<!-- Top bar -->
|
|
41
58
|
<header class="sticky top-0 z-40 flex h-14 items-center gap-4 border-b border-border bg-background/95 px-6 backdrop-blur">
|
|
42
59
|
<a href="/docs" class="mr-4 text-sm font-semibold text-foreground hover:text-primary">
|
|
@@ -70,7 +87,7 @@ const tocHeadings = headings.filter((h) => h.depth === 2 || h.depth === 3)
|
|
|
70
87
|
<p class="mb-8 text-lg text-muted-foreground">{entry.data.description}</p>
|
|
71
88
|
)}
|
|
72
89
|
<div class="prose prose-slate dark:prose-invert max-w-none">
|
|
73
|
-
<slot />
|
|
90
|
+
{Content ? <Content /> : <slot />}
|
|
74
91
|
</div>
|
|
75
92
|
|
|
76
93
|
<!-- Edit this page -->
|
|
@@ -114,5 +131,4 @@ const tocHeadings = headings.filter((h) => h.depth === 2 || h.depth === 3)
|
|
|
114
131
|
</div>
|
|
115
132
|
</main>
|
|
116
133
|
</div>
|
|
117
|
-
|
|
118
|
-
</html>
|
|
134
|
+
</div>
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro'
|
|
1
2
|
import type { OnePluginFactory } from '@oneie/frontend'
|
|
2
3
|
|
|
3
4
|
export interface SidebarFolder {
|
|
@@ -17,12 +18,39 @@ export interface OneDocsConfig {
|
|
|
17
18
|
editBaseUrl?: string
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const defaults: Required<Pick<OneDocsConfig, 'injectRoutes'>> = {
|
|
22
|
+
injectRoutes: true,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const docs: OnePluginFactory<OneDocsConfig> = (config = {}) => {
|
|
26
|
+
const resolved = { ...defaults, ...config }
|
|
27
|
+
|
|
28
|
+
const integration = (): AstroIntegration => ({
|
|
29
|
+
name: '@oneie/plugin-docs',
|
|
30
|
+
hooks: {
|
|
31
|
+
'astro:config:setup': ({ injectRoute }) => {
|
|
32
|
+
if (resolved.injectRoutes) {
|
|
33
|
+
injectRoute({
|
|
34
|
+
pattern: '/docs',
|
|
35
|
+
entrypoint: '@oneie/plugin-docs/DocsIndex.astro',
|
|
36
|
+
})
|
|
37
|
+
injectRoute({
|
|
38
|
+
pattern: '/docs/[slug]',
|
|
39
|
+
entrypoint: '@oneie/plugin-docs/DocsLayout.astro',
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
name: 'plugin-docs',
|
|
48
|
+
tier: 'free',
|
|
49
|
+
config: undefined,
|
|
50
|
+
integration,
|
|
51
|
+
entitlement: undefined,
|
|
52
|
+
serves: undefined,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
27
55
|
|
|
28
|
-
export type { OneDocsConfig as DocsConfig
|
|
56
|
+
export type { OneDocsConfig as DocsConfig }
|
package/tsconfig.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "
|
|
2
|
+
"extends": "../tsconfig.base.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"jsx": "react-jsx",
|
|
5
5
|
"jsxImportSource": "react",
|
|
6
6
|
"paths": {
|
|
7
|
-
"@/*": ["../../
|
|
7
|
+
"@/*": ["../../template/site/src/*"]
|
|
8
8
|
}
|
|
9
9
|
},
|
|
10
10
|
"include": ["src"]
|