idcmd 0.0.11 → 0.0.13

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.
@@ -1,7 +1,4 @@
1
- /* eslint-disable react/no-danger */
2
- import type { JSX } from "preact";
3
-
4
- import { render } from "preact-render-to-string";
1
+ /* eslint-disable react/jsx-key */
5
2
 
6
3
  import type { NavGroup, NavItem } from "../content/navigation";
7
4
  import type { ResolvedRightRailConfig } from "../site/config";
@@ -10,6 +7,8 @@ import type { TocItem } from "./toc";
10
7
 
11
8
  import { RightRail } from "./right-rail";
12
9
 
10
+ const escapeText = (value: string): string => Bun.escapeHTML(value);
11
+
13
12
  export interface LayoutProps {
14
13
  title: string;
15
14
  siteName: string;
@@ -31,10 +30,7 @@ export interface LayoutProps {
31
30
  export type RenderLayout = (props: LayoutProps) => string;
32
31
 
33
32
  const Icon = ({ svg }: { svg: string }): JSX.Element => (
34
- <span
35
- class="inline-flex w-[18px] h-[18px]"
36
- dangerouslySetInnerHTML={{ __html: svg }}
37
- />
33
+ <span class="inline-flex w-[18px] h-[18px]">{svg}</span>
38
34
  );
39
35
 
40
36
  const isActiveLink = (item: NavItem, currentPath: string): boolean =>
@@ -59,7 +55,7 @@ const NavLink = ({
59
55
  class={`flex items-center gap-3 px-3 py-1.5 text-sm hover:text-sidebar-foreground transition-colors ${activeClass}`}
60
56
  >
61
57
  <Icon svg={item.iconSvg} />
62
- <span>{item.title}</span>
58
+ <span>{escapeText(item.title)}</span>
63
59
  </a>
64
60
  );
65
61
  };
@@ -73,11 +69,11 @@ const NavGroupComponent = ({
73
69
  }): JSX.Element => (
74
70
  <div class="py-2">
75
71
  <div class="px-3 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider">
76
- {group.label}
72
+ {escapeText(group.label)}
77
73
  </div>
78
74
  <nav class="space-y-1">
79
75
  {group.items.map((item) => (
80
- <NavLink key={item.href} item={item} currentPath={currentPath} />
76
+ <NavLink item={item} currentPath={currentPath} />
81
77
  ))}
82
78
  </nav>
83
79
  </div>
@@ -100,71 +96,17 @@ const Sidebar = ({
100
96
  data-prefetch="hover"
101
97
  >
102
98
  <span class="text-muted-foreground">~/</span>
103
- {siteName}
99
+ {escapeText(siteName)}
104
100
  </a>
105
101
  </div>
106
102
  <div class="sidebar-content">
107
103
  {navigation.map((group) => (
108
- <NavGroupComponent
109
- key={group.id}
110
- group={group}
111
- currentPath={currentPath}
112
- />
104
+ <NavGroupComponent group={group} currentPath={currentPath} />
113
105
  ))}
114
106
  </div>
115
107
  </aside>
116
108
  );
117
109
 
118
- const SearchForm = ({ query }: { query?: string }): JSX.Element => (
119
- <form
120
- method="get"
121
- action="/search/"
122
- class="flex w-full items-center"
123
- role="search"
124
- noValidate
125
- >
126
- <label htmlFor="site-search" class="sr-only">
127
- Search pages
128
- </label>
129
- <input
130
- id="site-search"
131
- name="q"
132
- type="search"
133
- autoComplete="off"
134
- spellcheck={false}
135
- placeholder="Search..."
136
- defaultValue={query ?? ""}
137
- class="w-full border-b border-input bg-transparent px-1 py-1.5 text-sm placeholder:text-muted-foreground focus:border-foreground focus:outline-none transition-colors"
138
- />
139
- </form>
140
- );
141
-
142
- const TopNavbar = ({
143
- query,
144
- siteName,
145
- }: {
146
- query?: string;
147
- siteName: string;
148
- }): JSX.Element => (
149
- <header class="sticky top-0 z-30 border-b border-border bg-background/80 backdrop-blur-sm">
150
- <div class="mx-auto max-w-6xl px-8 py-3">
151
- <div class="flex items-center gap-4">
152
- <a
153
- href="/"
154
- class="text-sm font-medium tracking-tight font-mono lg:hidden"
155
- data-prefetch="hover"
156
- >
157
- <span class="text-muted-foreground">~/</span>
158
- {siteName}
159
- </a>
160
- <div class="not-prose w-full max-w-xs ml-auto">
161
- <SearchForm query={query} />
162
- </div>
163
- </div>
164
- </div>
165
- </header>
166
- );
167
-
168
110
  interface DocumentHeadProps {
169
111
  canonicalUrl?: string;
170
112
  description?: string;
@@ -183,14 +125,16 @@ const DocumentHead = ({
183
125
  <head>
184
126
  <meta charset="utf-8" />
185
127
  <meta name="viewport" content="width=device-width, initial-scale=1" />
186
- <title>{title}</title>
187
- {description ? <meta name="description" content={description} /> : null}
128
+ <title>{escapeText(title)}</title>
129
+ {description ? (
130
+ <meta name="description" content={escapeText(description)} />
131
+ ) : null}
188
132
  {canonicalUrl ? <link rel="canonical" href={canonicalUrl} /> : null}
189
133
  <link rel="preconnect" href="https://fonts.googleapis.com" />
190
134
  <link
191
135
  rel="preconnect"
192
136
  href="https://fonts.gstatic.com"
193
- crossOrigin="anonymous"
137
+ crossorigin="anonymous"
194
138
  />
195
139
  <link
196
140
  href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap"
@@ -231,7 +175,6 @@ interface DocumentBodyProps {
231
175
  rightRail: ResolvedRightRailConfig;
232
176
  scriptPaths: string[];
233
177
  scrollSpyDataset: ScrollSpyDataset;
234
- searchQuery?: string;
235
178
  shouldShowRightRail: boolean;
236
179
  siteName: string;
237
180
  tocItems: TocItem[];
@@ -246,7 +189,6 @@ const DocumentBody = ({
246
189
  rightRail,
247
190
  scriptPaths,
248
191
  scrollSpyDataset,
249
- searchQuery,
250
192
  shouldShowRightRail,
251
193
  siteName,
252
194
  tocItems,
@@ -264,13 +206,14 @@ const DocumentBody = ({
264
206
  currentPath={currentPath}
265
207
  />
266
208
  <div class="main-wrapper">
267
- <TopNavbar query={searchQuery} siteName={siteName} />
268
209
  <main class="main-content">
269
210
  <div class="mx-auto flex w-full max-w-6xl items-start gap-10">
270
211
  <article
271
212
  class={`prose min-w-0 flex-1${currentPath === "/" ? " prose-home" : ""}`}
272
- dangerouslySetInnerHTML={{ __html: content }}
273
- />
213
+ >
214
+ {/* content is pre-rendered markdown HTML */}
215
+ {content}
216
+ </article>
274
217
  {shouldShowRightRail ? (
275
218
  <RightRailComponent
276
219
  canonicalUrl={canonicalUrl}
@@ -282,12 +225,12 @@ const DocumentBody = ({
282
225
  </div>
283
226
  </main>
284
227
  <footer class="site-footer">
285
- Built with Preact SSR + Tailwind &nbsp;|&nbsp; Zero JavaScript on
286
- content pages
228
+ Built with idcmd SSR + Tailwind &nbsp;|&nbsp; Zero JavaScript on content
229
+ pages
287
230
  </footer>
288
231
  </div>
289
232
  {scriptPaths.map((scriptPath) => (
290
- <script key={scriptPath} defer src={scriptPath} />
233
+ <script defer src={scriptPath} />
291
234
  ))}
292
235
  </body>
293
236
  );
@@ -303,7 +246,6 @@ const Layout = ({
303
246
  currentPath,
304
247
  navigation,
305
248
  scriptPaths = [],
306
- searchQuery,
307
249
  showRightRail = true,
308
250
  rightRailComponent = RightRail,
309
251
  rightRail,
@@ -333,7 +275,6 @@ const Layout = ({
333
275
  rightRail={rightRail}
334
276
  scriptPaths={scriptPaths}
335
277
  scrollSpyDataset={scrollSpyDataset}
336
- searchQuery={searchQuery}
337
278
  shouldShowRightRail={shouldShowRightRail}
338
279
  siteName={siteName}
339
280
  tocItems={tocItems}
@@ -344,4 +285,4 @@ const Layout = ({
344
285
  };
345
286
 
346
287
  export const renderLayout: RenderLayout = (props) =>
347
- `<!DOCTYPE html>${render(<Layout {...props} />)}`;
288
+ `<!DOCTYPE html>${<Layout {...props} />}`;
@@ -1,8 +1,10 @@
1
- import type { JSX } from "preact";
1
+ /* eslint-disable react/jsx-key */
2
2
 
3
3
  import type { ResolvedRightRailConfig } from "../site/config";
4
4
  import type { TocItem } from "./toc";
5
5
 
6
+ const escapeText = (value: string): string => Bun.escapeHTML(value);
7
+
6
8
  const CaretDownIcon = (): JSX.Element => (
7
9
  <svg
8
10
  width="16"
@@ -171,13 +173,13 @@ const OnThisPage = ({ items }: { items: TocItem[] }): JSX.Element => (
171
173
  <div class="toc-scroll min-h-0 flex-1" data-toc-scroll-container="1">
172
174
  <ul class="space-y-2 text-sm text-muted-foreground">
173
175
  {items.map((item) => (
174
- <li key={item.id} class={item.level >= 3 ? "pl-3" : ""}>
176
+ <li class={item.level >= 3 ? "pl-3" : ""}>
175
177
  <a
176
178
  href={`#${encodeURIComponent(item.id)}`}
177
179
  class="hover:text-foreground"
178
180
  data-toc-link="1"
179
181
  >
180
- {item.text}
182
+ {escapeText(item.text)}
181
183
  </a>
182
184
  </li>
183
185
  ))}
@@ -11,19 +11,16 @@ import {
11
11
  slugFromContentFile,
12
12
  } from "../content/paths";
13
13
 
14
- export const SEARCH_INDEX_VERSION = 1 as const;
15
-
16
- export interface SearchIndexDocumentV1 {
14
+ export interface SearchIndexDocument {
17
15
  url: string;
18
16
  title: string;
19
17
  description: string;
20
18
  body: string;
21
19
  }
22
20
 
23
- export interface SearchIndexV1 {
24
- version: typeof SEARCH_INDEX_VERSION;
21
+ export interface SearchIndex {
25
22
  generatedAt: string;
26
- documents: SearchIndexDocumentV1[];
23
+ documents: SearchIndexDocument[];
27
24
  }
28
25
 
29
26
  const SEARCH_INDEX_PATH = "public/search-index.json";
@@ -67,7 +64,7 @@ const isEligibleDocument = (
67
64
  hidden: boolean | undefined
68
65
  ): boolean => !hidden && slug !== "404";
69
66
 
70
- const sortDocuments = (documents: SearchIndexDocumentV1[]): void => {
67
+ const sortDocuments = (documents: SearchIndexDocument[]): void => {
71
68
  documents.sort((a, b) => {
72
69
  if (a.url === "/") {
73
70
  return -1;
@@ -84,7 +81,7 @@ const buildDocumentFromFile = async (
84
81
  bodyMaxChars: number,
85
82
  contentDir: string,
86
83
  siteConfig: SiteConfig
87
- ): Promise<SearchIndexDocumentV1 | null> => {
84
+ ): Promise<SearchIndexDocument | null> => {
88
85
  const slug = slugFromContentFile(file);
89
86
  const markdown = await Bun.file(`${contentDir}/${file}`).text();
90
87
  const parsed = parseFrontmatter(markdown);
@@ -117,11 +114,11 @@ export interface GenerateSearchIndexOptions {
117
114
 
118
115
  export const generateSearchIndexFromContent = async (
119
116
  options: GenerateSearchIndexOptions
120
- ): Promise<SearchIndexV1> => {
117
+ ): Promise<SearchIndex> => {
121
118
  const { bodyMaxChars = DEFAULT_BODY_MAX_CHARS, siteConfig } = options;
122
119
  const generatedAt = options.generatedAt ?? new Date().toISOString();
123
120
 
124
- const documents: SearchIndexDocumentV1[] = [];
121
+ const documents: SearchIndexDocument[] = [];
125
122
  const contentDir = await getContentDir();
126
123
 
127
124
  for await (const file of scanContentFiles()) {
@@ -141,13 +138,12 @@ export const generateSearchIndexFromContent = async (
141
138
  return {
142
139
  documents,
143
140
  generatedAt,
144
- version: SEARCH_INDEX_VERSION,
145
141
  };
146
142
  };
147
143
 
148
- const isSearchIndexDocumentV1 = (
144
+ const isSearchIndexDocument = (
149
145
  value: unknown
150
- ): value is SearchIndexDocumentV1 => {
146
+ ): value is SearchIndexDocument => {
151
147
  if (!value || typeof value !== "object") {
152
148
  return false;
153
149
  }
@@ -161,28 +157,27 @@ const isSearchIndexDocumentV1 = (
161
157
  );
162
158
  };
163
159
 
164
- const isSearchIndexV1 = (value: unknown): value is SearchIndexV1 => {
160
+ const isSearchIndex = (value: unknown): value is SearchIndex => {
165
161
  if (!value || typeof value !== "object") {
166
162
  return false;
167
163
  }
168
164
 
169
165
  const record = value as Record<string, unknown>;
170
166
  return (
171
- record.version === SEARCH_INDEX_VERSION &&
172
167
  isNonEmptyString(record.generatedAt) &&
173
168
  Array.isArray(record.documents) &&
174
- record.documents.every((doc) => isSearchIndexDocumentV1(doc))
169
+ record.documents.every((doc) => isSearchIndexDocument(doc))
175
170
  );
176
171
  };
177
172
 
178
- let indexCache: SearchIndexV1 | null = null;
173
+ let indexCache: SearchIndex | null = null;
179
174
 
180
175
  export interface LoadSearchIndexOptions {
181
176
  forceRefresh?: boolean;
182
177
  siteConfig: SiteConfig;
183
178
  }
184
179
 
185
- const tryLoadSearchIndexFromDisk = async (): Promise<SearchIndexV1 | null> => {
180
+ const tryLoadSearchIndexFromDisk = async (): Promise<SearchIndex | null> => {
186
181
  const file = Bun.file(SEARCH_INDEX_PATH);
187
182
  if (!(await file.exists())) {
188
183
  return null;
@@ -190,7 +185,7 @@ const tryLoadSearchIndexFromDisk = async (): Promise<SearchIndexV1 | null> => {
190
185
 
191
186
  try {
192
187
  const parsed = (await file.json()) as unknown;
193
- return isSearchIndexV1(parsed) ? parsed : null;
188
+ return isSearchIndex(parsed) ? parsed : null;
194
189
  } catch {
195
190
  return null;
196
191
  }
@@ -198,7 +193,7 @@ const tryLoadSearchIndexFromDisk = async (): Promise<SearchIndexV1 | null> => {
198
193
 
199
194
  export const loadSearchIndex = async (
200
195
  options: LoadSearchIndexOptions
201
- ): Promise<SearchIndexV1> => {
196
+ ): Promise<SearchIndex> => {
202
197
  const { forceRefresh = false, siteConfig } = options;
203
198
  if (indexCache && !forceRefresh) {
204
199
  return indexCache;
@@ -216,7 +211,7 @@ export const loadSearchIndex = async (
216
211
  };
217
212
 
218
213
  const getScopeHaystack = (
219
- document: SearchIndexDocumentV1,
214
+ document: SearchIndexDocument,
220
215
  scope: SearchScope
221
216
  ): string => {
222
217
  if (scope === "title") {
@@ -231,7 +226,7 @@ const getScopeHaystack = (
231
226
  };
232
227
 
233
228
  const matchesAllTokens = (
234
- document: SearchIndexDocumentV1,
229
+ document: SearchIndexDocument,
235
230
  tokens: readonly string[],
236
231
  scope: SearchScope
237
232
  ): boolean => {
@@ -239,14 +234,14 @@ const matchesAllTokens = (
239
234
  return tokens.every((token) => haystack.includes(token));
240
235
  };
241
236
 
242
- const toSearchResult = (document: SearchIndexDocumentV1): SearchResult => ({
237
+ const toSearchResult = (document: SearchIndexDocument): SearchResult => ({
243
238
  description: document.description,
244
239
  slug: document.url,
245
240
  title: document.title,
246
241
  });
247
242
 
248
243
  export const search = (
249
- index: SearchIndexV1,
244
+ index: SearchIndex,
250
245
  query: string,
251
246
  scope: SearchScope
252
247
  ): SearchResult[] => {
@@ -1,9 +1,9 @@
1
- import type { JSX } from "preact";
2
-
3
- import { render as renderToString } from "preact-render-to-string";
1
+ /* eslint-disable react/jsx-key */
4
2
 
5
3
  import type { SearchResult } from "./contract";
6
4
 
5
+ const escapeText = (value: string): string => Bun.escapeHTML(value);
6
+
7
7
  export interface TopPageLink {
8
8
  href: string;
9
9
  title: string;
@@ -24,9 +24,11 @@ const ResultItem = ({ result }: { result: SearchResult }): JSX.Element => (
24
24
  href={result.slug}
25
25
  class="font-medium underline decoration-border underline-offset-4"
26
26
  >
27
- {result.title}
27
+ {escapeText(result.title)}
28
28
  </a>
29
- <p class="mt-1 text-sm text-muted-foreground">{result.description}</p>
29
+ <p class="mt-1 text-sm text-muted-foreground">
30
+ {escapeText(result.description)}
31
+ </p>
30
32
  </li>
31
33
  );
32
34
 
@@ -44,12 +46,12 @@ const EmptyState = ({
44
46
  <p class="mt-4 font-medium text-foreground">Popular pages</p>
45
47
  <ul class="mt-2 space-y-1">
46
48
  {topPages.map((page) => (
47
- <li key={page.href}>
49
+ <li>
48
50
  <a
49
51
  href={page.href}
50
52
  class="underline decoration-border underline-offset-4"
51
53
  >
52
- {page.title}
54
+ {escapeText(page.title)}
53
55
  </a>
54
56
  </li>
55
57
  ))}
@@ -74,8 +76,8 @@ const SearchPage = ({
74
76
  {showResults ? (
75
77
  <p class="mt-2 text-sm text-muted-foreground">
76
78
  {results.length === 0
77
- ? `No matches for "${trimmed}".`
78
- : `Found ${results.length} result(s) for "${trimmed}".`}
79
+ ? `No matches for "${escapeText(trimmed)}".`
80
+ : `Found ${results.length} result(s) for "${escapeText(trimmed)}".`}
79
81
  </p>
80
82
  ) : (
81
83
  <div class="mt-2">
@@ -86,7 +88,7 @@ const SearchPage = ({
86
88
  {showResults ? (
87
89
  <ul class="mt-4 space-y-2">
88
90
  {results.map((result) => (
89
- <ResultItem key={result.slug} result={result} />
91
+ <ResultItem result={result} />
90
92
  ))}
91
93
  </ul>
92
94
  ) : null}
@@ -95,4 +97,4 @@ const SearchPage = ({
95
97
  };
96
98
 
97
99
  export const renderSearchPageContent: RenderSearchPageContent = (props) =>
98
- renderToString(<SearchPage {...props} />);
100
+ `${<SearchPage {...props} />}`;
@@ -141,7 +141,7 @@ const loadOneRoute = async (
141
141
  const pathname = pathnameFromRouteRelativePath(relativeFile);
142
142
  if (hasUnsupportedDynamicSegment(pathname)) {
143
143
  throw new Error(
144
- `Unsupported dynamic route segment in ${routesDir}/${relativeFile} (computed pathname: ${pathname}). V1 does not support [param] or :param routes.`
144
+ `Unsupported dynamic route segment in ${routesDir}/${relativeFile} (computed pathname: ${pathname}). Dynamic [param] and :param routes are not supported.`
145
145
  );
146
146
  }
147
147
 
@@ -19,6 +19,3 @@ jobs:
19
19
  run: bun install
20
20
  - name: Run checks
21
21
  run: bun run check
22
- - name: Run smoke
23
- timeout-minutes: 15
24
- run: bun run smoke
@@ -11,11 +11,10 @@ bun install
11
11
  bun run dev
12
12
  ```
13
13
 
14
- ## CI Smoke
14
+ ## Validation
15
15
 
16
16
  ```bash
17
17
  bun run check
18
- bun run smoke
19
18
  ```
20
19
 
21
20
  ## Layout
@@ -8,7 +8,6 @@
8
8
  "preview": "idcmd preview",
9
9
  "deploy": "idcmd deploy",
10
10
  "check": "bun run scripts/check.ts",
11
- "smoke": "bun run scripts/smoke.ts",
12
11
  "test": "bun test",
13
12
  "typecheck": "tsc --noEmit -p tsconfig.json",
14
13
  "fix": "ultracite fix"
@@ -1,4 +1,4 @@
1
1
  // Optional: this file is here as the obvious place to put server-side code.
2
- // V1 runs the built-in idcmd server; add custom endpoints via `src/routes/**`.
2
+ // Runs the built-in idcmd server; add custom endpoints via `src/routes/**`.
3
3
 
4
4
  export const serverPlaceholder = true;