Skip to content

Commit f701185

Browse files
committed
updated The Data
1 parent b503c75 commit f701185

File tree

5 files changed

+258559
-244326
lines changed

5 files changed

+258559
-244326
lines changed

Diff for: scripts/jsdoc_to_docusaurus.js

+52-29
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function updateFrontmatter(existingFrontmatter, additionalFrontmatter) {
1818
}
1919

2020
function createFrontMatter(frontMatter) {
21-
let frontMatterString = `---\ntitle: ${frontMatter.name}\ndescription: ${frontMatter.description}\n---\n`
22-
return frontMatterString;
21+
let frontMatterString = yaml.dump(frontMatter);
22+
return `---\n${frontMatterString}---\n`;
2323
}
2424

2525
function createCategoryFile(categoryPath, categoryName) {
@@ -39,6 +39,30 @@ function createCategoryFile(categoryPath, categoryName) {
3939
}
4040
}
4141

42+
43+
function writeToFile(filePath, frontMatterVars){
44+
let originalfileContent = '';
45+
let newFileContent = '';
46+
47+
if (fs.existsSync(filePath)) {
48+
originalfileContent = fs.readFileSync(filePath, 'utf8');
49+
const frontMatterMatch = originalfileContent.match(/^---\n([\s\S]*?)\n---/);
50+
if (frontMatterMatch) {
51+
const frontMatterContent = frontMatterMatch[1];
52+
let newYamlContent = updateFrontmatter(frontMatterContent, { "cbbaseinfo": frontMatterVars.cbbaseinfo, "cbparameters": frontMatterVars.cbparameters });
53+
newFileContent = originalfileContent.replace(frontMatterMatch[0], `---\n${newYamlContent}---`);
54+
} else {
55+
const frontMatter = createFrontMatter({ name: frontMatterVars.data.name, "cblibrary": frontMatterVars.cbbaseinfo, "cbparameters": frontMatterVars.cbparameters });
56+
newFileContent = frontMatter + originalfileContent;
57+
}
58+
fs.writeFileSync(filePath, newFileContent);
59+
} else {
60+
const frontMatter = createFrontMatter({ name: frontMatterVars.data.name, "cblibrary": frontMatterVars.cbbaseinfo, "cbparameters": frontMatterVars.cbparameters });
61+
newFileContent = frontMatter + "<CBBaseInfo/>";
62+
fs.writeFileSync(filePath, newFileContent);
63+
}
64+
}
65+
4266
if (codeboltChild && codeboltChild.children) {
4367
codeboltChild.children.forEach(CbProperties => {
4468
const dir = `../docs/api/${CbProperties.name}`;
@@ -52,46 +76,45 @@ if (codeboltChild && codeboltChild.children) {
5276
const categoryFilePath = `${dir}/_category_.json`;
5377
createCategoryFile(categoryFilePath, CbProperties.name);
5478

79+
let frontMatterVars = {
80+
"data": {
81+
"name": " ",
82+
"category": " ",
83+
},
84+
"cbbaseinfo": {
85+
"description": " ",
86+
},
87+
"cbparameters": {
88+
"parameters": [],
89+
"returndata": " ",
90+
}
91+
}
92+
5593

5694
if (CbProperties.type && CbProperties.type.declaration && CbProperties.type.declaration.children) {
5795
CbProperties.type.declaration.children.forEach(CbFunctions => {
58-
let content = `${CbProperties.name} - ${CbFunctions.name}\n`;
59-
let description = CbFunctions.comment && CbFunctions.comment.summary && CbFunctions.comment.summary.length > 0 ? CbFunctions.comment.summary[0].text : '';
60-
let returndata = "";
61-
let parameterNames = [];
96+
97+
frontMatterVars.data.category = CbProperties.name;
98+
frontMatterVars.data.name = CbFunctions.name;
99+
frontMatterVars.cbbaseinfo.description = CbFunctions.comment && CbFunctions.comment.summary && CbFunctions.comment.summary.length > 0 ? CbFunctions.comment.summary[0].text : ' ';
100+
101+
62102
if (CbFunctions.type && CbFunctions.type.declaration && CbFunctions.type.declaration.signatures) {
63103
CbFunctions.type.declaration.signatures.forEach(signature => {
64104
if (signature.parameters) {
65105
signature.parameters.forEach(param => {
66-
parameterNames.push(`${param.name}: ${param.type.name}`);
106+
frontMatterVars.cbparameters.parameters.push(`${param.name}: ${param.type.name}`);
67107
console.log(`${param.name}: ${param.type.name}`);
68108
});
69109
}
70-
returndata = `Returns: ${signature.type.name}\n`;
110+
frontMatterVars.cbparameters.returndata = signature.type.name;
71111
});
72112
}
73113

74-
const filePath = `${dir}/${CbFunctions.name}.md`;
75-
let originalfileContent = '';
76-
let newFileContent = '';
77-
78-
if (fs.existsSync(filePath)) {
79-
originalfileContent = fs.readFileSync(filePath, 'utf8');
80-
const frontMatterMatch = originalfileContent.match(/^---\n([\s\S]*?)\n---/);
81-
if (frontMatterMatch) {
82-
const frontMatterContent = frontMatterMatch[1];
83-
let newYamlContent = updateFrontmatter(frontMatterContent, { "cblibrary": { "description": description } })
84-
newFileContent = originalfileContent.replace(frontMatterMatch[0], `---\n${newYamlContent}---`);
85-
} else {
86-
const frontMatter = createFrontMatter({ name: CbFunctions.name, description: description });
87-
newFileContent = frontMatter + originalfileContent;
88-
}
89-
fs.writeFileSync(filePath, newFileContent);
90-
} else {
91-
const frontMatter = createFrontMatter({ name: CbFunctions.name, description: description });
92-
newFileContent = frontMatter + `${content}\n${parameterNames.join('\n')}\n${returndata} <CBBaseInfo/>`;
93-
fs.writeFileSync(filePath, newFileContent);
94-
}
114+
115+
const filePath = `${dir}/${frontMatterVars.data.name}.md`;
116+
writeToFile(filePath, frontMatterVars)
117+
95118
});
96119
}
97120
});

Diff for: src/components/CBBaseInfo.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const CBBaseInfo = () => {
1010
return (
1111
<div>
1212
{Object.entries(frontMatter).map(([key, value]) => {
13-
if (key === 'cblibrary') {
13+
if (key === 'cbbaseinfo') {
1414
console.log(`Key: ${key}, Value: ${value}`);
1515

1616
return (

Diff for: src/components/CBParameters.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const CBParameters = () => {
1010
return (
1111
<div>
1212
{Object.entries(frontMatter).map(([key, value]) => {
13-
if (key === 'cblibrary') {
13+
if (key === 'cbparamters') {
1414
console.log(`Key: ${key}, Value: ${value}`);
1515

1616
if (value.parameters) {

0 commit comments

Comments
 (0)