@trypattern/sdk 0.1.14 → 0.1.15
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/README.md +1 -1
- package/dist/server/pages.d.ts +2 -0
- package/dist/server/pages.js +7 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ email, phone, address, notes, status }` with `status` `requested`, `accepted`, `
|
|
|
117
117
|
shows the live photos without storing them. With
|
|
118
118
|
`pages` (`definePages(tables, { '/': head, '/items/:itemId': { head, paths } })` in
|
|
119
119
|
`server/pages.ts`) it renders the `<head>` of public pages: each `head` reads tables anyone may
|
|
120
|
-
read (`rows`, `row`, `photoUrl`) and returns `{ title, description, image, hero, jsonLd, data }`
|
|
120
|
+
read (`rows`, `row`, `photoUrl`), and `appTitle()` gives the site's name as the owner set it, and returns `{ title, description, image, hero, jsonLd, data }`
|
|
121
121
|
(or `null` for a 404). The Worker puts the title, description, canonical link, `og:*` (the image
|
|
122
122
|
at 1200×630 with `fit=cover`), `twitter:card`, JSON-LD, a preload of the `hero` with `Image`'s
|
|
123
123
|
srcset, and `data` as `<script type="application/json" id="pattern-data">` into the built
|
package/dist/server/pages.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type PageRequest<Group extends Tables> = {
|
|
|
14
14
|
rows: <Name extends ReadableName<Group>>(table: Name) => Promise<readonly Row<Group[Name]>[]>;
|
|
15
15
|
row: <Name extends ReadableName<Group>>(table: Name, id: string) => Promise<Row<Group[Name]> | undefined>;
|
|
16
16
|
photoUrl: (image: MediaImage) => string;
|
|
17
|
+
appTitle: () => Promise<string>;
|
|
17
18
|
};
|
|
18
19
|
export type PageHero = {
|
|
19
20
|
image: MediaImage;
|
|
@@ -49,6 +50,7 @@ type AnyRequest = {
|
|
|
49
50
|
rows: (table: string) => Promise<readonly unknown[]>;
|
|
50
51
|
row: (table: string, id: string) => Promise<unknown>;
|
|
51
52
|
photoUrl: (image: MediaImage) => string;
|
|
53
|
+
appTitle: () => Promise<string>;
|
|
52
54
|
};
|
|
53
55
|
type PageRoute = {
|
|
54
56
|
pattern: string;
|
package/dist/server/pages.js
CHANGED
|
@@ -71,6 +71,7 @@ function readableTable(pages, name) {
|
|
|
71
71
|
function requestFor(c, pages, params) {
|
|
72
72
|
const url = new URL(c.req.url);
|
|
73
73
|
const read = new Map();
|
|
74
|
+
let title;
|
|
74
75
|
return {
|
|
75
76
|
url,
|
|
76
77
|
params,
|
|
@@ -81,7 +82,11 @@ function requestFor(c, pages, params) {
|
|
|
81
82
|
return found;
|
|
82
83
|
},
|
|
83
84
|
row: (name, id) => readRow(c.env.DB, readableTable(pages, name), id),
|
|
84
|
-
photoUrl: (image) => `${url.origin}${mediaPath(image.key)}
|
|
85
|
+
photoUrl: (image) => `${url.origin}${mediaPath(image.key)}`,
|
|
86
|
+
appTitle: () => {
|
|
87
|
+
title ??= readTitle(c.env.DB);
|
|
88
|
+
return title;
|
|
89
|
+
}
|
|
85
90
|
};
|
|
86
91
|
}
|
|
87
92
|
function escapeHtml(text) {
|
|
@@ -217,7 +222,7 @@ export async function renderPage(c, pages, route, params) {
|
|
|
217
222
|
try {
|
|
218
223
|
head = await route.head(request);
|
|
219
224
|
if (head !== null) {
|
|
220
|
-
tags = headTags(pages, request.url, await
|
|
225
|
+
tags = headTags(pages, request.url, await request.appTitle(), head);
|
|
221
226
|
}
|
|
222
227
|
}
|
|
223
228
|
catch (error) {
|