@mccaskie-labs/workbench-site 0.15.2 → 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,11 @@
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
+
3
9
  ## 0.15.2
4
10
 
5
11
  ### Patch Changes
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.2",
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",