-
Notifications
You must be signed in to change notification settings - Fork 327
Generate the SDK landing page section lists from sidebars.js #5179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
DABH
wants to merge
5
commits into
main
Choose a base branch
from
docs/prototype-sidebar-link-codegen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
27d82d8
WIP: prototype insert-only sidebar link list generator for #5144
DABH b211dc9
Report pages that hand-maintain a list with no markers
DABH 8abf8f1
Generate the SDK landing page section lists from sidebars.js
DABH abb4d4c
Fix five defects found reviewing the generator
DABH 57f11f4
Close the Serverless Workers gap on the Workers index pages too
DABH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| const test = require('node:test'); | ||
| const assert = require('node:assert'); | ||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
|
|
||
| const { | ||
| reconcileList, | ||
| firstLink, | ||
| buildDocIndex, | ||
| buildSidebarTree, | ||
| findOwningCategory, | ||
| findNamedDescendant, | ||
| processFile, | ||
| } = require('./generate-sidebar-link-lists'); | ||
|
|
||
| // Synthetic categories keep these cases stable as the real docs change. | ||
| const cat = (label, children) => ({ kind: 'category', label, url: null, children }); | ||
| const doc = (label, url) => ({ kind: 'doc', label, url }); | ||
| const link = (label, url) => ({ kind: 'link', label, url, external: true }); | ||
|
|
||
| test('adds a missing sidebar entry next to its sibling, not at the end', () => { | ||
| const category = cat('Workers', [ | ||
| doc('Run a Worker', '/develop/python/workers/run-worker-process'), | ||
| doc('Serverless Workers', '/develop/python/workers/serverless-workers'), | ||
| doc('Interceptors', '/develop/python/workers/interceptors'), | ||
| ]); | ||
| const existing = [ | ||
| '- [Worker processes](/develop/python/workers/run-worker-process)', | ||
| '- [Interceptors](/develop/python/workers/interceptors)', | ||
| ]; | ||
|
|
||
| const { lines, added } = reconcileList(category, existing, ''); | ||
|
|
||
| assert.deepStrictEqual(added, ['/develop/python/workers/serverless-workers']); | ||
| assert.deepStrictEqual(lines, [ | ||
| // Hand-written "Worker processes" survives; the sidebar's "Run a Worker" does not win. | ||
| '- [Worker processes](/develop/python/workers/run-worker-process)', | ||
| '- [Serverless Workers](/develop/python/workers/serverless-workers)', | ||
| '- [Interceptors](/develop/python/workers/interceptors)', | ||
| ]); | ||
| }); | ||
|
|
||
| test('never rewrites the label of an entry that is already listed', () => { | ||
| const category = cat('Best practices', [doc('Data handling', '/develop/java/best-practices/data-handling')]); | ||
| const existing = ['- [Converters and encryption](/develop/java/best-practices/data-handling)']; | ||
|
|
||
| const { lines, added } = reconcileList(category, existing, ''); | ||
|
|
||
| assert.deepStrictEqual(added, []); | ||
| assert.deepStrictEqual(lines, existing, 'sidebar labels disagree with prose on 37 links; prose wins'); | ||
| }); | ||
|
|
||
| test('preserves a link the sidebar does not know about', () => { | ||
| // docs/develop/java/nexus/index.mdx carries an external learn.temporal.io | ||
| // tutorial link inside its section list. | ||
| const category = cat('Nexus', [doc('Quickstart', '/develop/java/nexus/quickstart')]); | ||
| const existing = [ | ||
| '- [Quickstart](/develop/java/nexus/quickstart)', | ||
| '- [Nexus sync tutorial](https://learn.temporal.io/tutorials/nexus/nexus-sync-tutorial/)', | ||
| ]; | ||
|
|
||
| const { lines } = reconcileList(category, existing, ''); | ||
|
|
||
| assert.ok( | ||
| lines.includes('- [Nexus sync tutorial](https://learn.temporal.io/tutorials/nexus/nexus-sync-tutorial/)'), | ||
| 'an external link inside a generated region must survive', | ||
| ); | ||
| assert.strictEqual(lines.length, 2); | ||
| }); | ||
|
|
||
| test('is idempotent', () => { | ||
| const category = cat('Workers', [ | ||
| doc('Run a Worker', '/a'), | ||
| doc('Serverless Workers', '/b'), | ||
| ]); | ||
| const first = reconcileList(category, ['- [Worker processes](/a)'], '').lines; | ||
| const second = reconcileList(category, first, '').lines; | ||
| assert.deepStrictEqual(second, first); | ||
| }); | ||
|
|
||
| test('resolves a category with no link of its own to its first descendant', () => { | ||
| // "Standalone Activities" has no link:, so Docusaurus falls back to the | ||
| // first child. Dropping it instead would silently shorten the list. | ||
| const nested = cat('Standalone Activities', [ | ||
| doc('Quickstart', '/develop/go/activities/standalone-activities-quickstart'), | ||
| doc('Feature Guide', '/develop/go/activities/standalone-activities'), | ||
| ]); | ||
| assert.strictEqual(firstLink(nested), '/develop/go/activities/standalone-activities-quickstart'); | ||
| }); | ||
|
|
||
| test('refuses to render an item with no resolvable link rather than omitting it', () => { | ||
| const category = cat('Activities', [cat('Empty', [])]); | ||
| assert.throws(() => reconcileList(category, [], ''), /no resolvable link/); | ||
| }); | ||
|
|
||
| test('keeps an external sidebar link item', () => { | ||
| const category = cat('Section', [link('Change log', 'https://temporal.io/change-log')]); | ||
| const { lines } = reconcileList(category, [], ''); | ||
| assert.deepStrictEqual(lines, ['- [Change log](https://temporal.io/change-log)']); | ||
| }); | ||
|
|
||
| test('honours the indent of the marker', () => { | ||
| const category = cat('S', [doc('A', '/a')]); | ||
| const { lines } = reconcileList(category, [], ' '); | ||
| assert.deepStrictEqual(lines, [' - [A](/a)']); | ||
| }); | ||
|
|
||
| // Integration: the real sidebars.js and docs tree must resolve without | ||
| // throwing, so a malformed sidebar entry fails the test rather than the build. | ||
| test('every SDK section index page resolves to a sidebar category', () => { | ||
| const docs = buildDocIndex(); | ||
| const tree = buildSidebarTree(docs); | ||
| const missing = []; | ||
|
|
||
| for (const [id, entry] of docs) { | ||
| if (!/^develop\/[a-z]+\/[a-z-]+\/index$/.test(id)) continue; | ||
| if (entry.draft || entry.unlisted) continue; | ||
| if (!findOwningCategory(tree, id)) missing.push(id); | ||
| } | ||
|
|
||
| assert.deepStrictEqual(missing, [], 'these pages have no owning sidebar category'); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // processFile: marker parsing and the error paths. These run against a real | ||
| // temporary page under docs/ because the doc id -> sidebar category lookup | ||
| // only means anything against the real sidebars.js. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| const TMP_DIR = path.join(process.cwd(), 'docs', 'develop', '_sidebar_link_list_fixture'); | ||
|
|
||
| function withFixture(body, run) { | ||
| fs.mkdirSync(TMP_DIR, { recursive: true }); | ||
| const file = path.join(TMP_DIR, 'index.mdx'); | ||
| fs.writeFileSync(file, body); | ||
| try { | ||
| return run(file); | ||
| } finally { | ||
| fs.rmSync(TMP_DIR, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| test('processFile rejects a region with no closing marker', () => { | ||
| const docs = buildDocIndex(); | ||
| const tree = buildSidebarTree(docs); | ||
| withFixture('---\nid: index\n---\n\n{/* SIDEBAR-LIST-START */}\n- [A](/a)\n', (file) => { | ||
| assert.throws(() => processFile(file, tree, docs), /no matching SIDEBAR-LIST-END/); | ||
| }); | ||
| }); | ||
|
|
||
| test('processFile rejects a page no sidebar category links to', () => { | ||
| const docs = buildDocIndex(); | ||
| const tree = buildSidebarTree(docs); | ||
| withFixture('---\nid: index\n---\n\n{/* SIDEBAR-LIST-START */}\n{/* SIDEBAR-LIST-END */}\n', (file) => { | ||
| assert.throws(() => processFile(file, tree, docs), /no sidebars\.js category links to this page/); | ||
| }); | ||
| }); | ||
|
|
||
| test('processFile leaves everything outside the markers untouched', () => { | ||
| const docs = buildDocIndex(); | ||
| const tree = buildSidebarTree(docs); | ||
| const real = path.join(process.cwd(), 'docs', 'develop', 'python', 'index.mdx'); | ||
| const before = fs.readFileSync(real, 'utf8'); | ||
| const { content, regions } = processFile(real, tree, docs); | ||
|
|
||
| assert.ok(regions.length > 0, 'the Python landing page should have marked regions'); | ||
|
|
||
| // Compare everything that is not inside a marked region. | ||
| const strip = (text) => { | ||
| const out = []; | ||
| let inside = false; | ||
| for (const line of text.split('\n')) { | ||
| if (/SIDEBAR-LIST-START/.test(line)) { inside = true; out.push(line); continue; } | ||
| if (/SIDEBAR-LIST-END/.test(line)) { inside = false; out.push(line); continue; } | ||
| if (!inside) out.push(line); | ||
| } | ||
| return out.join('\n'); | ||
| }; | ||
| assert.strictEqual(strip(content), strip(before), 'content outside the markers must not change'); | ||
| }); | ||
|
|
||
| test('processFile is a no-op on an already-current page', () => { | ||
| const docs = buildDocIndex(); | ||
| const tree = buildSidebarTree(docs); | ||
| const real = path.join(process.cwd(), 'docs', 'develop', 'python', 'index.mdx'); | ||
| const { changed } = processFile(real, tree, docs); | ||
| assert.strictEqual(changed, false, 'run `yarn sidebar-links` — the committed page is stale'); | ||
| }); | ||
|
|
||
| test('a marker keyed by category URL resolves even when the heading text differs', () => { | ||
| // "## [Temporal Client](/develop/python/client)" sits above the category | ||
| // labelled "Client", which is why the URL form exists. | ||
| const docs = buildDocIndex(); | ||
| const tree = buildSidebarTree(docs); | ||
| const own = findOwningCategory(tree, 'develop/python/index'); | ||
| assert.ok(own, 'the Python SDK category should link develop/python/index'); | ||
| assert.strictEqual(findNamedDescendant(own, '/develop/python/client').label, 'Client'); | ||
| assert.strictEqual(findNamedDescendant(own, 'Temporal Client'), null, 'heading text is not a sidebar label'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [vale] reported by reviewdog 🐶
[Temporal.Headings] 'Temporal .NET technical resources' should use sentence-style capitalization.