mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-08 12:52:58 +00:00
docs: better formatting for Node API docs (#1892)
* Sets `"useCodeBlocks": true` * Adds a post-processing script `nodejs/typedoc_post_process.js` that puts the parameter description on the same line as the parameter name, like it is in our Python docs. This makes the text hierarchy clearer in those sections and also makes the sections shorter.
This commit is contained in:
@@ -78,6 +78,7 @@
|
||||
"build-release": "npm run build:release && tsc -b && shx cp lancedb/native.d.ts dist/native.d.ts",
|
||||
"lint-ci": "biome ci .",
|
||||
"docs": "typedoc --plugin typedoc-plugin-markdown --out ../docs/src/js lancedb/index.ts",
|
||||
"postdocs": "node typedoc_post_process.js",
|
||||
"lint": "biome check . && biome format .",
|
||||
"lint-fix": "biome check --write . && biome format --write .",
|
||||
"prepublishOnly": "napi prepublish -t npm",
|
||||
|
||||
@@ -8,5 +8,6 @@
|
||||
"lancedb/native.d.ts:Table"
|
||||
],
|
||||
"useHTMLEncodedBrackets": true,
|
||||
"useCodeBlocks": true,
|
||||
"disableSources": true
|
||||
}
|
||||
|
||||
63
nodejs/typedoc_post_process.js
Normal file
63
nodejs/typedoc_post_process.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
// Read all files in the directory
|
||||
function processDirectory(directoryPath) {
|
||||
fs.readdir(directoryPath, { withFileTypes: true }, (err, files) => {
|
||||
if (err) {
|
||||
return console.error("Unable to scan directory: " + err);
|
||||
}
|
||||
|
||||
files.forEach((file) => {
|
||||
const filePath = path.join(directoryPath, file.name);
|
||||
|
||||
if (file.isDirectory()) {
|
||||
// Recursively process subdirectory
|
||||
processDirectory(filePath);
|
||||
} else if (file.isFile()) {
|
||||
// Read each file
|
||||
fs.readFile(filePath, "utf8", (err, data) => {
|
||||
if (err) {
|
||||
return console.error("Unable to read file: " + err);
|
||||
}
|
||||
|
||||
// Process the file content
|
||||
const processedData = processContents(data);
|
||||
|
||||
// Write the processed content back to the file
|
||||
fs.writeFile(filePath, processedData, "utf8", (err) => {
|
||||
if (err) {
|
||||
return console.error("Unable to write file: " + err);
|
||||
}
|
||||
console.log(`Processed file: ${filePath}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function processContents(contents) {
|
||||
// This changes the parameters section to put the parameter description on
|
||||
// the same line as the bullet with the parameter name and type.
|
||||
return contents.replace(/(## Parameters[\s\S]*?)(?=##|$)/g, (match) => {
|
||||
let lines = match
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
|
||||
.filter((line) => line !== "")
|
||||
.map((line) => {
|
||||
if (line.startsWith("##")) {
|
||||
return line;
|
||||
} else if (line.startsWith("•")) {
|
||||
return "\n*" + line.substring(1);
|
||||
} else {
|
||||
return " " + line;
|
||||
}
|
||||
});
|
||||
return lines.join("\n") + "\n\n";
|
||||
});
|
||||
}
|
||||
|
||||
// Start processing from the root directory
|
||||
processDirectory("../docs/src/js");
|
||||
Reference in New Issue
Block a user