|
1 | 1 | import { readFile } from "fs/promises"; |
| 2 | +import { hyphenToCamelCase } from "./utils/css.js"; |
2 | 3 |
|
3 | 4 | const inputFile = new URL("../../inputfiles/mdn.json", import.meta.url); |
4 | 5 |
|
5 | 6 | // Valid subdirectories for our use case |
6 | 7 | const subdirectories = [ |
7 | 8 | "Web/API/", |
8 | 9 | "WebAssembly/Reference/JavaScript_interface/", |
| 10 | + "Web/CSS/Reference/Properties/", |
9 | 11 | ]; |
10 | 12 |
|
11 | 13 | const paths: Record<string, string[]> = { |
| 14 | + "css-property": ["CSSStyleProperties", "properties", "property"], |
| 15 | + "css-shorthand-property": ["CSSStyleProperties", "properties", "property"], |
12 | 16 | "web-api-instance-property": ["properties", "property"], |
13 | 17 | "web-api-static-property": ["properties", "property"], |
14 | 18 | "web-api-instance-method": ["methods", "method"], |
@@ -49,15 +53,10 @@ function insertComment( |
49 | 53 | slug: string[], |
50 | 54 | summary: string, |
51 | 55 | path: string[], |
| 56 | + name: string, |
52 | 57 | ) { |
53 | | - if (!path.length) { |
54 | | - const iface = ensureLeaf(root, slug); |
55 | | - iface.comment = summary; |
56 | | - } else { |
57 | | - const [ifaceName, memberName] = slug; |
58 | | - const target = ensureLeaf(root, [ifaceName, ...path, memberName]); |
59 | | - target.comment = summary; |
60 | | - } |
| 58 | + const target = ensureLeaf(root, [...slug.slice(0, -1), ...path, name]); |
| 59 | + target.comment = summary; |
61 | 60 | } |
62 | 61 |
|
63 | 62 | function generateComment(summary: string, name: string): string | undefined { |
@@ -91,11 +90,17 @@ export async function generateDescriptions(): Promise<{ |
91 | 90 | if (!slugArr.length || !path) { |
92 | 91 | continue; |
93 | 92 | } |
94 | | - const comment = generateComment(entry.summary, slugArr.at(-1)!); |
| 93 | + const leaf = slugArr.at(-1)!; |
| 94 | + const name = ["css-property", "css-shorthand-property"].includes( |
| 95 | + entry.pageType, |
| 96 | + ) |
| 97 | + ? hyphenToCamelCase(leaf) |
| 98 | + : leaf; |
| 99 | + const comment = generateComment(entry.summary, name); |
95 | 100 | if (!comment) { |
96 | 101 | continue; |
97 | 102 | } |
98 | | - insertComment(results, slugArr, comment, path); |
| 103 | + insertComment(results, slugArr, comment, path, name); |
99 | 104 | } |
100 | 105 | return { interfaces: { interface: results } }; |
101 | 106 | } |
0 commit comments