@riebeckite/honox 0.0.24 → 0.0.26

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/dist/index.js CHANGED
@@ -23,7 +23,7 @@ function siteRiebeckiteExternals(siteRoot) {
23
23
  const dependencies = packageJson.dependencies;
24
24
  if (!dependencies || typeof dependencies !== "object") return [];
25
25
  return Object.keys(dependencies).filter(
26
- (name) => name === "@riebeckite/core" || name.startsWith("@riebeckite/plugin-") || name.startsWith("@riebeckite/theme-")
26
+ (name) => name === "@riebeckite/core" || name === "@riebeckite/ui" || name.startsWith("@riebeckite/plugin-") || name.startsWith("@riebeckite/theme-")
27
27
  );
28
28
  }
29
29
 
@@ -678,10 +678,7 @@ function riebeckiteSsg(options = {}) {
678
678
  this,
679
679
  `client manifest ${clientBuildArtifacts ? `preserved (${clientBuildArtifacts.paths.length} files)` : "not found"}`
680
680
  );
681
- await rm(outDir, {
682
- recursive: true,
683
- force: true
684
- });
681
+ await emptyBuildOutputDirectory(outDir);
685
682
  },
686
683
  resolveId(id) {
687
684
  return id === virtualId ? resolvedVirtualId : void 0;
@@ -1053,6 +1050,17 @@ function isMissingDirectoryError(error) {
1053
1050
  function formatBytes(bytes) {
1054
1051
  return `${(bytes / (1024 * 1024)).toFixed(1)} MiB`;
1055
1052
  }
1053
+ async function emptyBuildOutputDirectory(outDir) {
1054
+ const entries = await readdir(outDir, { withFileTypes: true }).catch(
1055
+ (error) => {
1056
+ if (isMissingDirectoryError(error)) return [];
1057
+ throw error;
1058
+ }
1059
+ );
1060
+ for (const entry of entries) {
1061
+ await rm(join(outDir, entry.name), { recursive: true, force: true });
1062
+ }
1063
+ }
1056
1064
  async function preserveClientBuildArtifacts(outDir) {
1057
1065
  const manifestPath = ".vite/manifest.json";
1058
1066
  let manifestSource;
@@ -2113,6 +2121,10 @@ async function hasViteConfig(directory) {
2113
2121
 
2114
2122
  // src/vite_plugin.ts
2115
2123
  var defaultSsrExternals = [
2124
+ "hono",
2125
+ "hono/html",
2126
+ "hono/jsx",
2127
+ "hono/jsx/jsx-runtime",
2116
2128
  "extend",
2117
2129
  "debug",
2118
2130
  "node:fs/promises",
package/dist/server.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export type { ResolvedContentRequest, ResolvedContentRoute, ResolvedRiebeckiteRoute, } from "./src/content_route.js";
2
2
  export { applyRiebeckiteRouteContext, contentRouteSsgParams, pluginPageSsgParams, resolveContentRoute, resolveRiebeckiteContentRequest, resolveRiebeckiteHomeRequest, resolveRiebeckiteRoute, riebeckiteSsgParams, ssgEnumerableHandler, } from "./src/content_route.js";
3
3
  export { mountRiebeckiteEndpoints } from "./src/endpoints.js";
4
+ export type { ContentRouteOptions, HomeRouteOptions } from "./src/routes.js";
5
+ export { createContentRoute, createHomeRoute } from "./src/routes.js";
package/dist/server.js CHANGED
@@ -236,9 +236,84 @@ function findHeader(headers, name) {
236
236
  );
237
237
  return key ? headers[key] : void 0;
238
238
  }
239
+
240
+ // src/routes.tsx
241
+ import { createPublicContentView } from "@riebeckite/core";
242
+ import { createRoute } from "honox/factory";
243
+
244
+ // src/ui/context.ts
245
+ import {
246
+ ArticleProvider,
247
+ SiteProvider,
248
+ useArticleContext,
249
+ useSiteContext
250
+ } from "@riebeckite/ui";
251
+
252
+ // src/ui/primitives.tsx
253
+ import { ColorModeScript } from "@riebeckite/plugin-color-mode";
254
+ import { raw } from "hono/html";
255
+ import { Link, Script } from "honox/server";
256
+ import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime";
257
+ import { createElement } from "hono/jsx";
258
+ function PageBody(props) {
259
+ return /* @__PURE__ */ jsx(
260
+ "div",
261
+ {
262
+ class: joinClassNames("rb-page-body", props.class, props.className),
263
+ dangerouslySetInnerHTML: { __html: props.html }
264
+ }
265
+ );
266
+ }
267
+ function joinClassNames(...classNames) {
268
+ return classNames.filter(Boolean).join(" ");
269
+ }
270
+
271
+ // src/routes.tsx
272
+ import { jsx as jsx2 } from "hono/jsx/jsx-runtime";
273
+ function createContentRoute(options) {
274
+ const path = options.path ?? "/:slug{.+}";
275
+ const parameter = options.parameter ?? "slug";
276
+ return createRoute(
277
+ contentRouteSsgParams(
278
+ path,
279
+ () => riebeckiteSsgParams(options.content, parameter)
280
+ ),
281
+ async (c) => {
282
+ const resolved = await resolveRiebeckiteContentRequest(
283
+ c,
284
+ options.content,
285
+ parameter
286
+ );
287
+ if (resolved.kind === "response") return resolved.response;
288
+ if (resolved.kind === "page")
289
+ return c.render(/* @__PURE__ */ jsx2(PageBody, { html: resolved.page.body }));
290
+ return renderContent(c, options, resolved.entry, resolved.post);
291
+ }
292
+ );
293
+ }
294
+ function createHomeRoute(options) {
295
+ return createRoute(async (c) => {
296
+ const resolved = await resolveRiebeckiteHomeRequest(c, options.content);
297
+ if (resolved.kind === "response") return resolved.response;
298
+ if (resolved.kind === "page")
299
+ return c.render(/* @__PURE__ */ jsx2(PageBody, { html: resolved.page.body }));
300
+ return renderContent(c, options, resolved.entry, resolved.post);
301
+ });
302
+ }
303
+ async function renderContent(c, options, entry, post) {
304
+ const manifest = await options.content.getManifest();
305
+ const view = createPublicContentView(manifest);
306
+ const publicEntry = view.findRoutableBySlug(entry.slug);
307
+ if (!publicEntry) return c.notFound();
308
+ return c.render(
309
+ /* @__PURE__ */ jsx2(ArticleProvider, { entry: publicEntry, post, children: options.render({ entry, post }) })
310
+ );
311
+ }
239
312
  export {
240
313
  applyRiebeckiteRouteContext,
241
314
  contentRouteSsgParams,
315
+ createContentRoute,
316
+ createHomeRoute,
242
317
  mountRiebeckiteEndpoints,
243
318
  pluginPageSsgParams,
244
319
  resolveContentRoute,
@@ -0,0 +1,18 @@
1
+ import type { ContentManager, ContentManifestEntry, PostContent, ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ import type { Child } from "hono/jsx";
3
+ type RouteContent = Pick<ContentManager, "resolvePage" | "getManifest" | "getProcessedContent" | "getOutputChangeSet" | "getPagePaths">;
4
+ type RenderContent = (content: {
5
+ entry: ContentManifestEntry;
6
+ post: PostContent;
7
+ }) => Child;
8
+ export type ContentRouteOptions = {
9
+ content: RouteContent;
10
+ config: ResolvedRiebeckiteConfig;
11
+ render: RenderContent;
12
+ path?: string;
13
+ parameter?: string;
14
+ };
15
+ export type HomeRouteOptions = Omit<ContentRouteOptions, "path" | "parameter">;
16
+ export declare function createContentRoute(options: ContentRouteOptions): [import("hono/types").H<any, string, {}, Response>, import("hono/types").H<{}, string, {}, Promise<Response>>];
17
+ export declare function createHomeRoute(options: HomeRouteOptions): [import("hono/types").H<import("hono").Env, string, {}, Promise<Response>>];
18
+ export {};
@@ -32,6 +32,7 @@ export type RiebeckiteSsgOptions = {
32
32
  extensionMap?: Record<string, string>;
33
33
  };
34
34
  export declare function riebeckiteSsg(options?: RiebeckiteSsgOptions): Plugin;
35
+ export declare function emptyBuildOutputDirectory(outDir: string): Promise<void>;
35
36
  export declare function shouldApplyRiebeckiteSsg(_config: unknown, env: ConfigEnv): boolean;
36
37
  export declare function findBuildOutputSiteCollisions(buildOutputPaths: Iterable<string>, siteOwnedOutputPaths: ReadonlySet<string>): readonly string[];
37
38
  export declare function verifyNoChangeFastPath(input: {
@@ -0,0 +1,2 @@
1
+ export type { ArticleContextValue, SiteContextValue, } from "@riebeckite/ui";
2
+ export { ArticleProvider, SiteProvider, useArticleContext, useSiteContext, } from "@riebeckite/ui";
@@ -0,0 +1,13 @@
1
+ // src/ui/context.ts
2
+ import {
3
+ ArticleProvider,
4
+ SiteProvider,
5
+ useArticleContext,
6
+ useSiteContext
7
+ } from "@riebeckite/ui";
8
+ export {
9
+ ArticleProvider,
10
+ SiteProvider,
11
+ useArticleContext,
12
+ useSiteContext
13
+ };
@@ -1,4 +1,4 @@
1
- import type { PluginHeadTag, ResolvedRiebeckiteConfig } from "@riebeckite/core";
1
+ import type { PluginHeadTag, PostContent, PublicContentEntry, ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
2
  export type PrimitiveChildren = unknown;
3
3
  export type PrimitiveProps = {
4
4
  children?: PrimitiveChildren;
@@ -11,6 +11,8 @@ export type PrimitiveClassProps = {
11
11
  };
12
12
  export type ArticleProps = PrimitiveProps & {
13
13
  "data-slot"?: string;
14
+ post?: PostContent;
15
+ entry?: PublicContentEntry;
14
16
  };
15
17
  export type ArticleLayoutProps = PrimitiveProps;
16
18
  export type ArticleHeaderProps = (PrimitiveClassProps & {
@@ -39,7 +41,7 @@ export declare function ArticleHeader(props: ArticleHeaderProps): import("hono/j
39
41
  export declare function ArticleMeta(props: ArticleMetaProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
40
42
  export declare function ArticleContent(props: ArticleContentProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
41
43
  export type ArticleBodyProps = PrimitiveClassProps & {
42
- html: string;
44
+ html?: string;
43
45
  };
44
46
  export type HtmlFragmentSource = "markdown" | "plugin-page";
45
47
  export type HtmlFragmentProps = {
@@ -66,7 +68,7 @@ export declare function PageBody(props: PageBodyProps): import("hono/jsx/jsx-dev
66
68
  export declare function ArticleFooter(props: ArticleFooterProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
67
69
  export declare function Sidebar(props: SidebarProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
68
70
  export type ThemeRootProps = {
69
- theme: ResolvedRiebeckiteConfig["theme"];
71
+ theme?: ResolvedRiebeckiteConfig["theme"];
70
72
  lang?: string;
71
73
  children?: PrimitiveChildren;
72
74
  };
@@ -94,7 +96,7 @@ export type PluginHeadTagsProps = {
94
96
  */
95
97
  export declare function PluginHeadTags(props: PluginHeadTagsProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
96
98
  export type RiebeckiteHeadProps = {
97
- title: string;
99
+ title?: string;
98
100
  headTags?: readonly PluginHeadTag[];
99
101
  faviconHref?: string | null;
100
102
  colorModeScript?: boolean;
@@ -2,10 +2,20 @@
2
2
  import { ColorModeScript } from "@riebeckite/plugin-color-mode";
3
3
  import { raw } from "hono/html";
4
4
  import { Link, Script } from "honox/server";
5
+
6
+ // src/ui/context.ts
7
+ import {
8
+ ArticleProvider,
9
+ SiteProvider,
10
+ useArticleContext,
11
+ useSiteContext
12
+ } from "@riebeckite/ui";
13
+
14
+ // src/ui/primitives.tsx
5
15
  import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime";
6
16
  import { createElement } from "hono/jsx";
7
17
  function Article(props) {
8
- return /* @__PURE__ */ jsx(
18
+ const article = /* @__PURE__ */ jsx(
9
19
  "article",
10
20
  {
11
21
  class: joinClassNames("rb-article", props.class, props.className),
@@ -13,6 +23,8 @@ function Article(props) {
13
23
  children: props.children
14
24
  }
15
25
  );
26
+ if (!props.post) return article;
27
+ return /* @__PURE__ */ jsx(ArticleProvider, { entry: props.entry, post: props.post, children: article });
16
28
  }
17
29
  function ArticleLayout(props) {
18
30
  return /* @__PURE__ */ jsx(
@@ -63,11 +75,14 @@ function HtmlFragment(props) {
63
75
  return raw(props.html);
64
76
  }
65
77
  function ArticleBody(props) {
78
+ const article = useArticleContext();
79
+ const html = props.html ?? article?.post.html;
80
+ if (html === void 0) return null;
66
81
  return /* @__PURE__ */ jsx(
67
82
  "div",
68
83
  {
69
84
  class: joinClassNames("rb-article-content", props.class, props.className),
70
- dangerouslySetInnerHTML: { __html: props.html }
85
+ dangerouslySetInnerHTML: { __html: html }
71
86
  }
72
87
  );
73
88
  }
@@ -109,7 +124,11 @@ function themeRootAttributes(theme) {
109
124
  };
110
125
  }
111
126
  function ThemeRoot(props) {
112
- return /* @__PURE__ */ jsx("html", { lang: props.lang, ...themeRootAttributes(props.theme), children: props.children });
127
+ const site = useSiteContext();
128
+ const theme = props.theme ?? site?.config.theme;
129
+ const lang = props.lang ?? site?.language ?? site?.config.site.locale;
130
+ if (!theme) return /* @__PURE__ */ jsx("html", { lang, children: props.children });
131
+ return /* @__PURE__ */ jsx("html", { lang, ...themeRootAttributes(theme), children: props.children });
113
132
  }
114
133
  function PluginHeadTags(props) {
115
134
  return /* @__PURE__ */ jsx(Fragment, { children: props.tags?.map(renderPluginHeadTag) });
@@ -132,6 +151,7 @@ function renderPluginHeadTag(tag, index) {
132
151
  );
133
152
  }
134
153
  function RiebeckiteHead(props) {
154
+ const site = useSiteContext();
135
155
  const faviconHref = props.faviconHref === void 0 ? "/favicon.ico" : props.faviconHref;
136
156
  const stylesheets = props.stylesheets ?? ["/app/style.css"];
137
157
  const clientSrc = props.clientSrc === void 0 ? "/app/client.ts" : props.clientSrc;
@@ -139,11 +159,11 @@ function RiebeckiteHead(props) {
139
159
  return /* @__PURE__ */ jsxs(Fragment, { children: [
140
160
  /* @__PURE__ */ jsx("meta", { charset: "utf-8" }),
141
161
  /* @__PURE__ */ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" }),
142
- /* @__PURE__ */ jsx("title", { children: props.title }),
162
+ /* @__PURE__ */ jsx("title", { children: props.title ?? site?.config.site.title }),
143
163
  faviconHref ? /* @__PURE__ */ jsx("link", { rel: "icon", href: faviconHref }) : null,
144
164
  colorModeScript ? /* @__PURE__ */ jsx(ColorModeScript, {}) : null,
145
165
  stylesheets.map((href) => /* @__PURE__ */ jsx(Link, { href, rel: "stylesheet", prod: props.prod }, href)),
146
- /* @__PURE__ */ jsx(PluginHeadTags, { tags: props.headTags }),
166
+ /* @__PURE__ */ jsx(PluginHeadTags, { tags: props.headTags ?? site?.headTags }),
147
167
  clientSrc ? /* @__PURE__ */ jsx(Script, { src: clientSrc, async: true, prod: props.prod }) : null,
148
168
  props.children
149
169
  ] });
@@ -12,7 +12,7 @@ export type RiebeckiteIntegrationOptions = {
12
12
  * external. These are internal to the integration: sites should not have to
13
13
  * restate the Vite `environments.ssr.resolve.external` list.
14
14
  */
15
- export declare const defaultSsrExternals: readonly ["extend", "debug", "node:fs/promises", "node:path", "parse-numeric-range", "slugify", "vfile-matter", "yaml"];
15
+ export declare const defaultSsrExternals: readonly ["hono", "hono/html", "hono/jsx", "hono/jsx/jsx-runtime", "extend", "debug", "node:fs/promises", "node:path", "parse-numeric-range", "slugify", "vfile-matter", "yaml"];
16
16
  export type RiebeckiteViteOptions = RiebeckiteIntegrationOptions & {
17
17
  /** Extra SSR externals appended after Riebeckite's defaults. */
18
18
  ssrExternals?: readonly string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/honox",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -30,6 +30,12 @@
30
30
  "source": "./src/ui/primitives.tsx",
31
31
  "default": "./dist/src/ui/primitives.js"
32
32
  },
33
+ "./ui/context": {
34
+ "types": "./dist/src/ui/context.d.ts",
35
+ "import": "./dist/src/ui/context.js",
36
+ "source": "./src/ui/context.ts",
37
+ "default": "./dist/src/ui/context.js"
38
+ },
33
39
  "./style.css": "./style.css"
34
40
  },
35
41
  "dependencies": {
@@ -38,12 +44,13 @@
38
44
  "hono": "^4.12.25",
39
45
  "honox": "0.1.56",
40
46
  "vite": "^8.0.9",
41
- "@riebeckite/core": "0.0.24",
42
- "@riebeckite/plugin-color-mode": "0.0.24"
47
+ "@riebeckite/core": "0.0.26",
48
+ "@riebeckite/plugin-color-mode": "0.0.26",
49
+ "@riebeckite/ui": "0.0.26"
43
50
  },
44
51
  "devDependencies": {
45
52
  "tsx": "^4.22.4",
46
- "@riebeckite/test": "0.0.24"
53
+ "@riebeckite/test": "0.0.26"
47
54
  },
48
55
  "publishConfig": {
49
56
  "access": "public"