@sevenfold/setto-client 0.49.0 → 0.50.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.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A page's own title and description, shared by the build (`settoBlog()`
3
+ * writes `<route>/index.html` with them) and the browser (`SettoPage` sets
4
+ * `document.title`), so the head a crawler reads without JavaScript and the
5
+ * one it reads after rendering are the same answer.
6
+ *
7
+ * Pure and dependency-free: the browser bundle and the Node plugin both
8
+ * import it.
9
+ */
10
+ /**
11
+ * The `<meta name>` the build writes on every page it gives a head of its
12
+ * own: the front page's title, which a page's title is built on. Without it
13
+ * the browser could only take `document.title` as the base, which on such a
14
+ * page is already the page's own title, and «Priser · Priser · …» follows.
15
+ */
16
+ export declare const TITLE_BASE_META = "setto:title-base";
17
+ /** A run of four or more capitals and not one small letter: «DIN FRISØR AS». */
18
+ export declare const isAllCaps: (value: string) => boolean;
19
+ /** «Nordvik Rør» from «Nordvik Rør – rørlegger i Ålesund». */
20
+ export declare function nameFromTitle(title: string | undefined): string | undefined;
21
+ /**
22
+ * A page's title from its own (`pages.priser`: «Priser») and the front
23
+ * page's («Sportsparken Vegsund – aktivitetspark i Ålesund»):
24
+ * «Priser · Sportsparken Vegsund – aktivitetspark i Ålesund».
25
+ *
26
+ * A page title that already names the business («Prisar – Hundeidvik
27
+ * Familiepark») is a whole title and is used as it is.
28
+ */
29
+ export declare function pageTitle(title: string | undefined | null, base: string | undefined | null): string;
30
+ /**
31
+ * Where a page's description lives: beside a title key that ends in
32
+ * `.title` (`pages.prisar.title` → `pages.prisar.description`). A title key
33
+ * that is a string of its own (`pages.priser`) has nowhere beside it, and the
34
+ * page takes the site's description.
35
+ */
36
+ export declare function descriptionKeyFor(titleKey: string): string | null;
@@ -3316,6 +3316,23 @@ const removeBtnStyle = {
3316
3316
  boxShadow: "0 1px 4px rgba(0,0,0,0.18)",
3317
3317
  fontFamily: 'system-ui, -apple-system, "Segoe UI", sans-serif'
3318
3318
  };
3319
+ const TITLE_BASE_META = "setto:title-base";
3320
+ const isAllCaps = (value) => !/\p{Ll}/u.test(value) && /\p{Lu}{4,}/u.test(value);
3321
+ function nameFromTitle(title) {
3322
+ if (!title) return void 0;
3323
+ const separator = /\s(?:–|—|\||-)\s/.exec(title);
3324
+ const name = (separator ? title.slice(0, separator.index) : title).replace(/\s+/g, " ").trim();
3325
+ return name && !isAllCaps(name) ? name : void 0;
3326
+ }
3327
+ function pageTitle(title, base) {
3328
+ const own = title?.replace(/\s+/g, " ").trim() ?? "";
3329
+ const front = base?.replace(/\s+/g, " ").trim() ?? "";
3330
+ if (!own) return front;
3331
+ if (!front || own === front) return own;
3332
+ const name = nameFromTitle(front);
3333
+ if (name && own.toLowerCase().includes(name.toLowerCase())) return own;
3334
+ return `${own} · ${front}`;
3335
+ }
3319
3336
  function usePageManifest() {
3320
3337
  const { pageStore, config } = useSetto();
3321
3338
  const snap = useSyncExternalStore(
@@ -3462,9 +3479,9 @@ function usePageTitle(page) {
3462
3479
  const title = page.path === "/" ? null : t(page.titleKey);
3463
3480
  useEffect(() => {
3464
3481
  if (!title || typeof document === "undefined") return;
3465
- original.current ??= document.title;
3482
+ original.current ??= document.querySelector(`meta[name="${TITLE_BASE_META}"]`)?.content || document.title;
3466
3483
  const base = original.current;
3467
- document.title = base ? `${title} · ${base}` : title;
3484
+ document.title = pageTitle(title, base);
3468
3485
  return () => {
3469
3486
  document.title = base;
3470
3487
  };