|
1 | 1 | const { writeFileSync } = require('fs')
|
2 | 2 | const path = require('path')
|
3 | 3 |
|
4 |
| -const standards = require('../data/standards.json') |
| 4 | +const checks = require('../data/checks.json') |
5 | 5 |
|
6 |
| -const addContent = (content) => { |
7 |
| - if (typeof content === 'string') { |
8 |
| - return content |
| 6 | +const addImplementationDetails = (check) => { |
| 7 | + if (!check.implementation_type) { |
| 8 | + return '' |
9 | 9 | }
|
| 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 | +} |
10 | 28 |
|
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 |
12 | 53 | }
|
| 54 | + |
13 | 55 | // Prepare the markdown files
|
14 |
| -standards.forEach((item, index) => { |
| 56 | +checks.forEach((check, index) => { |
15 | 57 | const fileContent = `---
|
16 | 58 | 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} |
20 | 62 | ---
|
21 | 63 |
|
22 |
| -# ${item.title} |
| 64 | +# ${check.title} |
23 | 65 |
|
24 | 66 | ## 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} |
29 | 70 |
|
30 | 71 | ## Description
|
31 | 72 |
|
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} |
41 | 74 |
|
| 75 | +${renderDetails(check)} |
42 | 76 | `
|
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`) |
44 | 78 | writeFileSync(detination, fileContent)
|
45 | 79 | })
|
0 commit comments