Skip to content

Commit 4e5a2cd

Browse files
authored
feat: add plugin to generate help.json (#24)
* feat: add help.json plugin * feat: add formName to front matter
1 parent 6199379 commit 4e5a2cd

File tree

30 files changed

+138
-2
lines changed

30 files changed

+138
-2
lines changed
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"label": "Customer Refund",
2+
"label": "Customer",
33
"position": 3,
44
"link": {
55
"type": "generated-index",
6-
"description": "Learn on Customer Refund in SQL Account"
6+
"description": "Learn on Customer in SQL Account"
77
}
88
}

docs/quick-start/customer/customer-aging/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/customer/customer-aging
6+
form_name: TrfmARAging
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/customer/customer-contra/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/customer/customer-contra
6+
form_name: TfmARCT
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/customer/customer-deposit/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/customer/customer-deposit
6+
form_name: TfmARDP
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/customer/customer-due-document/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/customer/customer-due-document
6+
form_name: TrfmARDueDocument
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/customer/customer-payment/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/customer/customer-payment
6+
form_name: TfmARPM
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/customer/customer-refund/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/customer/customer-refund
6+
form_name: TfmARCF
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/customer/customer-statement/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/customer/customer-statement
6+
form_name: TrfmARStatement
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/gl/cash-book-entry/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/gl/cash-book-entry
6+
form_name: TfmGLCB
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/gl/journal-entry/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/gl/journal-entry
6+
form_name: TfmGLJE
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/purchase/cash-purchase/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/purchase/cash-purchase
6+
form_name: TfmPHCP
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/purchase/goods-received/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/purchase/goods-received
6+
form_name: TfmPHGR
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/purchase/purchase-cancelled-note/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/purchase/purchase-cancelled-note
6+
form_name: TfmPHPC
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/purchase/purchase-debit-note/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/purchase/purchase-debit-note
6+
form_name: TfmPHSD
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/purchase/purchase-invoice/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/purchase/purchase-invoice
6+
form_name: TfmPHPI
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/purchase/purchase-order/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/purchase/purchase-order
6+
form_name: TfmPHPO
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/purchase/purchase-request/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/purchase/purchase-request
6+
form_name: TfmPHPQ
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/purchase/purchase-returned/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/purchase/purchase-returned
6+
form_name: TfmPHSC
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/sales/cash-sales/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/sales/cash-sales
6+
form_name: TfmSLCS
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/sales/sales-cancelled-note/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/sales/sales-cancelled-note
6+
form_name: TfmSLCC
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/sales/sales-credit-note/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/sales/sales-credit-note
6+
form_name: TfmSLCN
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/sales/sales-debit-note/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/sales/sales-debit-note
6+
form_name: TfmSLDN
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/sales/sales-delivery-order/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/sales/sales-delivery-order
6+
form_name: TfmSLDO
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/sales/sales-invoice/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/sales/sales-invoice
6+
form_name: TfmSLIV
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/sales/sales-order/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/sales/sales-order
6+
form_name: TfmSLSO
67
---
78

89
import {TOC} from '@src/components/toc.js';

docs/quick-start/sales/sales-quotation/intro.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sidebar_position: 1
33
title: Table of contents
44
hide_title: true
55
slug: /quick-start/sales/sales-quotation
6+
form_name: TfmSLQT
67
---
78

89
import {TOC} from '@src/components/toc.js';

