Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/site/scripts/base-aware-href.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';

import { baseAwareHref } from '../src/lib/base-aware-href.mjs';

test('leaves root-relative links unchanged at the root base', () => {
assert.equal(baseAwareHref('/configure/relay/'), '/configure/relay/');
});

test('prefixes root-relative links with a non-root base', () => {
assert.equal(baseAwareHref('/configure/relay/', '/dev/'), '/dev/configure/relay/');
assert.equal(baseAwareHref('/configure/relay/', '/dev'), '/dev/configure/relay/');
});

test('leaves external and protocol-relative links unchanged', () => {
assert.equal(baseAwareHref('https://example.com/spec'), 'https://example.com/spec');
assert.equal(baseAwareHref('//example.com/spec', '/dev/'), '//example.com/spec');
});
4 changes: 3 additions & 1 deletion docs/site/src/components/StandardsTable.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
---
import standards from '../data/generated/standards.json';
import { baseAwareHref } from '../lib/base-aware-href.mjs';

// evidence_gap is an optional flag; absent from the JSON unless a row sets it.
const rows = standards as ((typeof standards)[number] & { evidence_gap?: boolean })[];
const base = import.meta.env.BASE_URL;
---

<div class="standards-list">
Expand Down Expand Up @@ -56,7 +58,7 @@ const rows = standards as ((typeof standards)[number] & { evidence_gap?: boolean
<span class="footer-label">Evidence</span>
<ul class="link-list">
{standard.evidence_docs.map((doc: { url: string; label: string }) => (
<li><a href={doc.url}>{doc.label}</a></li>
<li><a href={baseAwareHref(doc.url, base)}>{doc.label}</a></li>
))}
</ul>
</footer>
Expand Down
6 changes: 6 additions & 0 deletions docs/site/src/lib/base-aware-href.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function baseAwareHref(href, baseUrl = '/') {
if (!href.startsWith('/') || href.startsWith('//')) return href;

const base = baseUrl === '/' ? '' : baseUrl.replace(/\/$/, '');
return `${base}${href}`;
}
Loading