igniteui-astro-components 0.0.1
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/LICENSE +21 -0
- package/README.md +374 -0
- package/package.json +109 -0
- package/src/components/DocsSidebar/DocsSidebar.astro +99 -0
- package/src/components/DocsSidebar/README.md +166 -0
- package/src/components/DocsSidebar/SidebarFilterInput.astro +74 -0
- package/src/components/DocsSidebar/SidebarLabel.astro +40 -0
- package/src/components/DocsSidebar/sidebar-filter.ts +393 -0
- package/src/components/DocsSidebar/toTreeNodes.ts +66 -0
- package/src/components/DocsSubHeader/DocsSubHeader.astro +320 -0
- package/src/components/DocsSubHeader/README.md +74 -0
- package/src/components/DocsToc/DocsToc.astro +307 -0
- package/src/components/DocsToc/README.md +68 -0
- package/src/components/DocsToc/toTreeNodes.ts +57 -0
- package/src/components/DocsTree/DocsTree.astro +66 -0
- package/src/components/DocsTree/DocsTreeItem.astro +84 -0
- package/src/components/DocsTree/README.md +105 -0
- package/src/components/DocsTree/docs-tree.css +227 -0
- package/src/components/DocsTree/types.ts +47 -0
- package/src/components/GlobalFooter/GlobalFooter.astro +90 -0
- package/src/components/GlobalFooter/GlobalFooter.module.scss +23 -0
- package/src/components/GlobalFooter/README.md +35 -0
- package/src/components/GlobalNavBar/GlobalNavBar.astro +218 -0
- package/src/components/GlobalNavBar/GlobalNavBar.module.scss +215 -0
- package/src/components/GlobalNavBar/README.md +49 -0
- package/src/components/MobileSidebarToggle/MobileSidebarToggle.astro +112 -0
- package/src/components/MobileSidebarToggle/README.md +31 -0
- package/src/components/Search/README.md +43 -0
- package/src/components/Search/Search.astro +222 -0
- package/src/components/ThemingWidget/README.md +35 -0
- package/src/components/ThemingWidget/ThemingWidget.astro +152 -0
- package/src/components/mdx/ApiLink/ApiLink.astro +121 -0
- package/src/components/mdx/ApiLink/README.md +68 -0
- package/src/components/mdx/ApiRef/ApiRef.astro +92 -0
- package/src/components/mdx/ApiRef/README.md +50 -0
- package/src/components/mdx/DocsAside/DocsAside.astro +86 -0
- package/src/components/mdx/DocsAside/README.md +66 -0
- package/src/components/mdx/DocsAside/icons/caution.svg +3 -0
- package/src/components/mdx/DocsAside/icons/danger.svg +3 -0
- package/src/components/mdx/DocsAside/icons/note.svg +3 -0
- package/src/components/mdx/DocsAside/icons/tip.svg +4 -0
- package/src/components/mdx/PlatformBlock/PlatformBlock.astro +24 -0
- package/src/components/mdx/PlatformBlock/README.md +57 -0
- package/src/components/mdx/Sample/README.md +59 -0
- package/src/components/mdx/Sample/Sample.astro +142 -0
- package/src/content-helper.ts +159 -0
- package/src/content.config.ts +17 -0
- package/src/index.ts +42 -0
- package/src/integration.ts +841 -0
- package/src/layouts/DocsLayout/DocsLayout.astro +307 -0
- package/src/layouts/DocsLayout/README.md +124 -0
- package/src/lib/nav-helpers.ts +155 -0
- package/src/lib/platform-context.ts +305 -0
- package/src/lib/sidebar/helpers.ts +81 -0
- package/src/lib/sidebar/types.ts +36 -0
- package/src/llms.ts +315 -0
- package/src/platform.ts +281 -0
- package/src/plugins/remark-docfx.ts +368 -0
- package/src/scripts/sample-widget.ts +516 -0
- package/src/sidebar.ts +167 -0
- package/src/styles/custom.scss +254 -0
- package/src/styles/ig-theme.scss +43 -0
- package/src/virtual-modules.d.ts +35 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Renders its slotted content only when the current build platform matches.
|
|
4
|
+
*
|
|
5
|
+
* Replaces the fragile comment-block pattern:
|
|
6
|
+
* <!-- Angular, React -->…<!-- end: Angular, React -->
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* <PlatformBlock for="Angular, React">
|
|
10
|
+
* This paragraph only appears in Angular and React docs.
|
|
11
|
+
* </PlatformBlock>
|
|
12
|
+
*/
|
|
13
|
+
import { getPlatformContext } from '../../../lib/platform-context';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
/** Comma-separated list of platform names to show content for. */
|
|
17
|
+
for: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { for: forProp } = Astro.props;
|
|
21
|
+
const allowed = forProp.split(',').map((s) => s.trim());
|
|
22
|
+
const { name } = getPlatformContext();
|
|
23
|
+
---
|
|
24
|
+
{allowed.includes(name) && <slot />}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# PlatformBlock
|
|
2
|
+
|
|
3
|
+
Conditionally renders its slotted content only when the current build platform matches one of the specified platform names. Replaces the legacy comment-block pattern (`<!-- Angular, React -->…<!-- end: Angular, React -->`).
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```astro
|
|
8
|
+
import PlatformBlock from 'igniteui-astro-components/components/mdx/PlatformBlock.astro';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
| Prop | Type | Description |
|
|
14
|
+
|------|------|-------------|
|
|
15
|
+
| `for` | `string` | Comma-separated list of platform names to show content for. |
|
|
16
|
+
|
|
17
|
+
Valid platform names: `Angular`, `React`, `WebComponents`, `Blazor`
|
|
18
|
+
|
|
19
|
+
## Examples
|
|
20
|
+
|
|
21
|
+
```mdx
|
|
22
|
+
{/* Single platform */}
|
|
23
|
+
<PlatformBlock for="Angular">
|
|
24
|
+
This paragraph only appears in Angular docs.
|
|
25
|
+
</PlatformBlock>
|
|
26
|
+
|
|
27
|
+
{/* Multiple platforms */}
|
|
28
|
+
<PlatformBlock for="Angular, React">
|
|
29
|
+
Visible in Angular and React docs only.
|
|
30
|
+
</PlatformBlock>
|
|
31
|
+
|
|
32
|
+
{/* All platforms (just write the content without PlatformBlock) */}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Platform context
|
|
36
|
+
|
|
37
|
+
The active platform is read from the `PLATFORM` environment variable via `getPlatformContext()`. Set it in `astro.config.ts`:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
createDocsSite({ platform: 'angular' });
|
|
41
|
+
// → only <PlatformBlock for="Angular"> blocks render
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or in the environment directly:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
PLATFORM=React astro build
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## MDX global registration
|
|
51
|
+
|
|
52
|
+
To avoid importing `PlatformBlock` in every MDX file, register it globally in `mdx-components.ts`:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
// src/mdx-components.ts
|
|
56
|
+
export { default as PlatformBlock } from 'igniteui-astro-components/components/mdx/PlatformBlock.astro';
|
|
57
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Sample
|
|
2
|
+
|
|
3
|
+
Renders a live demo widget with an embedded iframe, source code tabs, and live-edit buttons (StackBlitz / CodeSandbox). The HTML shell is rendered server-side; client interactivity is handled by the `sample-widget` script loaded once per page.
|
|
4
|
+
|
|
5
|
+
## Import
|
|
6
|
+
|
|
7
|
+
```astro
|
|
8
|
+
import Sample from 'igniteui-astro-components/components/mdx/Sample.astro';
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
| Prop | Type | Default | Description |
|
|
14
|
+
|------|------|---------|-------------|
|
|
15
|
+
| `src` | `string` | *(required)* | Sample path relative to the demos base URL, e.g. `"/charts/data-chart/axis-crossing"`. |
|
|
16
|
+
| `height` | `number` | `400` | iframe height in pixels. |
|
|
17
|
+
| `alt` | `string` | `''` | `title` attribute for the iframe (accessibility). |
|
|
18
|
+
| `lob` | `boolean` | `false` | Use `lobDemosBaseUrl` instead of `demosBaseUrl` (LOB/grid-dynamic demos). |
|
|
19
|
+
| `dv` | `boolean` | `false` | Force use of `dvDemosBaseUrl` (data-viz demos). Auto-detected for paths starting with `charts/`, `gauges/`, `maps/`, `excel/`. |
|
|
20
|
+
| `crm` | `boolean` | `false` | Use `crmDemoBaseUrl` (CRM demo samples). |
|
|
21
|
+
| `iframeOnly` | `boolean` | `false` | Render only the iframe — no navbar, no code tabs, no live-edit footer. |
|
|
22
|
+
| `fullscreenBtn` | `boolean` | `false` | When `iframeOnly={true}`, also renders a "View in full screen" button below the iframe. |
|
|
23
|
+
|
|
24
|
+
## Examples
|
|
25
|
+
|
|
26
|
+
```mdx
|
|
27
|
+
{/* Standard widget */}
|
|
28
|
+
<Sample src="/charts/data-chart/axis-crossing" height={500} alt="Angular Data Chart Example" />
|
|
29
|
+
|
|
30
|
+
{/* DV sample (auto-detected) */}
|
|
31
|
+
<Sample src="/gauges/radial-gauge/needle" height={350} />
|
|
32
|
+
|
|
33
|
+
{/* LOB demo */}
|
|
34
|
+
<Sample src="/grid/grid/filtering" lob />
|
|
35
|
+
|
|
36
|
+
{/* Bare iframe for embedding */}
|
|
37
|
+
<Sample src="/charts/bar-chart/overview" iframeOnly height={300} />
|
|
38
|
+
|
|
39
|
+
{/* Bare iframe + fullscreen link */}
|
|
40
|
+
<Sample src="/charts/bar-chart/overview" iframeOnly fullscreenBtn height={300} />
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Environment configuration
|
|
44
|
+
|
|
45
|
+
The base URLs are resolved from `environment.json` at build time via `siteMetaIntegration` and exposed through `getPlatformContext().getEnvVars()`:
|
|
46
|
+
|
|
47
|
+
| Key | Used by |
|
|
48
|
+
|-----|---------|
|
|
49
|
+
| `demosBaseUrl` | Default demos |
|
|
50
|
+
| `dvDemosBaseUrl` | Charts / gauges / maps / excel |
|
|
51
|
+
| `lobDemosBaseUrl` | LOB / grids |
|
|
52
|
+
| `crmDemoBaseUrl` | CRM demos |
|
|
53
|
+
|
|
54
|
+
## MDX global registration
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
// src/mdx-components.ts
|
|
58
|
+
export { default as Sample } from 'igniteui-astro-components/components/mdx/Sample.astro';
|
|
59
|
+
```
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Renders a live demo widget with source code tabs and live-edit buttons.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* <Sample src="/charts/data-chart/axis-crossing" height={500} alt="Angular Example" />
|
|
7
|
+
*
|
|
8
|
+
* The widget HTML shell is rendered server-side by Astro; client-side behaviour
|
|
9
|
+
* (iframe serial loading, code-tab fetching, tab switching, StackBlitz / CodeSandbox)
|
|
10
|
+
* is handled by src/scripts/sample-widget.ts which is imported via the
|
|
11
|
+
* deduplicated <script> below — it runs once per page regardless of how many
|
|
12
|
+
* <Sample> components appear.
|
|
13
|
+
*
|
|
14
|
+
* DV samples (charts/, gauges/, maps/, excel/) automatically use dvDemosBaseUrl
|
|
15
|
+
* when a separate demosBaseUrl is present in the environment config.
|
|
16
|
+
*/
|
|
17
|
+
import { getPlatformContext, getEnvVars } from '../../../lib/platform-context.ts';
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
src: string;
|
|
21
|
+
height?: number;
|
|
22
|
+
alt?: string;
|
|
23
|
+
/** Use lobDemosBaseUrl instead of demosBaseUrl (for LOB/grid-dynamic demos). */
|
|
24
|
+
lob?: boolean;
|
|
25
|
+
/** Use dvDemosBaseUrl (for DV samples whose path doesn't start with a DV prefix). */
|
|
26
|
+
dv?: boolean;
|
|
27
|
+
/** Use crmDemoBaseUrl (for CRM demo samples). */
|
|
28
|
+
crm?: boolean;
|
|
29
|
+
/** Render only the iframe — no navbar, no code tabs, no live-edit footer. */
|
|
30
|
+
iframeOnly?: boolean;
|
|
31
|
+
/** When used with iframeOnly, also render a "View in full screen" button below. */
|
|
32
|
+
fullscreenBtn?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { src, height = 400, alt = '', lob = false, dv = false, crm = false, iframeOnly = false, fullscreenBtn = false } = Astro.props;
|
|
36
|
+
const { name, lower } = getPlatformContext();
|
|
37
|
+
const env = getEnvVars();
|
|
38
|
+
|
|
39
|
+
// DV samples (charts, gauges, maps, excel) use dvDemosBaseUrl when available.
|
|
40
|
+
const DV_PREFIXES = ['gauges/', 'maps/', 'excel/', 'charts/'];
|
|
41
|
+
const srcNoSlash = src.replace(/^\//, '');
|
|
42
|
+
const isDv = dv || DV_PREFIXES.some(p => srcNoSlash.startsWith(p));
|
|
43
|
+
const baseUrl = lob ? (env.lobDemosBaseUrl ?? env.demosBaseUrl ?? '').replace(/\/$/, '')
|
|
44
|
+
: crm ? (env.crmDemoBaseUrl ?? env.demosBaseUrl ?? '').replace(/\/$/, '')
|
|
45
|
+
: isDv ? (env.dvDemosBaseUrl ?? env.demosBaseUrl ?? '').replace(/\/$/, '')
|
|
46
|
+
: (env.demosBaseUrl ?? '').replace(/\/$/, '');
|
|
47
|
+
|
|
48
|
+
const iframeSrc = `${baseUrl}${src}`;
|
|
49
|
+
const githubSrc = srcNoSlash;
|
|
50
|
+
|
|
51
|
+
// Stable, unique element ID derived from the sample path.
|
|
52
|
+
const widgetId = 'cw' + src.replace(/[^a-z0-9]/gi, '-');
|
|
53
|
+
const exampleTabId = `${widgetId}-example`;
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
{iframeOnly ? (
|
|
57
|
+
<>
|
|
58
|
+
<div class="sample-container" style={`height: ${height}px`}>
|
|
59
|
+
<iframe
|
|
60
|
+
src={iframeSrc}
|
|
61
|
+
title={alt || `${name} Example`}
|
|
62
|
+
style="width: 100%; height: 100%;"
|
|
63
|
+
frameborder="0"
|
|
64
|
+
seamless
|
|
65
|
+
></iframe>
|
|
66
|
+
</div>
|
|
67
|
+
{fullscreenBtn && (
|
|
68
|
+
<button class="full-screen-btn" onclick={`window.open("${iframeSrc}")`}>View in full screen</button>
|
|
69
|
+
)}
|
|
70
|
+
</>
|
|
71
|
+
) : (
|
|
72
|
+
<>
|
|
73
|
+
<div class="code-view"
|
|
74
|
+
id={widgetId}
|
|
75
|
+
data-iframe-src={iframeSrc}
|
|
76
|
+
data-demos-base-url={baseUrl}
|
|
77
|
+
data-github-src={githubSrc}
|
|
78
|
+
data-platform={lower}>
|
|
79
|
+
<div class="code-view-navbar">
|
|
80
|
+
<div class="code-view-tab code-view-tab--active" data-tab-id={exampleTabId}>EXAMPLE</div>
|
|
81
|
+
<span class="fs-button-container" title="Expand to fullscreen"></span>
|
|
82
|
+
</div>
|
|
83
|
+
<div class="code-views-container">
|
|
84
|
+
<div id={exampleTabId}
|
|
85
|
+
class="sample-container code-view-tab-content loading"
|
|
86
|
+
style={`height: ${height}px`}>
|
|
87
|
+
<iframe
|
|
88
|
+
data-src={iframeSrc}
|
|
89
|
+
title={alt || `${name} Example`}
|
|
90
|
+
style="width: 100%; height: 100%;"
|
|
91
|
+
frameborder="0"
|
|
92
|
+
seamless
|
|
93
|
+
></iframe>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<div class="divider--half"></div>
|
|
99
|
+
|
|
100
|
+
<script>
|
|
101
|
+
// Astro deduplicates module scripts — this runs exactly once per full page load.
|
|
102
|
+
// astro:page-load fires after every client-router navigation AND on the initial
|
|
103
|
+
// page load, so using it as the sole trigger handles both cases without
|
|
104
|
+
// double-initialization.
|
|
105
|
+
import { initSampleWidgets } from '../../../scripts/sample-widget';
|
|
106
|
+
document.addEventListener('astro:page-load', initSampleWidgets);
|
|
107
|
+
</script>
|
|
108
|
+
</>
|
|
109
|
+
)}
|
|
110
|
+
|
|
111
|
+
<style>
|
|
112
|
+
.full-screen-btn {
|
|
113
|
+
display: inline-flex;
|
|
114
|
+
align-items: center;
|
|
115
|
+
font-size: 0.8rem;
|
|
116
|
+
font-weight: 400;
|
|
117
|
+
color: #fff;
|
|
118
|
+
border: 0;
|
|
119
|
+
text-transform: uppercase;
|
|
120
|
+
padding: 0.5rem 1rem;
|
|
121
|
+
margin: 1.5rem 0;
|
|
122
|
+
outline-style: none;
|
|
123
|
+
transition: all 0.25s ease-out;
|
|
124
|
+
background: #0099ff;
|
|
125
|
+
cursor: pointer;
|
|
126
|
+
}
|
|
127
|
+
.full-screen-btn:hover,
|
|
128
|
+
.full-screen-btn:focus {
|
|
129
|
+
color: white;
|
|
130
|
+
box-shadow: 0 5px 5px -3px rgba(0,0,0,.26), 0 8px 10px 1px rgba(0,0,0,.12), 0 3px 14px 2px rgba(0,0,0,.08);
|
|
131
|
+
}
|
|
132
|
+
.full-screen-btn::before {
|
|
133
|
+
content: "";
|
|
134
|
+
display: inline-block;
|
|
135
|
+
width: 1.75rem;
|
|
136
|
+
height: 1.75rem;
|
|
137
|
+
margin-right: 0.5rem;
|
|
138
|
+
background-image: url("/images/general/fullscreen-white-18dp.svg");
|
|
139
|
+
background-size: 100%;
|
|
140
|
+
background-repeat: no-repeat;
|
|
141
|
+
}
|
|
142
|
+
</style>
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* content-helper.ts
|
|
3
|
+
*
|
|
4
|
+
* Exports `createDocsCollection` — a helper for consuming Astro projects to
|
|
5
|
+
* wire up their own `src/content.config.ts` with a single call.
|
|
6
|
+
*
|
|
7
|
+
* ── Zero-config usage (recommended when using createDocsSite) ─────────────
|
|
8
|
+
*
|
|
9
|
+
* // src/content.config.ts — entire file, nothing else needed
|
|
10
|
+
* import { collections } from 'docs-template/content';
|
|
11
|
+
* export { collections };
|
|
12
|
+
*
|
|
13
|
+
* `createDocsSite({ source: { docsDir } })` in astro.config.ts
|
|
14
|
+
* automatically sets DOCS_SOURCE_PATH, so the exported `collections`
|
|
15
|
+
* object picks it up with no extra configuration.
|
|
16
|
+
*
|
|
17
|
+
* ── Custom excludes / extra schema fields ────────────────────────────────
|
|
18
|
+
*
|
|
19
|
+
* import { z } from 'astro:content';
|
|
20
|
+
* import { createDocsCollection } from 'docs-template/content';
|
|
21
|
+
*
|
|
22
|
+
* export const collections = {
|
|
23
|
+
* docs: createDocsCollection(process.env.DOCS_SOURCE_PATH, {
|
|
24
|
+
* exclude: ['internal/**', 'draft.md'],
|
|
25
|
+
* extendSchema: z.object({ myCustomField: z.string().optional() }),
|
|
26
|
+
* }),
|
|
27
|
+
* };
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { defineCollection } from 'astro:content';
|
|
31
|
+
import { glob } from 'astro/loaders';
|
|
32
|
+
import { z } from 'astro/zod';
|
|
33
|
+
import { pathToFileURL } from 'node:url';
|
|
34
|
+
|
|
35
|
+
/** Sentinel value placed on entries that have no title so we can remove them after loading. */
|
|
36
|
+
const SKIP_TITLE = '\x00skip';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Wraps a loader so that after it populates the store, any entry whose
|
|
40
|
+
* title equals the SKIP_TITLE sentinel is silently removed.
|
|
41
|
+
*/
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
function withTitleFilter(baseLoader: any): any {
|
|
44
|
+
return {
|
|
45
|
+
...baseLoader,
|
|
46
|
+
load: async (ctx: any) => {
|
|
47
|
+
await baseLoader.load(ctx);
|
|
48
|
+
for (const id of [...ctx.store.keys()]) {
|
|
49
|
+
const entry = ctx.store.get(id);
|
|
50
|
+
if (!entry?.data?.title || entry.data.title === SKIP_TITLE) {
|
|
51
|
+
ctx.store.delete(id);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Base frontmatter schema for MDX/Markdown documentation files.
|
|
60
|
+
* Wraps with a z.preprocess that injects a sentinel title for entries
|
|
61
|
+
* missing one so the glob loader doesn't throw InvalidContentEntryDataError.
|
|
62
|
+
*/
|
|
63
|
+
function makeDocsSchema(extend?: z.ZodObject<z.ZodRawShape>) {
|
|
64
|
+
const base = z.object({
|
|
65
|
+
title: z.string(),
|
|
66
|
+
description: z.string().optional().nullable(),
|
|
67
|
+
keywords: z.string().optional().nullable(),
|
|
68
|
+
draft: z.boolean().optional(),
|
|
69
|
+
license: z.string().optional(),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const schema = extend ? base.merge(extend) : base;
|
|
73
|
+
|
|
74
|
+
return z.preprocess(
|
|
75
|
+
(data: unknown) => {
|
|
76
|
+
if (typeof data === 'object' && data !== null) {
|
|
77
|
+
const d = data as Record<string, unknown>;
|
|
78
|
+
if (d['description'] === null) delete d['description'];
|
|
79
|
+
if (!d['title']) return { ...d, title: SKIP_TITLE };
|
|
80
|
+
}
|
|
81
|
+
return data;
|
|
82
|
+
},
|
|
83
|
+
schema,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface CreateDocsCollectionOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Glob patterns to exclude (relative to `sourceDir`). A leading `!` is
|
|
90
|
+
* added automatically when missing, so `'internal/**'` and
|
|
91
|
+
* `'!internal/**'` are both accepted.
|
|
92
|
+
*/
|
|
93
|
+
exclude?: string[];
|
|
94
|
+
/**
|
|
95
|
+
* Additional Zod object fields merged into the docs schema.
|
|
96
|
+
* Useful for repo-specific frontmatter fields.
|
|
97
|
+
*/
|
|
98
|
+
extendSchema?: z.ZodObject<z.ZodRawShape>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Creates an Astro content collection (`docs`) for a docs site,
|
|
103
|
+
* using a glob loader against the given source directory.
|
|
104
|
+
*
|
|
105
|
+
* @param sourceDir - Absolute path to the directory containing the source
|
|
106
|
+
* `.md`/`.mdx` files. Defaults to `process.env.DOCS_SOURCE_PATH` if omitted.
|
|
107
|
+
* @param options - Optional exclude patterns and schema extension.
|
|
108
|
+
*/
|
|
109
|
+
export function createDocsCollection(
|
|
110
|
+
sourceDir?: string,
|
|
111
|
+
{ exclude = [], extendSchema }: CreateDocsCollectionOptions = {},
|
|
112
|
+
) {
|
|
113
|
+
const dir = sourceDir ?? process.env.DOCS_SOURCE_PATH;
|
|
114
|
+
if (!dir) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
'[docs-template] createDocsCollection: no source directory provided. ' +
|
|
117
|
+
'Pass a path as the first argument or set the DOCS_SOURCE_PATH env variable.'
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const excludePatterns = exclude.map(p => (p.startsWith('!') ? p : `!${p}`));
|
|
122
|
+
|
|
123
|
+
return defineCollection({
|
|
124
|
+
loader: withTitleFilter(glob({
|
|
125
|
+
base: pathToFileURL(dir.endsWith('/') ? dir : dir + '/'),
|
|
126
|
+
pattern: [
|
|
127
|
+
'*.{md,mdx}',
|
|
128
|
+
'**/*.{md,mdx}',
|
|
129
|
+
'!**/_*.{md,mdx}',
|
|
130
|
+
'!**/toc.yml',
|
|
131
|
+
'!**/*.json',
|
|
132
|
+
'!readme.md',
|
|
133
|
+
'!README.md',
|
|
134
|
+
'!CHANGELOG.md',
|
|
135
|
+
'!LICENSE.md',
|
|
136
|
+
...excludePatterns,
|
|
137
|
+
],
|
|
138
|
+
})),
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
+
schema: makeDocsSchema(extendSchema) as any,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
// Zero-config pre-built export
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Ready-to-use `collections` object for the common case where
|
|
150
|
+
* `createDocsSite` is used in `astro.config.ts`.
|
|
151
|
+
*
|
|
152
|
+
* Usage — the entire `src/content.config.ts` in a consuming project:
|
|
153
|
+
*
|
|
154
|
+
* import { collections } from 'docs-template/content';
|
|
155
|
+
* export { collections };
|
|
156
|
+
*/
|
|
157
|
+
export const collections = {
|
|
158
|
+
docs: createDocsCollection(process.env.DOCS_SOURCE_PATH),
|
|
159
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Re-export the pre-built collection from the shared helper.
|
|
2
|
+
// DOCS_SOURCE_PATH is set to the components dir (en/components) by
|
|
3
|
+
// astro.config.ts before Astro evaluates this file.
|
|
4
|
+
import { createDocsCollection } from './content-helper.ts';
|
|
5
|
+
|
|
6
|
+
// TODO: remove these template-specific exclusions once the source repos add
|
|
7
|
+
// proper Starlight frontmatter to these files (no `title` → fail schema).
|
|
8
|
+
export const collections = {
|
|
9
|
+
docs: createDocsCollection(process.env.DOCS_SOURCE_PATH, {
|
|
10
|
+
exclude: [
|
|
11
|
+
'grids_templates/**',
|
|
12
|
+
'style-guide.md',
|
|
13
|
+
'themes/sass/presets/**',
|
|
14
|
+
'themes.md',
|
|
15
|
+
],
|
|
16
|
+
}),
|
|
17
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* igniteui-astro-components
|
|
3
|
+
*
|
|
4
|
+
* Public entry barrel. This module re-exports the JavaScript / TypeScript
|
|
5
|
+
* APIs only. `.astro` components must be imported via their explicit
|
|
6
|
+
* subpath exports declared in package.json — they cannot be re-exported
|
|
7
|
+
* from a `.ts` barrel because Astro components are not plain modules.
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
*
|
|
11
|
+
* // JS / TS APIs
|
|
12
|
+
* import { createDocsSite, buildSidebarFromToc } from 'igniteui-astro-components';
|
|
13
|
+
*
|
|
14
|
+
* // Astro components
|
|
15
|
+
* import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
|
|
16
|
+
* import ApiLink from 'igniteui-astro-components/components/mdx/ApiLink.astro';
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// Astro integration helpers
|
|
20
|
+
export * from './integration';
|
|
21
|
+
|
|
22
|
+
// Sidebar build-time helpers
|
|
23
|
+
export * from './sidebar';
|
|
24
|
+
|
|
25
|
+
// Platform helpers
|
|
26
|
+
export * from './platform';
|
|
27
|
+
|
|
28
|
+
// Content helpers
|
|
29
|
+
export * from './content-helper';
|
|
30
|
+
|
|
31
|
+
// Sidebar runtime types & tree helpers
|
|
32
|
+
export type {
|
|
33
|
+
SidebarBadge,
|
|
34
|
+
SidebarBadgeVariant,
|
|
35
|
+
SidebarLink,
|
|
36
|
+
SidebarGroup,
|
|
37
|
+
SidebarEntry,
|
|
38
|
+
} from './lib/sidebar/types';
|
|
39
|
+
export * from './lib/sidebar/helpers';
|
|
40
|
+
|
|
41
|
+
// Platform context
|
|
42
|
+
export * from './lib/platform-context';
|