Skip to content

Commit a7cb985

Browse files
committed
enter.md has frontmatter
1 parent a044e21 commit a7cb985

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

docs/api/Browser/Enter.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
---
2+
title: A doc with tags
3+
cblibrary:
4+
name: browser.enter
5+
---
16
browser - enter
27

38
Simulates the Enter key press on the current page.
49

510
Returns: Promise
11+
12+
<CBBaseInfo />

package-lock.json

Lines changed: 1 addition & 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
@@ -19,6 +19,7 @@
1919
"@docusaurus/preset-classic": "3.2.1",
2020
"@mdx-js/react": "^3.0.0",
2121
"clsx": "^2.0.0",
22+
"js-yaml": "^4.1.0",
2223
"prism-react-renderer": "^2.3.0",
2324
"react": "^18.0.0",
2425
"react-dom": "^18.0.0"

scripts/jsdoc_to_docusaurus.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
const fs = require('fs');
3+
const yaml = require('js-yaml');
34

45
let rawdata = fs.readFileSync('../temp/out.json');
56
let outJson = JSON.parse(rawdata);
@@ -16,18 +17,21 @@ if (codeboltChild && codeboltChild.children) {
1617
if (!fs.existsSync(dir)){
1718
fs.mkdirSync(dir, { recursive: true });
1819
}
19-
fs.writeFileSync(`${dir}/_category_.json`, JSON.stringify({
20-
"label": CbProperties.name,
21-
"position": 2.5,
22-
"collapsible": true,
23-
"collapsed": true,
24-
"className": "red",
25-
"link": {
26-
"type": "generated-index",
27-
"title": CbProperties.name,
28-
"description": "Provides Functionality for "+CbProperties.name
29-
}
30-
}, null, 2));
20+
const categoryFilePath = `${dir}/_category_.json`;
21+
if (!fs.existsSync(categoryFilePath)) {
22+
fs.writeFileSync(categoryFilePath, JSON.stringify({
23+
"label": CbProperties.name,
24+
"position": 2.5,
25+
"collapsible": true,
26+
"collapsed": true,
27+
"className": "red",
28+
"link": {
29+
"type": "generated-index",
30+
"title": CbProperties.name,
31+
"description": "Provides Functionality for "+CbProperties.name
32+
}
33+
}, null, 2));
34+
}
3135
if (CbProperties.type && CbProperties.type.declaration && CbProperties.type.declaration.children) {
3236
CbProperties.type.declaration.children.forEach(CbFunctions => {
3337
let content = `${CbProperties.name} - ${CbFunctions.name}\n`;
@@ -46,7 +50,26 @@ if (codeboltChild && codeboltChild.children) {
4650
});
4751
}
4852

49-
fs.writeFileSync(`${dir}/${CbFunctions.name}.md`, content + '\n' + description + '\n' + parameterNames.join('\n') + "\n"+ returndata);
53+
const filePath = `${dir}/${CbFunctions.name}.md`;
54+
let fileContent = '';
55+
if (fs.existsSync(filePath)) {
56+
fileContent = fs.readFileSync(filePath, 'utf8');
57+
const frontMatterMatch = fileContent.match(/^---\n([\s\S]*?)\n---/);
58+
if (frontMatterMatch) {
59+
const frontMatterContent = frontMatterMatch[1];
60+
61+
let frontMatter = yaml.load(frontMatterContent);
62+
frontMatter.description = description;
63+
const newYamlContent = yaml.dump(frontMatter);
64+
fileContent = fileContent.replace(frontMatterMatch[0], `---\n${newYamlContent}---`);
65+
} else {
66+
fileContent = `---\ntitle: ${CbFunctions.name}\ndescription: ${description}\n---\n${content}\n${parameterNames.join('\n')}\n${returndata}`;
67+
}
68+
fs.writeFileSync(filePath, fileContent);
69+
} else {
70+
fileContent = `---\ntitle: ${CbFunctions.name}\ndescription: ${description}\n---\n${content}\n${parameterNames.join('\n')}\n${returndata}`;
71+
fs.writeFileSync(filePath, fileContent);
72+
}
5073
});
5174
}
5275
});

0 commit comments

Comments
 (0)