@f5-sales-demo/docs-theme 4.4.4 → 4.4.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@f5-sales-demo/docs-theme",
3
- "version": "4.4.4",
3
+ "version": "4.4.6",
4
4
  "description": "F5 Distributed Cloud branded Starlight documentation theme",
5
5
  "type": "module",
6
6
  "engines": {
@@ -1,6 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
3
- import { join } from 'node:path';
3
+ import { join, posix } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
 
6
6
  const hash = (value) => createHash('sha256').update(value).digest('hex').slice(0, 24);
@@ -11,6 +11,7 @@ export async function shareProviderAssets(root, base = '/') {
11
11
  const assetRoot = join(root, '_shared');
12
12
  const assets = new Map();
13
13
  const prefix = `${base.replace(/\/$/, '')}/_shared/`;
14
+ const tokenStyles = new Map();
14
15
  let saved = 0;
15
16
  await mkdir(assetRoot, { recursive: true });
16
17
  for (const file of files) {
@@ -23,14 +24,32 @@ export async function shareProviderAssets(root, base = '/') {
23
24
  assets.set(name, body);
24
25
  return `<script${attrs} src="${prefix}${name}"></script>`;
25
26
  });
27
+ html = html.replace(/<span style="(--0:[^"]+)"/g, (_, style) => {
28
+ const name = `t${hash(style).slice(0, 10)}`;
29
+ if (style.length <= name.length + 2) return `<span style="${style}"`;
30
+ tokenStyles.set(name, style);
31
+ return `<span class="${name}"`;
32
+ });
33
+ html = html.replace(/href="https:\/\/f5-sales-demo.github.io(\/terraform-provider-xcsh\/[^"#]*)/g, 'href="$1');
34
+ if (tokenStyles.size) html = html.replace('</head>', `<link rel="stylesheet" href="${prefix}tokens.css"></head>`);
26
35
  const islands = [];
27
36
  html = html.replace(/<astro-island\b[\s\S]*?<\/astro-island>/g, (island) => {
28
37
  islands.push(island);
29
38
  return `<!--provider-island-${islands.length - 1}-->`;
30
39
  });
40
+ const pagePath = `${base.replace(/\/$/, '')}/${posix.dirname(file) === '.' ? '' : posix.dirname(file) + '/'}`;
41
+ html = html.replace(/<a\b([^>]*?)href="([^"#]+)(#[^"]*)?"/g, (original, attrs, href, fragment = '') => {
42
+ if (!href.startsWith(`${base.replace(/\/$/, '')}/`)) return original;
43
+ const target = href.split('?')[0];
44
+ const query = href.slice(target.length);
45
+ let relative = posix.relative(pagePath, target) || '.';
46
+ if (target.endsWith('/')) relative += '/';
47
+ relative += query + fragment;
48
+ return relative.length < (href + fragment).length ? `<a${attrs}href="${relative}"` : original;
49
+ });
31
50
  html = html.replace(/<svg\b([^>]*)>([\s\S]*?)<\/svg>/g, (original, attrs, body) => {
32
51
  // Sprite definitions and interactive SVG content must remain inline.
33
- if (/<(?:symbol|script|foreignObject)\b/.test(body) || /\bid=/.test(attrs) || /\bon\w+=/.test(attrs))
52
+ if (/<(?:use|symbol|script|foreignObject)\b/.test(body) || /\bid=/.test(attrs) || /\bon\w+=/.test(attrs))
34
53
  return original;
35
54
  const name = `${hash(body)}.svg`;
36
55
  assets.set(name, `<svg xmlns="http://www.w3.org/2000/svg"><symbol id="icon">${body}</symbol></svg>`);
@@ -40,6 +59,8 @@ export async function shareProviderAssets(root, base = '/') {
40
59
  saved += Buffer.byteLength(before) - Buffer.byteLength(html);
41
60
  await writeFile(path, html);
42
61
  }
62
+ if (tokenStyles.size)
63
+ assets.set('tokens.css', [...tokenStyles].map(([name, style]) => `.${name}{${style}}`).join('\n'));
43
64
  let assetBytes = 0;
44
65
  for (const [name, body] of assets) {
45
66
  await writeFile(join(assetRoot, name), body);
@@ -23,3 +23,51 @@ it('shares identical generated assets, preserving script order and SVG dimension
23
23
  await rm(root, { recursive: true, force: true });
24
24
  }
25
25
  });
26
+
27
+ it('keeps already shared SVG use elements unchanged on repeated passes', async () => {
28
+ const root = await mkdtemp(join(tmpdir(), 'shared-provider-repeat-'));
29
+ try {
30
+ const html = '<svg width="16"><use href="/shared/icon.svg#icon"></use></svg>';
31
+ await writeFile(join(root, 'page.html'), html);
32
+ await shareProviderAssets(root, '/provider/');
33
+ expect(await readFile(join(root, 'page.html'), 'utf8')).toBe(html);
34
+ } finally {
35
+ await rm(root, { recursive: true, force: true });
36
+ }
37
+ });
38
+
39
+ it('shortens internal HTML links without changing resolved fragment destinations', async () => {
40
+ const root = await mkdtemp(join(tmpdir(), 'provider-links-'));
41
+ try {
42
+ const { mkdir } = await import('node:fs/promises');
43
+ await mkdir(join(root, 'resources/demo'), { recursive: true });
44
+ const href = '/provider/preview/main/resources/demo/properties/#schema-name';
45
+ await writeFile(join(root, 'resources/demo/index.html'), `<a href="${href}">Property</a>`);
46
+ await shareProviderAssets(root, '/provider/preview/main/');
47
+ const html = await readFile(join(root, 'resources/demo/index.html'), 'utf8');
48
+ const match = /href="([^"]+)"/.exec(html);
49
+ if (!match) throw new Error('missing link');
50
+ expect(new URL(match[1], 'https://example.test/provider/preview/main/resources/demo/').href).toBe(
51
+ `https://example.test${href}`,
52
+ );
53
+ expect(match[1]).toBe('properties/#schema-name');
54
+ } finally {
55
+ await rm(root, { recursive: true, force: true });
56
+ }
57
+ });
58
+
59
+ it('resolves file-route links from their containing directory', async () => {
60
+ const root = await mkdtemp(join(tmpdir(), 'provider-file-route-'));
61
+ try {
62
+ await writeFile(join(root, '404.html'), '<a href="/provider/preview/main/actions/">Actions</a>');
63
+ await shareProviderAssets(root, '/provider/preview/main/');
64
+ const html = await readFile(join(root, '404.html'), 'utf8');
65
+ const match = /href="([^"]+)"/.exec(html);
66
+ if (!match) throw new Error('missing link');
67
+ expect(new URL(match[1], 'https://example.test/provider/preview/main/404.html').href).toBe(
68
+ 'https://example.test/provider/preview/main/actions/',
69
+ );
70
+ } finally {
71
+ await rm(root, { recursive: true, force: true });
72
+ }
73
+ });