forked from denoland/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(reference): generate HTML files with the deno/doc jsr packag…
…e instead of CLI (denoland#1146)
- Loading branch information
Showing
10 changed files
with
501 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { HrefResolver, ShortPath } from "@deno/doc"; | ||
import { dirname, join } from "@std/path"; | ||
|
||
export function renderMarkdown( | ||
md: string, | ||
titleOnly: boolean, | ||
_filePath: ShortPath | undefined, | ||
anchorizer: (content: string, depthLevel: number) => string, | ||
): string | undefined { | ||
return md; | ||
} | ||
|
||
export function stripMarkdown(md: string): string { | ||
return md; | ||
} | ||
|
||
export const hrefResolver: HrefResolver = { | ||
resolvePath(_current, _target, defaultResolve) { | ||
let path = defaultResolve(); | ||
|
||
if (path.endsWith("index.html")) { | ||
path = path.slice(0, -"index.html".length); | ||
} else if (path.endsWith(".html")) { | ||
path = path.slice(0, -".html".length); | ||
} | ||
|
||
return path; | ||
}, | ||
}; | ||
|
||
export async function writeFiles(root: string, files: Record<string, string>) { | ||
await Deno.remove(root, { recursive: true }); | ||
|
||
await Promise.all( | ||
Object.entries(files).map(async ([path, content]) => { | ||
const joined = join(root, path); | ||
|
||
await Deno.mkdir(dirname(joined), { recursive: true }); | ||
await Deno.writeTextFile(joined, content); | ||
}), | ||
); | ||
|
||
console.log(`Written ${Object.keys(files).length} files`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { doc, generateHtml } from "@deno/doc"; | ||
import { | ||
hrefResolver, | ||
renderMarkdown, | ||
stripMarkdown, | ||
writeFiles, | ||
} from "./common.ts"; | ||
import categoryDocs from "./deno-categories.json" with { type: "json" }; | ||
|
||
const url = import.meta.resolve("./types/deno.d.ts"); | ||
|
||
console.log("Generating doc nodes..."); | ||
|
||
const nodes = await doc(url, { includeAll: true }); | ||
|
||
console.log("Generating html files..."); | ||
|
||
const files = await generateHtml({ [url]: nodes }, { | ||
packageName: "Deno", | ||
categoryDocs, | ||
disableSearch: true, | ||
hrefResolver, | ||
usageComposer: { | ||
singleMode: true, | ||
compose(_currentResolve, _usageToMd) { | ||
return new Map(); | ||
}, | ||
}, | ||
markdownRenderer: renderMarkdown, | ||
markdownStripper: stripMarkdown, | ||
}); | ||
|
||
await writeFiles("./gen/deno", files); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
{ | ||
"nodeModulesDir": true, | ||
"lock": false, // TODO(@crowlKats): remove when 2.0 releases | ||
"nodeModulesDir": "auto", | ||
"imports": { | ||
"@b-fuze/deno-dom": "jsr:@b-fuze/deno-dom@^0.1.47", | ||
"@std/async": "jsr:@std/async@^0.224.2", | ||
"@std/fs": "jsr:@std/fs@^1.0.1", | ||
"@std/media-types": "jsr:@std/media-types@^0.224.1", | ||
"@std/path": "jsr:@std/path@^0.225.1", | ||
"@std/yaml": "jsr:@std/yaml@^1.0.3", | ||
"@deno/doc": "jsr:@deno/[email protected]", | ||
"@types/node": "npm:@types/[email protected]", | ||
"browserslist": "npm:[email protected]", | ||
"dax": "jsr:@david/dax@^0.40.1", | ||
"lightningcss": "npm:[email protected]", | ||
"ts-morph": "jsr:@ts-morph/[email protected]" | ||
}, | ||
"tasks": { | ||
"types:deno": "deno run --allow-read --allow-write --allow-run --allow-env --allow-sys deno-docs.ts", | ||
"types:node": "deno run --allow-read --allow-write=. --allow-env --allow-sys node-docs.ts", | ||
"types:deno": "deno run --allow-read --allow-write --allow-run --allow-env --allow-sys deno-types.ts", | ||
"types:node": "deno run --allow-read --allow-write=. --allow-env --allow-sys node-types.ts", | ||
"types": "deno task types:deno && deno task types:node", | ||
"doc:deno": "mkdir -p gen/deno && DENO_INTERNAL_HTML_DOCS=deno deno doc --html --name=Deno --category-docs=deno-categories.json --output=gen/deno --strip-trailing-html types/deno.d.ts", | ||
"doc:web": "mkdir -p gen/web && DENO_INTERNAL_HTML_DOCS=deno deno doc --html --name=Web --category-docs=web-categories.json --output=gen/web --strip-trailing-html types/web.d.ts", | ||
"doc:node": "mkdir -p gen/node && DENO_INTERNAL_HTML_DOCS=node deno doc --html --name=Node --output=gen/node --symbol-redirect-map=node-symbol-map.json --default-symbol-map=node-default-map.json --strip-trailing-html types/node/[!_]*", | ||
"doc:deno": "mkdir -p gen/deno && deno run --allow-read --allow-write --allow-env --allow-net deno-doc.ts", | ||
"doc:web": "mkdir -p gen/web && deno run --allow-read --allow-write --allow-env --allow-net web-doc.ts", | ||
"doc:node": "mkdir -p gen/node && deno run --allow-read --allow-write --allow-env --allow-net node-doc.ts", | ||
"doc": "deno task doc:deno && deno task doc:web && deno task doc:node" | ||
}, | ||
"exports": { | ||
|
Oops, something went wrong.