-
Notifications
You must be signed in to change notification settings - Fork 439
API Descriptions Update #1940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API Descriptions Update #1940
Changes from 18 commits
6bdf491
5d9b1b3
de0d117
39d5719
df3631e
e9c9379
8e74526
40e5317
d7c6297
51bc9cb
af54369
1bb475e
2695f20
5a5cbdd
66f5156
61d4fde
c06f21b
c110920
ed6f97f
afbb9e1
c854ebb
17ded6a
4c87230
47bd142
5933dd8
0ce76d5
6ff87d9
3b416ad
b8d9480
ad92293
5d58288
c1ad6ea
8402152
445fa89
4a9adfa
28bfccf
faca57f
ba429e0
ee545fc
6232f92
bfbfcbb
8e5651c
46ed6ae
4f02639
dea3437
afeef87
8f1ca09
499e76e
156c52d
4f48c8d
1d050d3
bff43b4
b9d231b
fe739ba
6f7c6cf
acc701a
c0b174b
aeb2d85
65213fe
26b2047
d899655
4c51aa9
bb2d85a
1f4f5f1
e4a1eb4
6166a1f
3f18c23
7289d10
2dbb91b
1693dbd
f2ab8d1
2a3ead7
5894b0d
2710f19
f18a444
f9d9bf8
5ec693d
8868c1d
b3cf7d6
4008574
9ed120d
6bd4822
6ba9eea
d2d7817
0e5b7c8
9e1b9de
56935fe
aa1d888
434acbf
d960681
79d2845
22cb393
3365a61
1ba1b36
1a888c7
a220c15
eea3294
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "mdn-content"] | ||
path = mdn-content | ||
url = https://github.com/mdn/content.git |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
], | ||
"scripts": { | ||
"build": "tsc && node ./lib/build.js", | ||
"generate": "tsc && node ./lib/generateDescriptions.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be part of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can do that :) |
||
"baseline-accept": "cpx \"generated\\**\" baselines\\", | ||
"lint": "eslint --max-warnings 0 src deploy/*.js && tsc -p deploy/jsconfig.json", | ||
"lint-fix": "eslint --max-warnings 0 src deploy/*.js --fix", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { promises as fs } from "fs"; | ||
Bashamega marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import * as path from "path"; | ||
import { fileURLToPath } from "url"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
Bashamega marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function extractSummary(markdown: string) { | ||
// Remove frontmatter (--- at the beginning) | ||
markdown = markdown.replace(/^---[\s\S]+?---\n/, ""); | ||
|
||
// Split into lines and find the first meaningful paragraph | ||
const lines = markdown.split("\n"); | ||
for (const line of lines) { | ||
const trimmed = line.trim(); | ||
if ( | ||
trimmed && | ||
!trimmed.startsWith("#") && | ||
!trimmed.startsWith(">") && | ||
!trimmed.startsWith("{{") | ||
) { | ||
// Remove bold (**text**), inline code (`text`), and links ([text](url)) | ||
return trimmed | ||
.replace(/\*\*(.*?)\*\*/g, "$1") // Remove bold | ||
.replace(/`(.*?)`/g, "$1") // Remove inline code | ||
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") // Remove links | ||
.replace(/\{\{[^()]+\("([^"]+)"\)\}\}/g, "$1"); | ||
} | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
async function getFolders(dirPath: string) { | ||
try { | ||
const entries = await fs.readdir(dirPath, { withFileTypes: true }); | ||
const folders = entries | ||
.filter((entry) => entry.isDirectory()) | ||
.map((entry) => path.join(dirPath, entry.name)); | ||
return folders; | ||
} catch (error) { | ||
console.error("Error reading directories:", error); | ||
return []; | ||
} | ||
} | ||
|
||
async function getIndexMdContents(folders: string[]) { | ||
const results: { [key: string]: string } = {}; | ||
|
||
for (const folder of folders) { | ||
const indexPath = path.join(folder, "index.md"); | ||
|
||
try { | ||
const content = await fs.readFile(indexPath, "utf-8"); | ||
const titleMatch = content.match(/title: (.*)/); | ||
const title = titleMatch ? titleMatch[1] : ""; | ||
const summary = extractSummary(content); | ||
results[title] = summary; | ||
} catch { | ||
// Ignore missing index.md files | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
async function generateDescription() { | ||
const basePath = path.resolve( | ||
__dirname, | ||
"../mdn-content/files/en-us/web/api", | ||
); | ||
const folders = await getFolders(basePath); | ||
const data = await getIndexMdContents(folders); | ||
// Write to JSON file | ||
await fs.writeFile( | ||
path.resolve(__dirname, "../inputfiles/mdn/") + "/apiDescriptions.json", | ||
JSON.stringify(data, null, 2), | ||
"utf-8", | ||
); | ||
} | ||
|
||
await generateDescription(); |
Uh oh!
There was an error while loading. Please reload this page.