Skip to content

Commit abd850a

Browse files
committed
Documentation keeps step anchors and removed-source notices
Converted procedures retain their source fragments, and stamped translations describe removed sources without linking to them. Signed-off-by: Shaun Struwig <41984034+Blargian@users.noreply.github.com>
1 parent 966f0d3 commit abd850a

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

‎docs/scripts/prepare-content.mjs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,21 @@ export function procedureMdx(text) {
491491
const heading = procedure[index];
492492
const bodyStart = heading.index + heading[0].length;
493493
const bodyEnd = procedure[index + 1]?.index ?? end;
494+
result += `<a id=${JSON.stringify(procedureHeadingId(heading[1], heading[2]))}></a>\n`;
494495
result += `<Step title=${JSON.stringify(heading[2])}>${text.slice(bodyStart, bodyEnd)}</Step>\n\n`;
495496
}
496497
return `${result}</Steps>\n\n${text.slice(end)}`;
497498
}
498499

500+
function procedureHeadingId(number, title) {
501+
return `${number}-${title}`
502+
.toLowerCase()
503+
.replace(/[`*_~]/g, "")
504+
.replace(/[^\p{L}\p{N}\s-]/gu, "")
505+
.trim()
506+
.replace(/\s+/g, "-");
507+
}
508+
499509
/** Escape uppercase Markdown placeholders that MDX would otherwise parse as JSX tags. */
500510
export function escapeMdxPlaceholders(text) {
501511
let fenced = false;
@@ -605,9 +615,13 @@ function gitBlob(text) {
605615

606616
/** Mark published translations whose stamped English source differs from this build's source. */
607617
export function staleTranslationNotice(text, english, url) {
608-
if (english === null) return text;
609618
const stamp = text.match(STAMP);
610-
if (!stamp || stamp[2] === gitBlob(english)) return text;
619+
if (!stamp) return text;
620+
if (english === null) {
621+
const notice = "> **Translation notice:** The English source is no longer published.";
622+
return text.replace(stamp[0], `${stamp[0]}\n\n${notice}\n`);
623+
}
624+
if (stamp[2] === gitBlob(english)) return text;
611625
const notice = "> **Translation notice:** The English source has changed. Read the [English page](" + url + ").";
612626
return text.replace(stamp[0], `${stamp[0]}\n\n${notice}\n`);
613627
}

‎docs/scripts/prepare-content.test.mjs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,15 @@ test("renders numbered source sections as Steps only in prepared content", () =>
134134
const source =
135135
"# Quickstart\n\nIntro.\n\n## 1. Boot the stack\n\nRun it.\n\n## 2. Open the dashboard\n\nOpen it.\n\n## Optional\n\nMore.\n";
136136
const expected =
137-
'# Quickstart\n\nIntro.\n\n<Steps>\n\n<Step title="Boot the stack">\n\nRun it.\n\n</Step>\n\n<Step title="Open the dashboard">\n\nOpen it.\n\n</Step>\n\n</Steps>\n\n## Optional\n\nMore.\n';
137+
'# Quickstart\n\nIntro.\n\n<Steps>\n\n<a id="1-boot-the-stack"></a>\n<Step title="Boot the stack">\n\nRun it.\n\n</Step>\n\n<a id="2-open-the-dashboard"></a>\n<Step title="Open the dashboard">\n\nOpen it.\n\n</Step>\n\n</Steps>\n\n## Optional\n\nMore.\n';
138+
139+
assert.equal(procedureMdx(source), expected);
140+
});
141+
142+
test("preserves source heading anchors when rendering steps", () => {
143+
const source = "## 1. Boot the stack\n\nRun it.\n";
144+
const expected =
145+
'<Steps>\n\n<a id="1-boot-the-stack"></a>\n<Step title="Boot the stack">\n\nRun it.\n</Step>\n\n</Steps>\n\n';
138146

139147
assert.equal(procedureMdx(source), expected);
140148
});
@@ -152,6 +160,18 @@ test("marks a stale translation after its stamped source comment", () => {
152160
);
153161
});
154162

163+
test("marks a translation whose English source was removed without linking to it", () => {
164+
const translation =
165+
"<!-- i18n: source=docs/getting-started/quickstart.md blob=0000000000000000000000000000000000000000 model=test -->\n" +
166+
"# Inicio rápido\n";
167+
168+
assert.equal(
169+
staleTranslationNotice(translation, null, ""),
170+
"<!-- i18n: source=docs/getting-started/quickstart.md blob=0000000000000000000000000000000000000000 model=test -->\n\n" +
171+
"> **Translation notice:** The English source is no longer published.\n\n# Inicio rápido\n",
172+
);
173+
});
174+
155175
test("links stale translated index pages to their directory routes", () => {
156176
assert.equal(englishRoute("ja/index.md"), "/docs/");
157177
assert.equal(englishRoute("ja/guides/index.md"), "/docs/guides/");

0 commit comments

Comments
 (0)