@hollware/nuxt 0.0.0-stage → 0.4.0
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 +56 -2
- package/dist/index.d.mts +31 -0
- package/dist/index.mjs +58 -0
- package/dist/runtime/components/HollwareContent.d.mts +40 -0
- package/dist/runtime/components/HollwareContent.mjs +33 -0
- package/dist/runtime/composables.d.mts +67 -0
- package/dist/runtime/composables.mjs +32 -0
- package/dist/runtime/generator.d.mts +4 -0
- package/dist/runtime/generator.mjs +10 -0
- package/dist/runtime/server/answer.d.mts +16 -0
- package/dist/runtime/server/answer.mjs +49 -0
- package/dist/runtime/server/reader.d.mts +13 -0
- package/dist/runtime/server/reader.mjs +34 -0
- package/dist/runtime/server/routes/entries.d.mts +8 -0
- package/dist/runtime/server/routes/entries.mjs +29 -0
- package/dist/runtime/server/routes/entry.d.mts +7 -0
- package/dist/runtime/server/routes/entry.mjs +15 -0
- package/dist/runtime/server/routes/site.d.mts +34 -0
- package/dist/runtime/server/routes/site.mjs +10 -0
- package/dist/runtime/server/routes/translations.d.mts +7 -0
- package/dist/runtime/server/routes/translations.mjs +14 -0
- package/dist/runtime/types.d.mts +16 -0
- package/dist/runtime/types.mjs +1 -0
- package/package.json +56 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present Sergio Azócar and Hollware contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @hollware/nuxt
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read [Hollware](https://hollware.com) from a Nuxt site: over a service binding when the site is a
|
|
4
|
+
Worker on the same Cloudflare account, or over HTTP with a read token anywhere else.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @hollware/nuxt
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
// nuxt.config.ts
|
|
12
|
+
export default defineNuxtConfig({
|
|
13
|
+
modules: ['@hollware/nuxt'],
|
|
14
|
+
hollware: { site: 'my-site' },
|
|
15
|
+
nitro: { preset: 'cloudflare_module', cloudflare: { deployConfig: true, nodeCompat: false } },
|
|
16
|
+
})
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
On Cloudflare, bind the Hollware Worker in the site's `wrangler.jsonc`:
|
|
20
|
+
|
|
21
|
+
```jsonc
|
|
22
|
+
"services": [{ "binding": "HOLLWARE", "service": "my-hollware", "entrypoint": "Hollware" }]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Elsewhere, set `hollware.url` and a read token (`hollware token create --read`) in
|
|
26
|
+
`NUXT_HOLLWARE_TOKEN`. The token stays on the server: pages read through the site's own
|
|
27
|
+
`/_hollware/` routes.
|
|
28
|
+
|
|
29
|
+
```vue
|
|
30
|
+
<script setup lang="ts">
|
|
31
|
+
const { data } = await useHollwareEntry('blog', 'en', useRoute().params.slug as string)
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<h1>{{ data?.entry.frontmatter.title }}</h1>
|
|
36
|
+
<HollwareContent :entry="data?.entry" />
|
|
37
|
+
</template>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| What | Does |
|
|
41
|
+
| ----------------------------------------------- | ---------------------------------------------------- |
|
|
42
|
+
| `useHollwareEntry(collection, locale, slug)` | A published entry with its Comark document, or a 404 |
|
|
43
|
+
| `useHollwareEntries(collection, { locale, … })` | A page of published entries, newest first |
|
|
44
|
+
| `useHollwareTranslations(collection, group)` | The entries of a translation group |
|
|
45
|
+
| `useHollwareSite()` | The site: its locales and collections |
|
|
46
|
+
| `<HollwareContent :entry :components>` | Renders the document with `@comark/vue` |
|
|
47
|
+
| `useHollware(event)` (server) | The reader itself, for routes of your own |
|
|
48
|
+
|
|
49
|
+
Every page carries `<meta name="generator" content="Hollware">`; set `hollware.generator: false`
|
|
50
|
+
to leave it out.
|
|
51
|
+
|
|
52
|
+
## Links
|
|
53
|
+
|
|
54
|
+
- Docs: <https://hollware.com>
|
|
55
|
+
- Repository: <https://github.com/hollware/hollware>
|
|
56
|
+
- Issues: <https://github.com/hollware/hollware/issues>
|
|
57
|
+
- License: MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PageEntry } from "./runtime/types.mjs";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
/** The options of `hollware` in nuxt.config.ts. */
|
|
4
|
+
export interface ModuleOptions {
|
|
5
|
+
/** The key of the site in the Hollware config. Required. */
|
|
6
|
+
site: string;
|
|
7
|
+
/**
|
|
8
|
+
* The service binding to the `Hollware` entrypoint of the Hollware Worker, by its name in the
|
|
9
|
+
* site's wrangler.jsonc. When the Worker has it, every read goes over it: no network, no token.
|
|
10
|
+
*/
|
|
11
|
+
binding: string;
|
|
12
|
+
/**
|
|
13
|
+
* The public URL of the Hollware, to read over HTTP when there is no binding: at build time on
|
|
14
|
+
* another host, or a site off Cloudflare. It goes with `token`.
|
|
15
|
+
*/
|
|
16
|
+
url?: string;
|
|
17
|
+
/**
|
|
18
|
+
* A read token (`hw_read_`, from `hollware token create --read`). It stays on the server: pages
|
|
19
|
+
* read through the site's own `/_hollware/` routes. Prefer the `NUXT_HOLLWARE_TOKEN` variable to
|
|
20
|
+
* writing it here.
|
|
21
|
+
*/
|
|
22
|
+
token?: string;
|
|
23
|
+
/** Whether pages carry `<meta name="generator" content="Hollware">`. */
|
|
24
|
+
generator: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare const name = "@hollware/nuxt";
|
|
27
|
+
/** The routes of the site that read Hollware for its pages, on the server. */
|
|
28
|
+
export declare const ROUTES: readonly [readonly ['/_hollware/site', 'site'], readonly ['/_hollware/entries/:collection', 'entries'], readonly ['/_hollware/entry/:collection/:locale/:slug', 'entry'], readonly ['/_hollware/translations/:collection/:group', 'translations']];
|
|
29
|
+
declare const _default: import("nuxt/schema").NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { type PageEntry, _default as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { addComponent, addImports, addPlugin, addServerHandler, addServerImports, createResolver, defineNuxtModule } from "@nuxt/kit";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
const name = "@hollware/nuxt";
|
|
4
|
+
/** The routes of the site that read Hollware for its pages, on the server. */
|
|
5
|
+
const ROUTES = [
|
|
6
|
+
["/_hollware/site", "site"],
|
|
7
|
+
["/_hollware/entries/:collection", "entries"],
|
|
8
|
+
["/_hollware/entry/:collection/:locale/:slug", "entry"],
|
|
9
|
+
["/_hollware/translations/:collection/:group", "translations"]
|
|
10
|
+
];
|
|
11
|
+
var src_default = defineNuxtModule({
|
|
12
|
+
meta: {
|
|
13
|
+
name,
|
|
14
|
+
configKey: "hollware",
|
|
15
|
+
compatibility: { nuxt: ">=4.6.0" }
|
|
16
|
+
},
|
|
17
|
+
defaults: {
|
|
18
|
+
site: "",
|
|
19
|
+
binding: "HOLLWARE",
|
|
20
|
+
generator: true
|
|
21
|
+
},
|
|
22
|
+
setup(options, nuxt) {
|
|
23
|
+
if (options.site === "") throw new Error("@hollware/nuxt: set hollware.site in nuxt.config.ts to the key of your site in the Hollware config.");
|
|
24
|
+
const resolver = createResolver(import.meta.url);
|
|
25
|
+
const resolve = (path) => resolver.resolve(path);
|
|
26
|
+
nuxt.options.runtimeConfig["hollware"] = {
|
|
27
|
+
site: options.site,
|
|
28
|
+
binding: options.binding,
|
|
29
|
+
url: options.url ?? "",
|
|
30
|
+
token: options.token ?? ""
|
|
31
|
+
};
|
|
32
|
+
addServerImports([{
|
|
33
|
+
name: "useHollware",
|
|
34
|
+
from: resolve("./runtime/server/reader")
|
|
35
|
+
}]);
|
|
36
|
+
for (const [route, handler] of ROUTES) addServerHandler({
|
|
37
|
+
route,
|
|
38
|
+
method: "get",
|
|
39
|
+
handler: resolve(`./runtime/server/routes/${handler}`)
|
|
40
|
+
});
|
|
41
|
+
addImports([
|
|
42
|
+
"useHollwareEntry",
|
|
43
|
+
"useHollwareEntries",
|
|
44
|
+
"useHollwareSite",
|
|
45
|
+
"useHollwareTranslations"
|
|
46
|
+
].map((imported) => ({
|
|
47
|
+
name: imported,
|
|
48
|
+
from: resolve("./runtime/composables")
|
|
49
|
+
})));
|
|
50
|
+
addComponent({
|
|
51
|
+
name: "HollwareContent",
|
|
52
|
+
filePath: resolve("./runtime/components/HollwareContent")
|
|
53
|
+
});
|
|
54
|
+
if (options.generator) addPlugin(resolve("./runtime/generator"));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
//#endregion
|
|
58
|
+
export { ROUTES, src_default as default, name };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PropType } from "vue";
|
|
2
|
+
//#region src/runtime/components/HollwareContent.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The body of an entry: the Comark document Hollware stored when it was written, rendered with
|
|
5
|
+
* `@comark/vue`. `components` maps the names of the entry's components to the site's own.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
8
|
+
/** An entry as `useHollwareEntry` gives it, with its `document`. */
|
|
9
|
+
entry: {
|
|
10
|
+
type: PropType<{
|
|
11
|
+
document?: unknown;
|
|
12
|
+
} | null | undefined>;
|
|
13
|
+
default: null;
|
|
14
|
+
};
|
|
15
|
+
components: {
|
|
16
|
+
type: PropType<Record<string, unknown>>;
|
|
17
|
+
default: () => {};
|
|
18
|
+
};
|
|
19
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}> | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
22
|
+
/** An entry as `useHollwareEntry` gives it, with its `document`. */
|
|
23
|
+
entry: {
|
|
24
|
+
type: PropType<{
|
|
25
|
+
document?: unknown;
|
|
26
|
+
} | null | undefined>;
|
|
27
|
+
default: null;
|
|
28
|
+
};
|
|
29
|
+
components: {
|
|
30
|
+
type: PropType<Record<string, unknown>>;
|
|
31
|
+
default: () => {};
|
|
32
|
+
};
|
|
33
|
+
}>> & Readonly<{}>, {
|
|
34
|
+
entry: {
|
|
35
|
+
document?: unknown;
|
|
36
|
+
} | null | undefined;
|
|
37
|
+
components: Record<string, unknown>;
|
|
38
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { _default as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineComponent, h } from "vue";
|
|
2
|
+
import { MarkdownDocument } from "@comark/vue";
|
|
3
|
+
//#region src/runtime/components/HollwareContent.ts
|
|
4
|
+
/**
|
|
5
|
+
* The body of an entry: the Comark document Hollware stored when it was written, rendered with
|
|
6
|
+
* `@comark/vue`. `components` maps the names of the entry's components to the site's own.
|
|
7
|
+
*/
|
|
8
|
+
var HollwareContent_default = defineComponent({
|
|
9
|
+
name: "HollwareContent",
|
|
10
|
+
props: {
|
|
11
|
+
/** An entry as `useHollwareEntry` gives it, with its `document`. */
|
|
12
|
+
entry: {
|
|
13
|
+
type: Object,
|
|
14
|
+
default: null
|
|
15
|
+
},
|
|
16
|
+
components: {
|
|
17
|
+
type: Object,
|
|
18
|
+
default: () => ({})
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
setup(props) {
|
|
22
|
+
return () => {
|
|
23
|
+
const document = props.entry?.document;
|
|
24
|
+
if (typeof document !== "object" || document === null || !("nodes" in document)) return null;
|
|
25
|
+
return h(MarkdownDocument, {
|
|
26
|
+
value: document,
|
|
27
|
+
components: props.components
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
//#endregion
|
|
33
|
+
export { HollwareContent_default as default };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { PageEntry } from "./types.mjs";
|
|
2
|
+
import { MaybeRefOrGetter } from "vue";
|
|
3
|
+
//#region src/runtime/composables.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The published content of the site, for a page: each reads the site's own `/_hollware/` route,
|
|
6
|
+
* which reads Hollware on the server, so no token reaches the browser. They are `useFetch`, so the
|
|
7
|
+
* page renders on the server with the answer and the browser does not ask again.
|
|
8
|
+
*/
|
|
9
|
+
/** An entry, with its Comark document; `data` is null while it loads, `error` a 404 when it is not published. */
|
|
10
|
+
export declare function useHollwareEntry(collection: MaybeRefOrGetter<string>, locale: MaybeRefOrGetter<string>, slug: MaybeRefOrGetter<string>): import("nuxt/app").AsyncData<{
|
|
11
|
+
outcome: 'ok';
|
|
12
|
+
entry: PageEntry;
|
|
13
|
+
} | undefined, import("nuxt/app").NuxtError<unknown> | undefined>;
|
|
14
|
+
/** A page of the published entries of a collection, newest first. */
|
|
15
|
+
export declare function useHollwareEntries(collection: MaybeRefOrGetter<string>, options?: MaybeRefOrGetter<{
|
|
16
|
+
locale?: string;
|
|
17
|
+
tag?: string;
|
|
18
|
+
limit?: number;
|
|
19
|
+
cursor?: string;
|
|
20
|
+
}>,
|
|
21
|
+
/** `lazy: true` renders without waiting for the answer, as `useFetch` does. */
|
|
22
|
+
fetching?: {
|
|
23
|
+
lazy?: boolean;
|
|
24
|
+
}): import("nuxt/app").AsyncData<{
|
|
25
|
+
outcome: 'ok';
|
|
26
|
+
entries: PageEntry[];
|
|
27
|
+
nextCursor: string | null;
|
|
28
|
+
} | undefined, import("nuxt/app").NuxtError<unknown> | undefined>;
|
|
29
|
+
/** The entries of a translation group, one per locale. */
|
|
30
|
+
export declare function useHollwareTranslations(collection: MaybeRefOrGetter<string>, group: MaybeRefOrGetter<string>): import("nuxt/app").AsyncData<{
|
|
31
|
+
outcome: 'ok';
|
|
32
|
+
entries: PageEntry[];
|
|
33
|
+
} | undefined, import("nuxt/app").NuxtError<unknown> | undefined>;
|
|
34
|
+
/** The site: its locales, its collections and their schemas. */
|
|
35
|
+
export declare function useHollwareSite(): import("nuxt/app").AsyncData<{
|
|
36
|
+
outcome: "ok";
|
|
37
|
+
site: {
|
|
38
|
+
key: string;
|
|
39
|
+
locales: string[];
|
|
40
|
+
defaultLocale: string;
|
|
41
|
+
styleGuide: string | null;
|
|
42
|
+
collections: {
|
|
43
|
+
name: string;
|
|
44
|
+
schema: Record<string, unknown>;
|
|
45
|
+
routes: Record<string, string>;
|
|
46
|
+
translationGroupField: string | null;
|
|
47
|
+
tagsField: string | null;
|
|
48
|
+
sortByField: string | null;
|
|
49
|
+
components: {
|
|
50
|
+
name: string;
|
|
51
|
+
description: string | null;
|
|
52
|
+
example: string | null;
|
|
53
|
+
props: Record<string, unknown>;
|
|
54
|
+
}[];
|
|
55
|
+
contracts: {
|
|
56
|
+
id: string;
|
|
57
|
+
severity: "error" | "warning";
|
|
58
|
+
phases: ("publish" | "write")[];
|
|
59
|
+
description: string;
|
|
60
|
+
}[];
|
|
61
|
+
maxMarkdownBytes: number;
|
|
62
|
+
styleGuide: string | null;
|
|
63
|
+
}[];
|
|
64
|
+
};
|
|
65
|
+
} | undefined, import("nuxt/app").NuxtError<unknown> | undefined>;
|
|
66
|
+
//#endregion
|
|
67
|
+
export type { PageEntry };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useFetch } from "nuxt/app";
|
|
2
|
+
import { computed, toValue } from "vue";
|
|
3
|
+
//#region src/runtime/composables.ts
|
|
4
|
+
/**
|
|
5
|
+
* The published content of the site, for a page: each reads the site's own `/_hollware/` route,
|
|
6
|
+
* which reads Hollware on the server, so no token reaches the browser. They are `useFetch`, so the
|
|
7
|
+
* page renders on the server with the answer and the browser does not ask again.
|
|
8
|
+
*/
|
|
9
|
+
/** An entry, with its Comark document; `data` is null while it loads, `error` a 404 when it is not published. */
|
|
10
|
+
function useHollwareEntry(collection, locale, slug) {
|
|
11
|
+
const path = computed(() => `/_hollware/entry/${encodeURIComponent(toValue(collection))}/${encodeURIComponent(toValue(locale))}/${encodeURIComponent(toValue(slug))}`);
|
|
12
|
+
return useFetch(path, { key: path.value });
|
|
13
|
+
}
|
|
14
|
+
/** A page of the published entries of a collection, newest first. */
|
|
15
|
+
function useHollwareEntries(collection, options = {}, fetching = {}) {
|
|
16
|
+
const path = computed(() => `/_hollware/entries/${encodeURIComponent(toValue(collection))}`);
|
|
17
|
+
return useFetch(path, {
|
|
18
|
+
query: computed(() => toValue(options)),
|
|
19
|
+
...fetching
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** The entries of a translation group, one per locale. */
|
|
23
|
+
function useHollwareTranslations(collection, group) {
|
|
24
|
+
const path = computed(() => `/_hollware/translations/${encodeURIComponent(toValue(collection))}/${encodeURIComponent(toValue(group))}`);
|
|
25
|
+
return useFetch(path);
|
|
26
|
+
}
|
|
27
|
+
/** The site: its locales, its collections and their schemas. */
|
|
28
|
+
function useHollwareSite() {
|
|
29
|
+
return useFetch("/_hollware/site");
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { useHollwareEntries, useHollwareEntry, useHollwareSite, useHollwareTranslations };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useHead } from "nuxt/app";
|
|
2
|
+
//#region src/runtime/generator.ts
|
|
3
|
+
var generator_default = defineNuxtPlugin(() => {
|
|
4
|
+
useHead({ meta: [{
|
|
5
|
+
name: "generator",
|
|
6
|
+
content: "Hollware"
|
|
7
|
+
}] });
|
|
8
|
+
});
|
|
9
|
+
//#endregion
|
|
10
|
+
export { generator_default as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { H3Event } from "h3";
|
|
2
|
+
//#region src/runtime/server/answer.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Hollware's answer as the site's own: a `not_found` outcome is a 404, a refusal of the read API
|
|
5
|
+
* keeps its status, and the rest is the answer. Pages revalidate it: it is published content, and
|
|
6
|
+
* a publication purges nothing on the site's side.
|
|
7
|
+
*/
|
|
8
|
+
export declare function answer<Value extends {
|
|
9
|
+
outcome: string;
|
|
10
|
+
}>(event: H3Event, read: () => Promise<Value>): Promise<Value>;
|
|
11
|
+
/**
|
|
12
|
+
* An entry for a page: its verdict, its revision and its last publication stay on the server, as
|
|
13
|
+
* the page sends what it read to the browser in its payload.
|
|
14
|
+
*/
|
|
15
|
+
export declare function forPage(entry: unknown): Record<string, unknown> | undefined;
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HollwareClientError } from "@hollware/client";
|
|
2
|
+
import { createError, setResponseHeader } from "h3";
|
|
3
|
+
//#region src/runtime/server/answer.ts
|
|
4
|
+
/**
|
|
5
|
+
* Hollware's answer as the site's own: a `not_found` outcome is a 404, a refusal of the read API
|
|
6
|
+
* keeps its status, and the rest is the answer. Pages revalidate it: it is published content, and
|
|
7
|
+
* a publication purges nothing on the site's side.
|
|
8
|
+
*/
|
|
9
|
+
async function answer(event, read) {
|
|
10
|
+
let value;
|
|
11
|
+
try {
|
|
12
|
+
value = await read();
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error instanceof HollwareClientError) throw createError({
|
|
15
|
+
statusCode: error.status,
|
|
16
|
+
statusMessage: error.message
|
|
17
|
+
});
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
if (value.outcome === "not_found") throw createError({
|
|
21
|
+
statusCode: 404,
|
|
22
|
+
statusMessage: "Not found in Hollware"
|
|
23
|
+
});
|
|
24
|
+
setResponseHeader(event, "cache-control", "no-cache");
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/** The fields of an entry that a page shows: what a reader sees, and not how it was checked. */
|
|
28
|
+
const PUBLIC_FIELDS = [
|
|
29
|
+
"id",
|
|
30
|
+
"collection",
|
|
31
|
+
"locale",
|
|
32
|
+
"slug",
|
|
33
|
+
"translationGroup",
|
|
34
|
+
"frontmatter",
|
|
35
|
+
"tags",
|
|
36
|
+
"publishedAt",
|
|
37
|
+
"updatedAt",
|
|
38
|
+
"document"
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* An entry for a page: its verdict, its revision and its last publication stay on the server, as
|
|
42
|
+
* the page sends what it read to the browser in its payload.
|
|
43
|
+
*/
|
|
44
|
+
function forPage(entry) {
|
|
45
|
+
if (typeof entry !== "object" || entry === null) return void 0;
|
|
46
|
+
return Object.fromEntries(PUBLIC_FIELDS.filter((field) => field in entry).map((field) => [field, Reflect.get(entry, field)]));
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { answer, forPage };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HollwareReader } from "@hollware/client";
|
|
2
|
+
import { H3Event } from "h3";
|
|
3
|
+
//#region src/runtime/server/reader.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The site's reader of Hollware for a request: the service binding when the Worker has it, else
|
|
6
|
+
* HTTP with the URL and the read token of the config. A site with neither gets a 500 that says
|
|
7
|
+
* which to set.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useHollware(event: H3Event): {
|
|
10
|
+
site: string;
|
|
11
|
+
reader: HollwareReader;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createClient } from "@hollware/client";
|
|
2
|
+
import { createError } from "h3";
|
|
3
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
4
|
+
//#region src/runtime/server/reader.ts
|
|
5
|
+
function isReader(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && "getEntry" in value;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The site's reader of Hollware for a request: the service binding when the Worker has it, else
|
|
10
|
+
* HTTP with the URL and the read token of the config. A site with neither gets a 500 that says
|
|
11
|
+
* which to set.
|
|
12
|
+
*/
|
|
13
|
+
function useHollware(event) {
|
|
14
|
+
const config = useRuntimeConfig(event)["hollware"];
|
|
15
|
+
const env = event.context["cloudflare"]?.env;
|
|
16
|
+
const binding = typeof env === "object" && env !== null ? Reflect.get(env, config.binding) : void 0;
|
|
17
|
+
if (isReader(binding)) return {
|
|
18
|
+
site: config.site,
|
|
19
|
+
reader: createClient({ binding })
|
|
20
|
+
};
|
|
21
|
+
if (config.url !== "" && config.token !== "") return {
|
|
22
|
+
site: config.site,
|
|
23
|
+
reader: createClient({
|
|
24
|
+
url: config.url,
|
|
25
|
+
token: config.token
|
|
26
|
+
})
|
|
27
|
+
};
|
|
28
|
+
throw createError({
|
|
29
|
+
statusCode: 500,
|
|
30
|
+
statusMessage: `Hollware: the Worker has no binding ${config.binding}, and hollware.url with a read token (NUXT_HOLLWARE_TOKEN) is not set.`
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { useHollware };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/runtime/server/routes/entries.d.ts
|
|
2
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
3
|
+
outcome: "ok";
|
|
4
|
+
entries: (Record<string, unknown> | undefined)[];
|
|
5
|
+
nextCursor: string | null;
|
|
6
|
+
}>>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { _default as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { answer, forPage } from "../answer.mjs";
|
|
2
|
+
import { useHollware } from "../reader.mjs";
|
|
3
|
+
import { defineEventHandler, getQuery, getRouterParam } from "h3";
|
|
4
|
+
//#region src/runtime/server/routes/entries.ts
|
|
5
|
+
const text = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
6
|
+
var entries_default = defineEventHandler(async (event) => {
|
|
7
|
+
const { site, reader } = useHollware(event);
|
|
8
|
+
const query = getQuery(event);
|
|
9
|
+
const [locale, tag, cursor, limit] = [
|
|
10
|
+
"locale",
|
|
11
|
+
"tag",
|
|
12
|
+
"cursor",
|
|
13
|
+
"limit"
|
|
14
|
+
].map((key) => text(query[key]));
|
|
15
|
+
const options = {
|
|
16
|
+
...locale === void 0 ? {} : { locale },
|
|
17
|
+
...tag === void 0 ? {} : { tag },
|
|
18
|
+
...cursor === void 0 ? {} : { cursor },
|
|
19
|
+
...limit === void 0 ? {} : { limit: Number(limit) }
|
|
20
|
+
};
|
|
21
|
+
const page = await answer(event, () => reader.listEntries(site, getRouterParam(event, "collection") ?? "", options));
|
|
22
|
+
return {
|
|
23
|
+
outcome: page.outcome,
|
|
24
|
+
entries: page.entries.map(forPage),
|
|
25
|
+
nextCursor: page.nextCursor
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
export { entries_default as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/runtime/server/routes/entry.d.ts
|
|
2
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
3
|
+
outcome: "not_found" | "ok";
|
|
4
|
+
entry: Record<string, unknown> | undefined;
|
|
5
|
+
}>>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { answer, forPage } from "../answer.mjs";
|
|
2
|
+
import { useHollware } from "../reader.mjs";
|
|
3
|
+
import { defineEventHandler, getRouterParam } from "h3";
|
|
4
|
+
//#region src/runtime/server/routes/entry.ts
|
|
5
|
+
var entry_default = defineEventHandler(async (event) => {
|
|
6
|
+
const { site, reader } = useHollware(event);
|
|
7
|
+
const param = (name) => getRouterParam(event, name) ?? "";
|
|
8
|
+
const found = await answer(event, () => reader.getEntry(site, param("collection"), param("slug"), param("locale"), { formats: ["document"] }));
|
|
9
|
+
return {
|
|
10
|
+
outcome: found.outcome,
|
|
11
|
+
entry: forPage(found.entry)
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
15
|
+
export { entry_default as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/runtime/server/routes/site.d.ts
|
|
2
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
3
|
+
outcome: "ok";
|
|
4
|
+
site: {
|
|
5
|
+
key: string;
|
|
6
|
+
locales: string[];
|
|
7
|
+
defaultLocale: string;
|
|
8
|
+
styleGuide: string | null;
|
|
9
|
+
collections: {
|
|
10
|
+
name: string;
|
|
11
|
+
schema: Record<string, unknown>;
|
|
12
|
+
routes: Record<string, string>;
|
|
13
|
+
translationGroupField: string | null;
|
|
14
|
+
tagsField: string | null;
|
|
15
|
+
sortByField: string | null;
|
|
16
|
+
components: {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string | null;
|
|
19
|
+
example: string | null;
|
|
20
|
+
props: Record<string, unknown>;
|
|
21
|
+
}[];
|
|
22
|
+
contracts: {
|
|
23
|
+
id: string;
|
|
24
|
+
severity: "error" | "warning";
|
|
25
|
+
phases: ("publish" | "write")[];
|
|
26
|
+
description: string;
|
|
27
|
+
}[];
|
|
28
|
+
maxMarkdownBytes: number;
|
|
29
|
+
styleGuide: string | null;
|
|
30
|
+
}[];
|
|
31
|
+
};
|
|
32
|
+
}>>;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { _default as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { answer } from "../answer.mjs";
|
|
2
|
+
import { useHollware } from "../reader.mjs";
|
|
3
|
+
import { defineEventHandler } from "h3";
|
|
4
|
+
//#region src/runtime/server/routes/site.ts
|
|
5
|
+
var site_default = defineEventHandler((event) => {
|
|
6
|
+
const { site, reader } = useHollware(event);
|
|
7
|
+
return answer(event, () => reader.describeSite(site));
|
|
8
|
+
});
|
|
9
|
+
//#endregion
|
|
10
|
+
export { site_default as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/runtime/server/routes/translations.d.ts
|
|
2
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
|
|
3
|
+
outcome: "not_found" | "ok";
|
|
4
|
+
entries: (Record<string, unknown> | undefined)[];
|
|
5
|
+
}>>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { _default as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { answer, forPage } from "../answer.mjs";
|
|
2
|
+
import { useHollware } from "../reader.mjs";
|
|
3
|
+
import { defineEventHandler, getRouterParam } from "h3";
|
|
4
|
+
//#region src/runtime/server/routes/translations.ts
|
|
5
|
+
var translations_default = defineEventHandler(async (event) => {
|
|
6
|
+
const { site, reader } = useHollware(event);
|
|
7
|
+
const group = await answer(event, () => reader.getTranslations(site, getRouterParam(event, "collection") ?? "", getRouterParam(event, "group") ?? ""));
|
|
8
|
+
return {
|
|
9
|
+
outcome: group.outcome,
|
|
10
|
+
entries: (group.entries ?? []).map(forPage)
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
//#endregion
|
|
14
|
+
export { translations_default as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/runtime/types.d.ts
|
|
2
|
+
/** An entry as a page of the site gets it: what a reader sees, and how to render it. */
|
|
3
|
+
export interface PageEntry {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly collection: string;
|
|
6
|
+
readonly locale: string;
|
|
7
|
+
readonly slug: string;
|
|
8
|
+
readonly translationGroup: string | null;
|
|
9
|
+
readonly frontmatter: Record<string, unknown>;
|
|
10
|
+
readonly tags: readonly string[];
|
|
11
|
+
readonly publishedAt: string | null;
|
|
12
|
+
readonly updatedAt: string;
|
|
13
|
+
/** The Comark document of the entry: only an entry read alone has it. */
|
|
14
|
+
readonly document?: unknown;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hollware/nuxt",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Read Hollware from a Nuxt site, over a service binding or HTTP.",
|
|
5
|
+
"homepage": "https://hollware.com",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/hollware/hollware/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/hollware/hollware.git",
|
|
13
|
+
"directory": "packages/nuxt"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public",
|
|
28
|
+
"provenance": true
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@comark/vue": "0.7.0",
|
|
32
|
+
"@hollware/client": "0.4.0",
|
|
33
|
+
"@nuxt/kit": "4.6.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "24.19.2",
|
|
37
|
+
"h3": "1.15.11",
|
|
38
|
+
"nitropack": "2.13.4",
|
|
39
|
+
"nuxt": "4.6.1",
|
|
40
|
+
"publint": "0.3.25",
|
|
41
|
+
"typescript": "7.0.2",
|
|
42
|
+
"vite-plus": "1.1.0",
|
|
43
|
+
"vue": "3.5.44"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"h3": "^1.15.0",
|
|
47
|
+
"nitropack": "^2.13.0",
|
|
48
|
+
"nuxt": "^4.6.0",
|
|
49
|
+
"vue": "^3.5.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=24.11.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "vp pack",
|
|
56
|
+
"test": "vp test",
|
|
57
|
+
"publint": "publint --strict"
|
|
58
|
+
}
|
|
6
59
|
}
|