Skip to content

Commit 9f933fe

Browse files
committed
slack code review
1 parent a894fb4 commit 9f933fe

File tree

11 files changed

+220
-203
lines changed

11 files changed

+220
-203
lines changed

package-lock.json

Lines changed: 138 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"preact-render-to-string": "^6.5.13",
7171
"reading-time": "^1.5.0",
7272
"recma-jsx": "^1.0.0",
73+
"rehype-raw": "^7.0.0",
7374
"rehype-recma": "^1.0.0",
7475
"rehype-stringify": "^10.0.1",
7576
"remark-gfm": "^4.0.1",

src/generators/jsx-ast/constants.mjs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ export const TAG_TRANSFORMS = {
3030
blockquote: JSX_IMPORTS.Blockquote.name,
3131
};
3232

33-
/**
34-
* @see transformer.mjs's TODO comment
35-
*/
36-
export const TYPE_TRANSFORMS = {
37-
raw: 'text',
38-
};
39-
4033
/**
4134
* API lifecycle change labels
4235
*/

src/generators/jsx-ast/index.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { buildSideBarDocPages } from './utils/buildBarProps.mjs';
21
import buildContent from './utils/buildContent.mjs';
32
import {
43
getCompatibleVersions,
@@ -38,7 +37,10 @@ export default {
3837
.sort((a, b) => a.heading.data.name.localeCompare(b.heading.data.name));
3938

4039
// Generate table of contents
41-
const docPages = buildSideBarDocPages(groupedModules, headNodes);
40+
const docPages = headNodes.map(node => [
41+
node.heading.data.name,
42+
`${node.api}.html`,
43+
]);
4244

4345
// Process each head node and build content
4446
const results = await Promise.all(
@@ -58,6 +60,7 @@ export default {
5860
};
5961
}),
6062
currentVersion: `v${version.version}`,
63+
pathname: `${entry.api}.html`,
6164
docPages,
6265
};
6366

src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,9 @@ import assert from 'node:assert/strict';
22
import { describe, it } from 'node:test';
33

44
import { SAMPLE } from './utils.mjs';
5-
import { buildSideBarDocPages, buildMetaBarProps } from '../buildBarProps.mjs';
5+
import { buildMetaBarProps } from '../buildBarProps.mjs';
66

77
describe('buildBarProps utilities', () => {
8-
describe('buildSideBarDocPages', () => {
9-
it('should return expected format', () => {
10-
const grouped = new Map([['sample-api', [SAMPLE]]]);
11-
const result = buildSideBarDocPages(grouped, [SAMPLE]);
12-
13-
assert.equal(result.length, 1);
14-
assert.equal(result[0].title, 'SampleFunc');
15-
assert.equal(result[0].doc, 'sample-api.html');
16-
assert.deepEqual(result[0].headings, [['SampleFunc', 'sample-func']]);
17-
});
18-
});
19-
208
describe('buildMetaBarProps', () => {
219
it('should include expected fields', () => {
2210
const result = buildMetaBarProps(SAMPLE, [SAMPLE]);

src/generators/jsx-ast/utils/buildBarProps.mjs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,6 @@ import { visit } from 'unist-util-visit';
33

44
import { DOC_API_BLOB_EDIT_BASE_URL } from '../../../constants.mjs';
55

6-
/**
7-
* Builds sidebar navigation for API documentation pages
8-
*
9-
* @param {Map<string, Array<ApiDocMetadataEntry>>} groupedModules - Modules grouped by API
10-
* @param {Array<ApiDocMetadataEntry>} headNodes - Main entry nodes for each API
11-
*/
12-
export const buildSideBarDocPages = (groupedModules, headNodes) =>
13-
headNodes.map(node => {
14-
const moduleEntries = groupedModules.get(node.api);
15-
16-
return {
17-
title: node.heading.data.name,
18-
doc: `${node.api}.html`,
19-
headings: moduleEntries
20-
.filter(entry => entry.heading?.data?.name && entry.heading.depth === 2)
21-
.map(entry => [entry.heading.data.name, entry.heading.data.slug]),
22-
};
23-
});
24-
256
/**
267
* Builds metadata for the sidebar and meta bar
278
*
@@ -38,10 +19,14 @@ export const buildMetaBarProps = (head, entries) => {
3819
}, '');
3920

4021
const headings = entries
41-
.filter(entry => entry.heading?.data?.name)
22+
.filter(
23+
entry => entry.heading?.data?.text && entry.heading?.data?.depth < 3
24+
)
4225
.map(entry => ({
4326
depth: entry.heading.depth,
44-
value: entry.heading.data.name,
27+
// TODO(@avivkeller): This should strip the `Type:` prefix,
28+
// and maybe also be HTML?
29+
value: entry.heading.data.text.replace(/`/g, ''),
4530
slug: entry.heading.data.slug,
4631
}));
4732

src/generators/jsx-ast/utils/transformer.mjs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import { visit } from 'unist-util-visit';
22

3-
import { TYPE_TRANSFORMS, TAG_TRANSFORMS } from '../constants.mjs';
3+
import { TAG_TRANSFORMS } from '../constants.mjs';
44

55
/**
66
* @template {import('unist').Node} T
77
* @param {T} tree
88
* @returns {T}
99
*/
1010
const transformer = tree => {
11-
visit(tree, ['raw', 'element'], node => {
12-
// TODO(@avivkeller): Our parsers shouldn't return raw nodes
13-
// when they mistake "<Type>" for an HTML node, rather, they
14-
// should return the string type that it is.
15-
node.type =
16-
node.type in TYPE_TRANSFORMS ? TYPE_TRANSFORMS[node.type] : node.type;
11+
visit(tree, 'element', node => {
1712
node.tagName =
1813
node.tagName in TAG_TRANSFORMS
1914
? TAG_TRANSFORMS[node.tagName]

src/generators/web/client/components/CodeBox.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default ({ className, ...props }) => {
5050
onCopy={handleCopy}
5151
language={getLanguageDisplayName(language)}
5252
{...props}
53-
copyText={copyText}
53+
buttonText={copyText}
5454
/>
5555
);
5656
};

0 commit comments

Comments
 (0)