Skip to content

Commit 53b457d

Browse files
authored
feat(metabar): improve headings and add stability (#381)
1 parent a04ad2d commit 53b457d

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,23 @@ const shouldIncludeEntryInToC = ({ heading }) =>
4141
const extractHeading = entry => {
4242
const data = entry.heading.data;
4343

44-
const rawName = data.name
45-
// Remove any containing code blocks
46-
.replace(/`/g, '')
47-
// Remove any prefixes (i.e. 'Class:')
48-
.replace(/^[^:]+:/, '')
49-
// Trim the remaining whitespace
50-
.trim();
51-
52-
let heading = getFullName(data, rawName);
44+
const cliFlagOrEnv = [...data.text.matchAll(/`(-[\w-]+|[A-Z0-9_]+=)/g)];
45+
46+
let heading;
47+
48+
if (cliFlagOrEnv.length > 0) {
49+
heading = cliFlagOrEnv.at(-1)[1];
50+
} else {
51+
const rawName = data.name
52+
// Remove any containing code blocks
53+
.replace(/`/g, '')
54+
// Remove any prefixes (i.e. 'Class:')
55+
.replace(/^[^:]+:/, '')
56+
// Trim the remaining whitespace
57+
.trim();
58+
59+
heading = getFullName(data, rawName);
60+
}
5361

5462
if (data.type === 'ctor') {
5563
heading += ' Constructor';
@@ -58,6 +66,7 @@ const extractHeading = entry => {
5866
return {
5967
depth: entry.heading.depth,
6068
value: heading,
69+
stability: parseInt(entry.stability?.children[0]?.data.index ?? 2),
6170
slug: data.slug,
6271
};
6372
};

src/generators/web/ui/components/MetaBar/index.jsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CodeBracketIcon, DocumentIcon } from '@heroicons/react/24/outline';
2+
import Badge from '@node-core/ui-components/Common/Badge';
23
import MetaBar from '@node-core/ui-components/Containers/MetaBar';
34
import GitHubIcon from '@node-core/ui-components/Icons/Social/GitHub';
45

@@ -11,13 +12,16 @@ const iconMap = {
1112

1213
/**
1314
* @typedef MetaBarProps
14-
* @property {Array<import('@vcarl/remark-headings').Heading>} headings - Array of page headings for table of contents
15+
* @property {Array<import('@vcarl/remark-headings').Heading & { stability: string }>} headings - Array of page headings for table of contents
1516
* @property {string} addedIn - Version or date when feature was added
1617
* @property {string} readingTime - Estimated reading time for the page
1718
* @property {Array<[string, string]>} viewAs - Array of [title, path] tuples for view options
1819
* @property {string} editThisPage - URL for editing the current page
1920
*/
2021

22+
const STABILITY_KINDS = ['error', 'warning', null, 'default'];
23+
const STABILITY_LABELS = ['D', 'E', null, 'L'];
24+
2125
/**
2226
* MetaBar component that displays table of contents and page metadata
2327
* @param {MetaBarProps} props - Component props
@@ -32,8 +36,23 @@ export default ({
3236
<MetaBar
3337
heading="Table of Contents"
3438
headings={{
35-
items: headings.map(({ slug, ...heading }) => ({
39+
items: headings.map(({ slug, value, stability, ...heading }) => ({
3640
...heading,
41+
value:
42+
stability !== 2 ? (
43+
<>
44+
{value}
45+
<Badge
46+
size="small"
47+
className={styles.badge}
48+
kind={STABILITY_KINDS[stability]}
49+
>
50+
{STABILITY_LABELS[stability]}
51+
</Badge>
52+
</>
53+
) : (
54+
value
55+
),
3756
data: { id: slug },
3857
})),
3958
}}

src/generators/web/ui/components/MetaBar/index.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
height: 1rem;
55
margin-right: 0.25rem;
66
}
7+
8+
.badge {
9+
display: inline-block;
10+
margin-left: 0.25rem;
11+
}

0 commit comments

Comments
 (0)