docusaurus.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ const config = {
3131
},
3232
plugins: [
3333
"plugin-image-zoom",
34+
[
35+
path.resolve(__dirname, 'plugins/generate-help-json'),
36+
{
37+
docsPath: 'docs',
38+
outputPath: '/'
39+
},
40+
],
3441
function aliasPlugin(context, options) {
3542
return {
3643
name: 'alias-plugin',

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@easyops-cn/docusaurus-search-local": "^0.40.1",
2121
"@mdx-js/react": "^3.0.0",
2222
"clsx": "^2.0.0",
23+
"gray-matter": "^4.0.3",
2324
"plugin-image-zoom": "github:flexanalytics/plugin-image-zoom",
2425
"prism-react-renderer": "^2.3.0",
2526
"qrcode.react": "^4.2.0",

plugins/generate-help-json/index.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const matter = require('gray-matter');
4+
5+
function getAllMarkdownFiles(dir, fileList = []) {
6+
const files = fs.readdirSync(dir);
7+
8+
files.forEach(file => {
9+
const filePath = path.join(dir, file);
10+
if (fs.statSync(filePath).isDirectory()) {
11+
getAllMarkdownFiles(filePath, fileList);
12+
} else if (file.endsWith('.md') || file.endsWith('.mdx')) {
13+
fileList.push(filePath);
14+
}
15+
});
16+
17+
return fileList;
18+
}
19+
20+
module.exports = function(context, options) {
21+
return {
22+
name: 'generate-help-json',
23+
24+
async postBuild({ siteConfig, routesPaths, outDir }) {
25+
let docsDir;
26+
docsDir = path.join(context.siteDir, options.docsPath);
27+
if (!fs.existsSync(docsDir)) {
28+
console.warn(`Warning: Docs directory not found: ${docsDir}`);
29+
return;
30+
}
31+
32+
const markdownFiles = getAllMarkdownFiles(docsDir);
33+
const helpData = [];
34+
const formNameMap = {};
35+
const duplicates = [];
36+
37+
for (const fullPath of markdownFiles) {
38+
const filePath = path.relative(docsDir, fullPath);
39+
const fileContent = fs.readFileSync(fullPath, 'utf8');
40+
41+
try {
42+
const { data: frontMatter } = matter(fileContent);
43+
44+
if (frontMatter && frontMatter.form_name) {
45+
let permalink = frontMatter.slug;
46+
if (!permalink) {
47+
console.warn(`WARNING: No slug found for ${filePath}`);
48+
}
49+
50+
if (formNameMap[frontMatter.form_name]) {
51+
duplicates.push({
52+
form_name: frontMatter.form_name,
53+
existingFile: formNameMap[frontMatter.form_name],
54+
newFile: filePath
55+
});
56+
57+
console.warn(`WARNING: Duplicate form_name "${frontMatter.form_name}" found in:`);
58+
console.warn(` 1. ${formNameMap[frontMatter.form_name]}`);
59+
console.warn(` 2. ${filePath}`);
60+
console.warn(` Using the first occurrence for help.json`);
61+
62+
continue;
63+
}
64+
65+
formNameMap[frontMatter.form_name] = filePath;
66+
67+
helpData.push({
68+
Name: frontMatter.form_name,
69+
Path: permalink
70+
});
71+
}
72+
} catch (err) {
73+
console.warn(`Error processing ${filePath}:`, err);
74+
}
75+
}
76+
77+
let targetDir = outDir;
78+
const outputPath = path.join(outDir, options.outputPath);
79+
80+
if (fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory()) {
81+
targetDir = outputPath;
82+
}
83+
84+
const helpJsonPath = path.join(targetDir, 'help.json');
85+
fs.writeFileSync(
86+
helpJsonPath,
87+
JSON.stringify(helpData, null, 2)
88+
);
89+
90+
if (duplicates.length > 0) {
91+
const duplicatesPath = path.join(targetDir, 'help-duplicates.json');
92+
fs.writeFileSync(
93+
duplicatesPath,
94+
JSON.stringify(duplicates, null, 2)
95+
);
96+
console.warn(`Found ${duplicates.length} duplicate form_name entries. See help-duplicates.json for details.`);
97+
}
98+
99+
console.log(`Generated HELP.json with ${helpData.length} entries in ${targetDir}`);
100+
}
101+
};
102+
};

0 commit comments

Comments
 (0)