Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit bec24b1

Browse files
committed
feat: migrate populate-details script to the new data source
1 parent 5b8044e commit bec24b1

File tree

1 file changed

+58
-24
lines changed

1 file changed

+58
-24
lines changed

scripts/populate-details.js

+58-24
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,79 @@
11
const { writeFileSync } = require('fs')
22
const path = require('path')
33

4-
const standards = require('../data/standards.json')
4+
const checks = require('../data/checks.json')
55

6-
const addContent = (content) => {
7-
if (typeof content === 'string') {
8-
return content
6+
const addImplementationDetails = (check) => {
7+
if (!check.implementation_type) {
8+
return ''
99
}
10+
let content = `- Implementation Details: It is ${check.implementation_type}`
11+
if (check.implementation_details_reference) {
12+
content += ` ([details](${check.implementation_details_reference})).`
13+
}
14+
return content
15+
}
16+
17+
const addContent = (title, description, url) => {
18+
if (!description && !url) {
19+
return ''
20+
}
21+
22+
if (url) {
23+
return `- ${title}: [${description}](${url})`
24+
}
25+
26+
return `- ${title}: ${description}`
27+
}
1028

11-
return `[${content.description}](${content.url})`
29+
const renderDetails = (check) => {
30+
const implementationDetails = addImplementationDetails(check)
31+
const mitreDetails = addContent('Mitre', check.mitre_description, check.mitre_url)
32+
const sourcesDetails = addContent('Sources', check.sources_description, check.sources_url)
33+
const howToDetails = addContent('How To', check.how_to_description, check.how_to_url)
34+
let content = '## Details\n'
35+
content += `- Implementation Status: ${check.implementation_status}\n`
36+
if (implementationDetails) {
37+
content += `${implementationDetails}\n`
38+
}
39+
content += `- C-SCRM: ${check.is_c_scrm}\n`
40+
content += `- Priority Group: ${check.priority_group}\n`
41+
if (mitreDetails) {
42+
content += `${mitreDetails}\n`
43+
}
44+
if (sourcesDetails) {
45+
content += `${sourcesDetails}\n`
46+
}
47+
if (howToDetails) {
48+
content += `${howToDetails}\n`
49+
}
50+
content += `- Created at ${check.created_at}\n`
51+
content += `- Updated at ${check.updated_at}\n`
52+
return content
1253
}
54+
1355
// Prepare the markdown files
14-
standards.forEach((item, index) => {
56+
checks.forEach((check, index) => {
1557
const fileContent = `---
1658
sidebar_position: ${index + 1}
17-
id: ${item.slug}
18-
title: ${item.title}
19-
slug: /details/${item.slug}
59+
id: ${check.id}
60+
title: ${check.title}
61+
slug: /details/${check.code_name}
2062
---
2163
22-
# ${item.title}
64+
# ${check.title}
2365
2466
## Use Case
25-
26-
- Incubating: ${item.incubating}
27-
- Active: ${item.active}
28-
- Retiring: ${item.retiring}
67+
- Incubating: ${check.level_incubating_status}
68+
- Active: ${check.level_active_status}
69+
- Retiring: ${check.level_retiring_status}
2970
3071
## Description
3172
32-
${item.description}
33-
34-
## Details
35-
36-
- C-SCRM: ${item['c-scrm']}
37-
- Priority Group: ${item['priority group']}
38-
- Mitre: ${addContent(item.mitre)}
39-
- Sources: ${addContent(item.sources)}
40-
- How To: ${addContent(item['how to'])}
73+
${check.description}
4174
75+
${renderDetails(check)}
4276
`
43-
const detination = path.join(process.cwd(), `docs/details/${item.slug}.mdx`)
77+
const detination = path.join(process.cwd(), `docs/details/${check.code_name}.mdx`)
4478
writeFileSync(detination, fileContent)
4579
})

0 commit comments

Comments
 (0)