Skip to content

Commit 2964513

Browse files
committed
make frontmatter optional if a name is provided
1 parent 6ff1506 commit 2964513

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

dist/main.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7854,9 +7854,19 @@ renderer.code = code_renderer;
78547854
renderer.heading = heading_renderer;
78557855
renderer.hr = hr_renderer;
78567856

7857-
function format_api(file, markdown) {
7858-
const { content, metadata } = extract_frontmatter(markdown);
7859-
const section_slug = make_slug(metadata.title);
7857+
function format_api(
7858+
file,
7859+
markdown,
7860+
name
7861+
) {
7862+
const {
7863+
content,
7864+
metadata: { title },
7865+
} = name
7866+
? { content: markdown, metadata: { title: name } }
7867+
: extract_frontmatter(markdown);
7868+
7869+
const section_slug = make_slug(title);
78607870

78617871
// reset the stateful stuff
78627872
prev_level = 3;
@@ -7868,7 +7878,7 @@ function format_api(file, markdown) {
78687878

78697879
return {
78707880
content: html,
7871-
title: metadata.title,
7881+
title: title,
78727882
slug: section_slug,
78737883
file,
78747884
sections,
@@ -7969,7 +7979,7 @@ async function run() {
79697979

79707980
const formatted_pkg_docs = pkg_docs.map(([name, content]) => [
79717981
name,
7972-
format_api(name, increment_headings(content)),
7982+
format_api(name, increment_headings(content), name),
79737983
]);
79747984

79757985
console.log(formatted_pkg_docs);

src/format/format_api.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ renderer.code = code_renderer;
106106
renderer.heading = heading_renderer;
107107
renderer.hr = hr_renderer;
108108

109-
export function format_api(file: string, markdown: string): FormattedFile {
110-
const { content, metadata } = extract_frontmatter(markdown);
111-
const section_slug = make_slug(metadata.title);
109+
export function format_api(
110+
file: string,
111+
markdown: string,
112+
name?: string
113+
): FormattedFile {
114+
const {
115+
content,
116+
metadata: { title },
117+
} = name
118+
? { content: markdown, metadata: { title: name } }
119+
: extract_frontmatter(markdown);
120+
121+
const section_slug = make_slug(title);
112122

113123
// reset the stateful stuff
114124
prev_level = 3;
@@ -120,7 +130,7 @@ export function format_api(file: string, markdown: string): FormattedFile {
120130

121131
return {
122132
content: html,
123-
title: metadata.title,
133+
title: title,
124134
slug: section_slug,
125135
file,
126136
sections,

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async function run() {
9696

9797
const formatted_pkg_docs = pkg_docs.map(([name, content]) => [
9898
name,
99-
format_api(name, increment_headings(content)),
99+
format_api(name, increment_headings(content), name),
100100
]);
101101

102102
console.log(formatted_pkg_docs);

0 commit comments

Comments
 (0)