@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/plugin-docs",
3
- "version": "0.1.0",
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
  }
@@ -38,16 +38,12 @@ function folderLabel(key: string): string {
38
38
  }
39
39
  ---
40
40
 
41
- <!doctype html>
42
- <html lang="en">
43
- <head>
44
- <meta charset="UTF-8" />
45
- <meta name="viewport" content="width=device-width, initial-scale=1" />
46
- <title>{title}</title>
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
- </body>
119
- </html>
114
+ </div>
@@ -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: CollectionEntry<'docs'>
8
- entries: CollectionEntry<'docs'>[]
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
- const { entry, entries, headings = [], editBaseUrl, sidebar } = Astro.props
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
- <!doctype html>
31
- <html lang="en" class="h-full">
32
- <head>
33
- <meta charset="UTF-8" />
34
- <meta name="viewport" content="width=device-width, initial-scale=1" />
35
- <title>{entry.data.title}</title>
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
- </body>
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
- export const docs: OnePluginFactory<OneDocsConfig> = (config = {}) => ({
21
- name: 'plugin-docs',
22
- tier: 'free',
23
- config: undefined,
24
- integration: undefined,
25
- entitlement: undefined,
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, SidebarFolder }
56
+ export type { OneDocsConfig as DocsConfig }
package/tsconfig.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
- "extends": "../../tsconfig.base.json",
2
+ "extends": "../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "jsx": "react-jsx",
5
5
  "jsxImportSource": "react",
6
6
  "paths": {
7
- "@/*": ["../../apps/web/src/*"]
7
+ "@/*": ["../../template/site/src/*"]
8
8
  }
9
9
  },
10
10
  "include": ["src"]