@mccaskie-labs/workbench-site 0.15.1 → 0.15.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mccaskie-labs/workbench-site
2
2
 
3
+ ## 0.15.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Links to other websites open in a new tab.
8
+
9
+ ## 0.15.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Two pages on the same menu number (header, footer, admin menu or Admin home's counts) keep one order, by address, whatever order they were added in.
14
+
3
15
  ## 0.15.1
4
16
 
5
17
  ### Patch Changes
package/dist/builder.js CHANGED
@@ -479,13 +479,15 @@ function indexFile(pages, byId) {
479
479
  ].join("\n");
480
480
  }
481
481
  /** src/pages/needs.ts: the admin dashboard's counts, one per page on the site that has one, in the admin menu's order. */
482
+ /** Two menu places on the same number keep one order: by address. */
483
+ const byText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
482
484
  function needsFile(pages, byId) {
483
485
  const counts = pages
484
486
  .flatMap((p) => {
485
487
  const r = byId.get(p.recipe);
486
488
  return r?.needsYou && p.path !== null ? [{ order: r.menu?.admin ?? 1000, label: r.needsYou.label, href: p.path, file: r.needsYou.file, fn: r.needsYou.fn }] : [];
487
489
  })
488
- .sort((a, b) => a.order - b.order);
490
+ .sort((a, b) => a.order - b.order || byText(a.href, b.href));
489
491
  const imports = [...new Map(counts.map((c) => [`${c.fn}|${c.file}`, c])).values()].map((c) => `import { ${c.fn} } from "./${c.file.replace(/^src\/pages\//, "")}";`);
490
492
  return [
491
493
  `// Generated by ${PACKAGE} from workbench/site.json and its recipes: \`npx workbench-site add <page>\``,
@@ -558,7 +560,7 @@ function navFile(pages, byId) {
558
560
  const entries = (place) => pages
559
561
  .map((p) => ({ p, menu: byId.get(p.recipe)?.menu }))
560
562
  .filter((x) => x.p.path !== null && x.menu?.[place] !== undefined)
561
- .sort((a, b) => a.menu[place] - b.menu[place])
563
+ .sort((a, b) => a.menu[place] - b.menu[place] || byText(a.p.path, b.p.path))
562
564
  .map(({ p, menu }) => ` [${JSON.stringify(menu.label)}, ${JSON.stringify(p.path)}],`);
563
565
  const admin = [
564
566
  ...pages.flatMap((p) => {
@@ -567,7 +569,7 @@ function navFile(pages, byId) {
567
569
  }),
568
570
  ...pages.flatMap((p) => (byId.get(p.recipe)?.links ?? []).map((l) => ({ order: l.admin, label: l.label, href: l.href, about: l.about }))),
569
571
  ]
570
- .sort((a, b) => a.order - b.order)
572
+ .sort((a, b) => a.order - b.order || byText(a.href, b.href))
571
573
  .map((l) => ` [${JSON.stringify(l.label)}, ${JSON.stringify(l.href)}, ${JSON.stringify(l.about)}],`);
572
574
  const list = (lines) => (lines.length ? `[\n${lines.join("\n")}\n]` : "[]");
573
575
  return [
package/dist/frames.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // header carries the admin menu instead of the site's, and its <html> carries
7
7
  // wb-ui-admin, so it takes the project's accent and fonts on Clean's light
8
8
  // neutrals (docs/theming.md, Decisions) however dark or bold the public look.
9
- import { escape, safeHref } from "./html.js";
9
+ import { escape, newTab, safeHref } from "./html.js";
10
10
  /**
11
11
  * - landing: full-width sections, for a home page
12
12
  * - column: one centred column of reading width, for about, legal and most pages
@@ -29,7 +29,7 @@ const links = (items, cls, current) => items
29
29
  .map((l) => {
30
30
  const href = safeHref(l.href);
31
31
  const here = current !== undefined && href === current ? ` aria-current="page"` : "";
32
- return `<a class="${cls}" href="${escape(href)}"${here}>${escape(l.label)}</a>`;
32
+ return `<a class="${cls}" href="${escape(href)}"${here}${newTab(href)}>${escape(l.label)}</a>`;
33
33
  })
34
34
  .join("");
35
35
  /** workbench-ui's preview styles (its PREVIEW_FILE.url): every look a project may choose, as switchable blocks. */
@@ -44,7 +44,7 @@ export function frame(o) {
44
44
  const menu = o.menu?.length ? `<nav class="wb-site-menu" aria-label="Main">${links(o.menu, "wb-site-menu-link", o.current)}</nav>` : "";
45
45
  const headerStyle = pick(HEADERS, o.layout?.header);
46
46
  const footerStyle = pick(FOOTERS, o.layout?.footer);
47
- const action = o.headerAction ? `<a class="wb-site-button wb-site-header-action" href="${escape(safeHref(o.headerAction.href))}">${escape(o.headerAction.label)}</a>` : "";
47
+ const action = o.headerAction ? `<a class="wb-site-button wb-site-header-action" href="${escape(safeHref(o.headerAction.href))}"${newTab(safeHref(o.headerAction.href))}>${escape(o.headerAction.label)}</a>` : "";
48
48
  const header = `<header class="wb-site-header" data-header="${headerStyle}"><div class="wb-site-header-row"><a class="wb-site-name" href="/">${escape(o.site)}</a>${env}${menu}${action}</div></header>`;
49
49
  const [first = "", ...rest] = o.sections;
50
50
  const main = o.frame === "two-columns"
package/dist/html.d.ts CHANGED
@@ -2,5 +2,11 @@
2
2
  export declare function escape(text: string): string;
3
3
  /** An address a link may use: a path on this site, https, mailto or tel. Anything else becomes "#". */
4
4
  export declare function safeHref(href: string): string;
5
+ /**
6
+ * A link to another website opens in a new tab (Robert, 26 November 2026):
7
+ * the attributes to add for a full https address, and nothing for a path on
8
+ * this site, mailto or tel. Give it what safeHref returned.
9
+ */
10
+ export declare function newTab(href: string): string;
5
11
  /** Plain words to paragraphs: a blank line starts a new one, and a single line break stays one. */
6
12
  export declare function paragraphs(text: string, cls: string): string;
package/dist/html.js CHANGED
@@ -13,6 +13,14 @@ export function safeHref(href) {
13
13
  return h;
14
14
  return "#";
15
15
  }
16
+ /**
17
+ * A link to another website opens in a new tab (Robert, 26 November 2026):
18
+ * the attributes to add for a full https address, and nothing for a path on
19
+ * this site, mailto or tel. Give it what safeHref returned.
20
+ */
21
+ export function newTab(href) {
22
+ return /^https:\/\//i.test(href) ? ' target="_blank" rel="noopener"' : "";
23
+ }
16
24
  /** Plain words to paragraphs: a blank line starts a new one, and a single line break stays one. */
17
25
  export function paragraphs(text, cls) {
18
26
  return text
package/dist/sections.js CHANGED
@@ -4,10 +4,10 @@
4
4
  // project restyles it from its own project.css. Tools draw their own sections
5
5
  // (the free times, the order form) from their own packages; these are the
6
6
  // general ones every site uses.
7
- import { escape, paragraphs, safeHref } from "./html.js";
7
+ import { escape, newTab, paragraphs, safeHref } from "./html.js";
8
8
  /** How a hero is laid out: words alone, words over a picture, or words beside one. */
9
9
  export const HERO_ARRANGEMENTS = ["plain", "over-picture", "beside-picture"];
10
- const action = (a, quiet = false) => a ? `<p class="wb-site-actions"><a class="wb-site-button${quiet ? " wb-site-button-quiet" : ""}" href="${escape(safeHref(a.href))}">${escape(a.label)}</a></p>` : "";
10
+ const action = (a, quiet = false) => a ? `<p class="wb-site-actions"><a class="wb-site-button${quiet ? " wb-site-button-quiet" : ""}" href="${escape(safeHref(a.href))}"${newTab(safeHref(a.href))}>${escape(a.label)}</a></p>` : "";
11
11
  const img = (p) => `<img class="wb-site-image" src="${escape(safeHref(p.src))}" alt="${escape(p.alt)}" loading="lazy">`;
12
12
  const heading = (text, level = 2) => (text ? `<h${level} class="wb-site-heading">${escape(text)}</h${level}>` : "");
13
13
  /** The top of a page: its big heading, a line or two under it and one button. The page's only h1. */
@@ -25,7 +25,7 @@ export function text(o) {
25
25
  export function list(o) {
26
26
  const items = o.items
27
27
  .map((i) => {
28
- const title = i.href ? `<h3 class="wb-site-heading"><a class="wb-site-link" href="${escape(safeHref(i.href))}">${escape(i.title)}</a></h3>` : heading(i.title, 3);
28
+ const title = i.href ? `<h3 class="wb-site-heading"><a class="wb-site-link" href="${escape(safeHref(i.href))}"${newTab(safeHref(i.href))}>${escape(i.title)}</a></h3>` : heading(i.title, 3);
29
29
  return `<li class="wb-site-item">${title}${i.body ? paragraphs(i.body, "wb-site-paragraph") : ""}</li>`;
30
30
  })
31
31
  .join("");
@@ -97,7 +97,7 @@ export function needsYou(o) {
97
97
  .map((i) => {
98
98
  const count = i.count === null ? "" : `<span class="wb-site-needs-count">${i.count}</span> `;
99
99
  const unknown = i.count === null ? ` <span class="wb-site-needs-unknown">${escape(o.unavailable)}</span>` : "";
100
- return `<li class="wb-site-needs-item"><a class="wb-site-needs-link" href="${escape(safeHref(i.href))}">${count}<span class="wb-site-needs-label">${escape(i.label)}</span></a>${unknown}</li>`;
100
+ return `<li class="wb-site-needs-item"><a class="wb-site-needs-link" href="${escape(safeHref(i.href))}"${newTab(safeHref(i.href))}>${count}<span class="wb-site-needs-label">${escape(i.label)}</span></a>${unknown}</li>`;
101
101
  })
102
102
  .join("")}</ul>`
103
103
  : `<p class="wb-site-paragraph">${escape(o.none)}</p>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mccaskie-labs/workbench-site",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "description": "A Workbench project's standard pages: page recipes, the builder that turns them into thin page files calling Workbench's tools, and the page frames and sections they are drawn with (wb-site-*, restylable, on the project's theme tokens).",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",