@sevenfold/setto-client 0.37.1 → 0.39.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/dist/modules/chat/SettoChat.d.ts +37 -1
- package/dist/modules/chat/translation-caption.d.ts +56 -0
- package/dist/setto-client.js +169 -14
- package/dist/setto-client.js.map +1 -1
- package/dist/vite/plugin.d.ts +13 -4
- package/dist/vite/static.d.ts +62 -3
- package/dist/vite.js +156 -26
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/vite/plugin.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import type { Plugin } from 'vite';
|
|
|
2
2
|
import { type BlogFrontmatter } from '../blog/contract.js';
|
|
3
3
|
export interface SettoBlogPluginOptions {
|
|
4
4
|
/**
|
|
5
|
-
* The site's public address, for canonical links, `og:url`,
|
|
6
|
-
* sitemap. Otherwise `
|
|
7
|
-
*
|
|
5
|
+
* The site's public address, for canonical links, `og:url`, `og:image`,
|
|
6
|
+
* RSS and the sitemap. Otherwise `siteUrl` in `setto.config.json` (which
|
|
7
|
+
* setto-server stamps on every publish), then `SETTO_SITE_URL`, then
|
|
8
|
+
* Vercel's `VERCEL_PROJECT_PRODUCTION_URL`, then the first address in
|
|
8
9
|
* `public/sitemap.xml`. Without any, pages still get their own head, only
|
|
9
|
-
*
|
|
10
|
+
* without addresses or pictures, and no feed.
|
|
10
11
|
*/
|
|
11
12
|
siteUrl?: string;
|
|
12
13
|
/** Hosts a post's images may come from. Setto's media store by default. */
|
|
@@ -28,5 +29,13 @@ export declare function settoBlog(options?: SettoBlogPluginOptions): Plugin;
|
|
|
28
29
|
/** Exported for tests: everything `writeBundle` does, given a built `outDir`. */
|
|
29
30
|
export declare function writeStaticFiles(root: string, outDir: string, loaded: readonly LoadedPost[], options?: SettoBlogPluginOptions): {
|
|
30
31
|
written: string[];
|
|
32
|
+
warnings: string[];
|
|
33
|
+
siteUrl: string | null;
|
|
31
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* The site's own address, first answer wins: the plugin option, `siteUrl` in
|
|
37
|
+
* `setto.config.json`, `SETTO_SITE_URL`, Vercel's production hostname, the
|
|
38
|
+
* sitemap's first address. Only an absolute http(s) origin counts.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveSiteUrl(options: Pick<SettoBlogPluginOptions, 'siteUrl'>, configured: unknown, sitemap: string | null): string | null;
|
|
32
41
|
export {};
|
package/dist/vite/static.d.ts
CHANGED
|
@@ -21,6 +21,10 @@ export interface HeadMeta {
|
|
|
21
21
|
url?: string;
|
|
22
22
|
/** Absolute. */
|
|
23
23
|
image?: string;
|
|
24
|
+
/** Pixels, when known: a crawler can lay out the card before it fetches the picture. */
|
|
25
|
+
imageWidth?: number;
|
|
26
|
+
imageHeight?: number;
|
|
27
|
+
imageAlt?: string;
|
|
24
28
|
type: 'article' | 'website';
|
|
25
29
|
locale: string;
|
|
26
30
|
siteName?: string;
|
|
@@ -39,24 +43,79 @@ export declare const escapeXml: (value: string) => string;
|
|
|
39
43
|
* canonical address, Open Graph and Twitter tags and structured data. Any of
|
|
40
44
|
* those the front page already had are taken out first, so a crawler never
|
|
41
45
|
* reads two answers.
|
|
46
|
+
*
|
|
47
|
+
* `social` is for the front page itself: only the title, description,
|
|
48
|
+
* canonical and share tags are replaced. Its structured data, feed link and
|
|
49
|
+
* language versions are what its author wrote, and stay.
|
|
42
50
|
*/
|
|
43
|
-
export declare function withHead(indexHtml: string, meta: HeadMeta): string;
|
|
51
|
+
export declare function withHead(indexHtml: string, meta: HeadMeta, scope?: 'page' | 'social'): string;
|
|
44
52
|
/** `https://x.no` + `/blogg/a` — or the path alone when the address is unknown. */
|
|
45
53
|
export declare function absolute(siteUrl: string | null, pathOrUrl: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* `https://kafeen.no` from `https://kafeen.no/` or `kafeen.no`-less junk:
|
|
56
|
+
* an http(s) origin, or null. A share tag with a relative address is worse
|
|
57
|
+
* than none, so anything that is not one is refused rather than guessed at.
|
|
58
|
+
*/
|
|
59
|
+
export declare function normaliseSiteUrl(value: unknown): string | null;
|
|
60
|
+
/** What a built `index.html` already says about itself. */
|
|
61
|
+
export declare function readHead(source: string): {
|
|
62
|
+
title?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
ogTitle?: string;
|
|
65
|
+
ogDescription?: string;
|
|
66
|
+
ogImage?: string;
|
|
67
|
+
ogImageAlt?: string;
|
|
68
|
+
};
|
|
69
|
+
/** Width and height of a JPEG or PNG from its bytes, or null. */
|
|
70
|
+
export declare function imageSize(bytes: Uint8Array): {
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
} | null;
|
|
74
|
+
/** Where the site's share picture lives: `public/og.jpg`, served at `/og.jpg`. */
|
|
75
|
+
export declare const SHARE_IMAGE_PATH = "/og.jpg";
|
|
76
|
+
export interface FrontPageHeadInput {
|
|
77
|
+
/** The built `index.html`. */
|
|
78
|
+
html: string;
|
|
79
|
+
siteUrl: string | null;
|
|
80
|
+
siteName?: string;
|
|
81
|
+
locale: string;
|
|
82
|
+
/** The site's own share picture, when the build has one. */
|
|
83
|
+
shareImage?: {
|
|
84
|
+
path: string;
|
|
85
|
+
width?: number;
|
|
86
|
+
height?: number;
|
|
87
|
+
version?: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The front page's share head, from what its `index.html` says.
|
|
92
|
+
*
|
|
93
|
+
* The `<title>` and `<meta name="description">` the site was built with are
|
|
94
|
+
* the source: they are what Google shows, and a share card that said
|
|
95
|
+
* something else would be a second answer. Open Graph and Twitter tags are
|
|
96
|
+
* derived from them, never the other way round. The picture is the site's
|
|
97
|
+
* `og.jpg` when it has one, else an `og:image` the page already carried; an
|
|
98
|
+
* address is written only when it is absolute.
|
|
99
|
+
*/
|
|
100
|
+
export declare function frontPageHead({ html, siteUrl, siteName, locale, shareImage }: FrontPageHeadInput): HeadMeta | null;
|
|
46
101
|
export interface PostHeadInput {
|
|
47
102
|
post: BlogFrontmatter;
|
|
48
103
|
blogPath: string;
|
|
49
104
|
siteUrl: string | null;
|
|
50
105
|
siteName?: string;
|
|
106
|
+
/** Absolute; for a post without a cover of its own. */
|
|
107
|
+
fallbackImage?: string;
|
|
51
108
|
}
|
|
52
|
-
export declare function postHead({ post, blogPath, siteUrl, siteName }: PostHeadInput): HeadMeta;
|
|
53
|
-
export declare function indexHead({ title, description, blogPath, siteUrl, siteName, locale, }: {
|
|
109
|
+
export declare function postHead({ post, blogPath, siteUrl, siteName, fallbackImage }: PostHeadInput): HeadMeta;
|
|
110
|
+
export declare function indexHead({ title, description, blogPath, siteUrl, siteName, locale, image, }: {
|
|
54
111
|
title: string;
|
|
55
112
|
description: string;
|
|
56
113
|
blogPath: string;
|
|
57
114
|
siteUrl: string | null;
|
|
58
115
|
siteName?: string;
|
|
59
116
|
locale: string;
|
|
117
|
+
/** Absolute; the site's own share picture. */
|
|
118
|
+
image?: string;
|
|
60
119
|
}): HeadMeta;
|
|
61
120
|
export declare function rssFeed({ posts, blogPath, siteUrl, title, description, locale, }: {
|
|
62
121
|
posts: readonly BlogFrontmatter[];
|
package/dist/vite.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync } from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { SETTO_MEDIA_HOST, BLOG_DIR, parseBlogPostPath, validateBlogPost } from "./blog.js";
|
|
@@ -190,13 +191,18 @@ function htmlLang(locale) {
|
|
|
190
191
|
return locale === "no" || locale === "nb" ? "nb-NO" : locale === "nn" ? "nn-NO" : locale;
|
|
191
192
|
}
|
|
192
193
|
const OG_LOCALE = { no: "nb_NO", nb: "nb_NO", nn: "nn_NO", en: "en_GB", sv: "sv_SE", da: "da_DK", de: "de_DE" };
|
|
193
|
-
function withHead(indexHtml, meta) {
|
|
194
|
-
|
|
194
|
+
function withHead(indexHtml, meta, scope = "page") {
|
|
195
|
+
const comments = [];
|
|
196
|
+
let html = indexHtml.replace(/<!--[\s\S]*?-->/g, (comment) => `<!--setto-comment:${comments.push(comment) - 1}-->`).replace(/<title>[\s\S]*?<\/title>\s*/gi, "").replace(/<meta\s+name=["']description["'][^>]*>\s*/gi, "").replace(/<meta\s+(?:property|name)=["'](?:og|twitter|article):[^"']*["'][^>]*>\s*/gi, "").replace(/<link\s+rel=["']canonical["'][^>]*>\s*/gi, "");
|
|
197
|
+
if (scope === "page") {
|
|
198
|
+
html = html.replace(/<link\s+rel=["']alternate["']\s+type=["']application\/rss\+xml["'][^>]*>\s*/gi, "").replace(/<link\b(?=[^>]*\bhreflang=)[^>]*>\s*/gi, "").replace(/<script\s+type=["']application\/ld\+json["'][^>]*>[\s\S]*?<\/script>\s*/gi, "");
|
|
199
|
+
}
|
|
200
|
+
html = html.replace(/<!--setto-comment:(\d+)-->/g, (_, i) => comments[Number(i)] ?? "");
|
|
195
201
|
const lang = escapeAttr(htmlLang(meta.locale));
|
|
196
202
|
html = /<html\b[^>]*\blang=/i.test(html) ? html.replace(/(<html\b[^>]*\blang=)(["'])[^"']*\2/i, `$1"${lang}"`) : html.replace(/<html\b/i, `<html lang="${lang}"`);
|
|
197
203
|
const tags = [
|
|
198
204
|
`<title>${escapeAttr(meta.title)}</title>`,
|
|
199
|
-
`<meta name="description" content="${escapeAttr(meta.description)}"
|
|
205
|
+
meta.description ? `<meta name="description" content="${escapeAttr(meta.description)}" />` : "",
|
|
200
206
|
meta.url ? `<link rel="canonical" href="${escapeAttr(meta.url)}" />` : "",
|
|
201
207
|
...(meta.alternates ?? []).map(
|
|
202
208
|
(a) => `<link rel="alternate" hreflang="${escapeAttr(a.hreflang === "x-default" ? a.hreflang : htmlLang(a.hreflang))}" href="${escapeAttr(a.href)}" />`
|
|
@@ -204,16 +210,20 @@ function withHead(indexHtml, meta) {
|
|
|
204
210
|
meta.rssUrl ? `<link rel="alternate" type="application/rss+xml" title="${escapeAttr(meta.siteName ?? meta.title)}" href="${escapeAttr(meta.rssUrl)}" />` : "",
|
|
205
211
|
`<meta property="og:type" content="${meta.type}" />`,
|
|
206
212
|
`<meta property="og:title" content="${escapeAttr(meta.title)}" />`,
|
|
207
|
-
`<meta property="og:description" content="${escapeAttr(meta.description)}"
|
|
213
|
+
meta.description ? `<meta property="og:description" content="${escapeAttr(meta.description)}" />` : "",
|
|
208
214
|
meta.url ? `<meta property="og:url" content="${escapeAttr(meta.url)}" />` : "",
|
|
209
215
|
meta.image ? `<meta property="og:image" content="${escapeAttr(meta.image)}" />` : "",
|
|
216
|
+
meta.image && meta.imageWidth ? `<meta property="og:image:width" content="${meta.imageWidth}" />` : "",
|
|
217
|
+
meta.image && meta.imageHeight ? `<meta property="og:image:height" content="${meta.imageHeight}" />` : "",
|
|
218
|
+
meta.image && meta.imageAlt ? `<meta property="og:image:alt" content="${escapeAttr(meta.imageAlt)}" />` : "",
|
|
210
219
|
meta.siteName ? `<meta property="og:site_name" content="${escapeAttr(meta.siteName)}" />` : "",
|
|
211
220
|
`<meta property="og:locale" content="${OG_LOCALE[meta.locale] ?? meta.locale}" />`,
|
|
212
221
|
meta.publishedTime ? `<meta property="article:published_time" content="${escapeAttr(meta.publishedTime)}" />` : "",
|
|
213
222
|
`<meta name="twitter:card" content="${meta.image ? "summary_large_image" : "summary"}" />`,
|
|
214
223
|
`<meta name="twitter:title" content="${escapeAttr(meta.title)}" />`,
|
|
215
|
-
`<meta name="twitter:description" content="${escapeAttr(meta.description)}"
|
|
224
|
+
meta.description ? `<meta name="twitter:description" content="${escapeAttr(meta.description)}" />` : "",
|
|
216
225
|
meta.image ? `<meta name="twitter:image" content="${escapeAttr(meta.image)}" />` : "",
|
|
226
|
+
meta.image && meta.imageAlt ? `<meta name="twitter:image:alt" content="${escapeAttr(meta.imageAlt)}" />` : "",
|
|
217
227
|
meta.jsonLd ? `<script type="application/ld+json">${safeJson(meta.jsonLd)}<\/script>` : ""
|
|
218
228
|
].filter(Boolean);
|
|
219
229
|
return html.replace(/<\/head>/i, ` ${tags.join("\n ")}
|
|
@@ -223,10 +233,95 @@ function absolute(siteUrl, pathOrUrl) {
|
|
|
223
233
|
if (/^https?:\/\//i.test(pathOrUrl)) return pathOrUrl;
|
|
224
234
|
return siteUrl ? `${siteUrl.replace(/\/+$/, "")}${pathOrUrl}` : pathOrUrl;
|
|
225
235
|
}
|
|
226
|
-
function
|
|
236
|
+
function normaliseSiteUrl(value) {
|
|
237
|
+
if (typeof value !== "string" || !/^https?:\/\//i.test(value.trim())) return null;
|
|
238
|
+
try {
|
|
239
|
+
return new URL(value.trim()).origin;
|
|
240
|
+
} catch {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const decodeEntities = (value) => value.replace(/"/g, '"').replace(/�*39;|�*27;|'/gi, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
245
|
+
function metaContent(html, attr, key) {
|
|
246
|
+
for (const tag of html.match(/<meta\b[^>]*>/gi) ?? []) {
|
|
247
|
+
const named = new RegExp(`\\b${attr}\\s*=\\s*["']${key.replace(/[:.]/g, "\\$&")}["']`, "i").test(tag);
|
|
248
|
+
if (!named) continue;
|
|
249
|
+
const content = /\bcontent\s*=\s*(["'])([\s\S]*?)\1/i.exec(tag)?.[2];
|
|
250
|
+
if (content !== void 0) return decodeEntities(content).trim();
|
|
251
|
+
}
|
|
252
|
+
return void 0;
|
|
253
|
+
}
|
|
254
|
+
function readHead(source) {
|
|
255
|
+
const html = source.replace(/<!--[\s\S]*?-->/g, "");
|
|
256
|
+
const title = /<title>([\s\S]*?)<\/title>/i.exec(html)?.[1];
|
|
257
|
+
return {
|
|
258
|
+
title: title ? decodeEntities(title).replace(/\s+/g, " ").trim() || void 0 : void 0,
|
|
259
|
+
description: metaContent(html, "name", "description") || void 0,
|
|
260
|
+
ogTitle: metaContent(html, "property", "og:title") || void 0,
|
|
261
|
+
ogDescription: metaContent(html, "property", "og:description") || void 0,
|
|
262
|
+
ogImage: metaContent(html, "property", "og:image") || void 0,
|
|
263
|
+
ogImageAlt: metaContent(html, "property", "og:image:alt") || void 0
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function imageSize(bytes) {
|
|
267
|
+
if (bytes.length >= 24 && bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71) {
|
|
268
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
269
|
+
return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
270
|
+
}
|
|
271
|
+
if (bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216) return null;
|
|
272
|
+
let i = 2;
|
|
273
|
+
while (i + 9 < bytes.length) {
|
|
274
|
+
if (bytes[i] !== 255) return null;
|
|
275
|
+
const marker = bytes[i + 1];
|
|
276
|
+
if (marker === 255) {
|
|
277
|
+
i += 1;
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const length = bytes[i + 2] << 8 | bytes[i + 3];
|
|
281
|
+
const isFrame = marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204;
|
|
282
|
+
if (isFrame) {
|
|
283
|
+
return { height: bytes[i + 5] << 8 | bytes[i + 6], width: bytes[i + 7] << 8 | bytes[i + 8] };
|
|
284
|
+
}
|
|
285
|
+
i += 2 + length;
|
|
286
|
+
}
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
const SHARE_IMAGE_PATH = "/og.jpg";
|
|
290
|
+
function frontPageHead({ html, siteUrl, siteName, locale, shareImage }) {
|
|
291
|
+
const found = readHead(html);
|
|
292
|
+
const title = found.title ?? found.ogTitle ?? siteName;
|
|
293
|
+
if (!title) return null;
|
|
294
|
+
const description = found.description ?? found.ogDescription ?? "";
|
|
295
|
+
let image;
|
|
296
|
+
let imageWidth;
|
|
297
|
+
let imageHeight;
|
|
298
|
+
if (shareImage && siteUrl) {
|
|
299
|
+
image = absolute(siteUrl, shareImage.version ? `${shareImage.path}?v=${shareImage.version}` : shareImage.path);
|
|
300
|
+
imageWidth = shareImage.width;
|
|
301
|
+
imageHeight = shareImage.height;
|
|
302
|
+
} else if (found.ogImage && /^https?:\/\//i.test(found.ogImage)) {
|
|
303
|
+
image = found.ogImage;
|
|
304
|
+
} else if (found.ogImage && siteUrl) {
|
|
305
|
+
image = absolute(siteUrl, `/${found.ogImage.replace(/^\.?\/+/, "")}`);
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
title,
|
|
309
|
+
description,
|
|
310
|
+
url: siteUrl ? `${siteUrl}/` : void 0,
|
|
311
|
+
image,
|
|
312
|
+
imageWidth,
|
|
313
|
+
imageHeight,
|
|
314
|
+
imageAlt: image ? found.ogImageAlt ?? title : void 0,
|
|
315
|
+
type: "website",
|
|
316
|
+
locale,
|
|
317
|
+
siteName
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function postHead({ post, blogPath, siteUrl, siteName, fallbackImage }) {
|
|
227
321
|
const path2 = `${blogPath}/${post.slug}`;
|
|
228
322
|
const url = siteUrl ? absolute(siteUrl, path2) : void 0;
|
|
229
|
-
const
|
|
323
|
+
const cover = post.cover ? absolute(siteUrl, post.cover) : void 0;
|
|
324
|
+
const image = cover && /^https?:\/\//i.test(cover) ? cover : fallbackImage ?? cover;
|
|
230
325
|
return {
|
|
231
326
|
title: siteName ? `${post.title} · ${siteName}` : post.title,
|
|
232
327
|
description: post.description,
|
|
@@ -257,13 +352,15 @@ function indexHead({
|
|
|
257
352
|
blogPath,
|
|
258
353
|
siteUrl,
|
|
259
354
|
siteName,
|
|
260
|
-
locale
|
|
355
|
+
locale,
|
|
356
|
+
image
|
|
261
357
|
}) {
|
|
262
358
|
const url = siteUrl ? absolute(siteUrl, blogPath) : void 0;
|
|
263
359
|
return {
|
|
264
360
|
title: siteName ? `${title} · ${siteName}` : title,
|
|
265
361
|
description,
|
|
266
362
|
url,
|
|
363
|
+
image,
|
|
267
364
|
type: "website",
|
|
268
365
|
locale,
|
|
269
366
|
siteName,
|
|
@@ -447,21 +544,17 @@ ${loaders}
|
|
|
447
544
|
sequential: true,
|
|
448
545
|
handler() {
|
|
449
546
|
if (config.command !== "build" || config.build.ssr) return;
|
|
450
|
-
writeStaticFiles(config.root, path.resolve(config.root, config.build.outDir), posts(), options);
|
|
547
|
+
const { warnings } = writeStaticFiles(config.root, path.resolve(config.root, config.build.outDir), posts(), options);
|
|
548
|
+
for (const warning of warnings) config.logger.warn(`[setto] ${warning}`);
|
|
451
549
|
}
|
|
452
550
|
}
|
|
453
551
|
};
|
|
454
552
|
}
|
|
455
553
|
function writeStaticFiles(root, outDir, loaded, options = {}) {
|
|
456
554
|
const written = [];
|
|
457
|
-
const
|
|
458
|
-
const parsed = manifestRaw ? parseManifest(manifestRaw) : null;
|
|
459
|
-
const blog = parsed?.ok ? blogPage(parsed.manifest) : null;
|
|
460
|
-
if (blog && (blog.page.hidden || blog.section.hidden)) return { written };
|
|
461
|
-
const blogPath = blog?.page.path ?? (options.blogPath ? normalisePath(options.blogPath) : null);
|
|
462
|
-
if (!blogPath || blogPath === "/") return { written };
|
|
555
|
+
const warnings = [];
|
|
463
556
|
const indexFile = path.join(outDir, "index.html");
|
|
464
|
-
if (!existsSync(indexFile)) return { written };
|
|
557
|
+
if (!existsSync(indexFile)) return { written, warnings, siteUrl: null };
|
|
465
558
|
const indexHtml = readFileSync(indexFile, "utf8");
|
|
466
559
|
const settoConfig = readJson(path.join(root, "setto.config.json")) ?? {};
|
|
467
560
|
const languages = settoConfig.languages?.length ? settoConfig.languages : ["no"];
|
|
@@ -469,19 +562,51 @@ function writeStaticFiles(root, outDir, loaded, options = {}) {
|
|
|
469
562
|
const siteName = settoConfig.displayName;
|
|
470
563
|
const sitemapFile = path.join(outDir, "sitemap.xml");
|
|
471
564
|
const sitemap = existsSync(sitemapFile) ? readFileSync(sitemapFile, "utf8") : null;
|
|
472
|
-
const
|
|
473
|
-
const siteUrl = options.siteUrl ?? process.env.SETTO_SITE_URL ?? (vercel ? `https://${vercel}` : null) ?? (sitemap ? originFromSitemap(sitemap) : null);
|
|
474
|
-
const posts = postsForLanguage(
|
|
475
|
-
loaded.map((p) => p.frontmatter),
|
|
476
|
-
language,
|
|
477
|
-
language
|
|
478
|
-
);
|
|
565
|
+
const siteUrl = resolveSiteUrl(options, settoConfig.siteUrl, sitemap);
|
|
479
566
|
const write = (relative, content) => {
|
|
480
567
|
const file = path.join(outDir, relative);
|
|
481
568
|
mkdirSync(path.dirname(file), { recursive: true });
|
|
482
569
|
writeFileSync(file, content);
|
|
483
570
|
written.push(relative.split(path.sep).join("/"));
|
|
484
571
|
};
|
|
572
|
+
const shareFile = path.join(outDir, SHARE_IMAGE_PATH.slice(1));
|
|
573
|
+
let shareImageUrl;
|
|
574
|
+
let shareImage;
|
|
575
|
+
if (existsSync(shareFile)) {
|
|
576
|
+
const bytes = readFileSync(shareFile);
|
|
577
|
+
shareImage = {
|
|
578
|
+
path: SHARE_IMAGE_PATH,
|
|
579
|
+
...imageSize(bytes) ?? {},
|
|
580
|
+
// A new picture is a new address, or a chat app keeps showing the old one.
|
|
581
|
+
version: createHash("sha256").update(bytes).digest("hex").slice(0, 8)
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
const front = frontPageHead({ html: indexHtml, siteUrl, siteName, locale: language, shareImage });
|
|
585
|
+
if (!front) {
|
|
586
|
+
warnings.push("index.html has no <title> and setto.config.json no displayName: the front page gets no share tags");
|
|
587
|
+
} else {
|
|
588
|
+
if (!front.description) warnings.push('index.html has no <meta name="description">: shared links show no text');
|
|
589
|
+
if (!siteUrl) {
|
|
590
|
+
warnings.push(
|
|
591
|
+
"no absolute site address (siteUrl in setto.config.json, SETTO_SITE_URL, VERCEL_PROJECT_PRODUCTION_URL or sitemap.xml): the front page gets no og:url, canonical or og:image"
|
|
592
|
+
);
|
|
593
|
+
} else if (!front.image) {
|
|
594
|
+
warnings.push(`no ${SHARE_IMAGE_PATH.slice(1)} in the build: shared links show no picture`);
|
|
595
|
+
}
|
|
596
|
+
shareImageUrl = front.image;
|
|
597
|
+
write("index.html", withHead(indexHtml, front, "social"));
|
|
598
|
+
}
|
|
599
|
+
const manifestRaw = readJson(path.join(root, PAGES_PATH));
|
|
600
|
+
const parsed = manifestRaw ? parseManifest(manifestRaw) : null;
|
|
601
|
+
const blog = parsed?.ok ? blogPage(parsed.manifest) : null;
|
|
602
|
+
if (blog && (blog.page.hidden || blog.section.hidden)) return { written, warnings, siteUrl };
|
|
603
|
+
const blogPath = blog?.page.path ?? (options.blogPath ? normalisePath(options.blogPath) : null);
|
|
604
|
+
if (!blogPath || blogPath === "/") return { written, warnings, siteUrl };
|
|
605
|
+
const posts = postsForLanguage(
|
|
606
|
+
loaded.map((p) => p.frontmatter),
|
|
607
|
+
language,
|
|
608
|
+
language
|
|
609
|
+
);
|
|
485
610
|
const all = loaded.map((p) => p.frontmatter);
|
|
486
611
|
const prefixOf = (lang) => lang === language ? "" : `/${lang}`;
|
|
487
612
|
const versionsOf = (slug) => all.filter((p) => p.slug === slug);
|
|
@@ -499,12 +624,13 @@ function writeStaticFiles(root, outDir, loaded, options = {}) {
|
|
|
499
624
|
blogPath: langBlogPath,
|
|
500
625
|
siteUrl,
|
|
501
626
|
siteName,
|
|
502
|
-
locale: lang
|
|
627
|
+
locale: lang,
|
|
628
|
+
image: shareImageUrl
|
|
503
629
|
})
|
|
504
630
|
)
|
|
505
631
|
);
|
|
506
632
|
for (const post of postsForLanguage(all, lang, language)) {
|
|
507
|
-
const meta = postHead({ post, blogPath: langBlogPath, siteUrl, siteName });
|
|
633
|
+
const meta = postHead({ post, blogPath: langBlogPath, siteUrl, siteName, fallbackImage: shareImageUrl });
|
|
508
634
|
const versions = versionsOf(post.slug);
|
|
509
635
|
if (post.locale !== lang && siteUrl) meta.url = absolute(siteUrl, `${prefixOf(post.locale)}${blogPath}/${post.slug}`);
|
|
510
636
|
if (siteUrl && versions.length > 1) {
|
|
@@ -542,7 +668,11 @@ function writeStaticFiles(root, outDir, loaded, options = {}) {
|
|
|
542
668
|
if (next !== sitemap) write("sitemap.xml", next);
|
|
543
669
|
}
|
|
544
670
|
}
|
|
545
|
-
return { written };
|
|
671
|
+
return { written, warnings, siteUrl };
|
|
672
|
+
}
|
|
673
|
+
function resolveSiteUrl(options, configured, sitemap) {
|
|
674
|
+
const vercel = process.env.VERCEL_PROJECT_PRODUCTION_URL?.trim();
|
|
675
|
+
return normaliseSiteUrl(options.siteUrl) ?? normaliseSiteUrl(configured) ?? normaliseSiteUrl(process.env.SETTO_SITE_URL) ?? (vercel ? normaliseSiteUrl(`https://${vercel}`) : null) ?? (sitemap ? originFromSitemap(sitemap) : null);
|
|
546
676
|
}
|
|
547
677
|
export {
|
|
548
678
|
settoBlog
|