File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed
Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ # cargo-docs
2+
3+ Serve ` cargo doc ` output with a generated index page listing all crates.
4+
5+ ## Usage
6+
7+ ``` bash
8+ cargo doc --workspace --no-deps
9+ http-nu :3001 examples/cargo-docs/serve.nu
10+ ```
11+
12+ Point at docs in a different location:
13+
14+ ``` nu
15+ with-env {DOC_ROOT: "/path/to/target/doc"} {|| http-nu :3001 examples/cargo-docs/serve.nu }
16+ ```
17+
18+ Defaults to ` ./target/doc ` when ` DOC_ROOT ` is not set.
Original file line number Diff line number Diff line change 1+ # Serve cargo doc output
2+ #
3+ # Usage:
4+ # cargo doc --workspace --no-deps
5+ # http-nu :3001 examples/cargo-docs/serve.nu
6+ #
7+ # Set DOC_ROOT to customize the path (defaults to ./target/doc)
8+
9+ use http-nu /html *
10+ use http-nu /router *
11+
12+ let doc_root = ($env .DOC_ROOT ? | default " target/doc" )
13+
14+ # Build an index page listing all documented crates
15+ def index-page [] {
16+ let crates = ls $doc_root
17+ | where type == dir
18+ | each { get name | path basename }
19+ | where {|c | ($doc_root | path join $c " index.html" | path exists ) }
20+ | sort
21+
22+ HTML (HEAD
23+ (META {charset : " utf-8" })
24+ (TITLE " Docs" )
25+ (STYLE {__html : "
26+ body { font-family: system-ui, sans-serif; max-width: 600px; margin: 2rem auto; padding: 0 1rem; }
27+ a { color: #2563eb; text-decoration: none; }
28+ a:hover { text-decoration: underline; }
29+ li { margin: 0.4rem 0; font-family: monospace; }
30+ " })
31+ ) (BODY
32+ (H1 " Crates" )
33+ (UL { $crates | each {|c | LI (A {href : $" /($c )/" } $c ) } })
34+ )
35+ }
36+
37+ {|req |
38+ dispatch $req [
39+ (route {path : " /" } {|req ctx |
40+ index-page
41+ })
42+
43+ (route true {|req ctx |
44+ .static $doc_root $req.path
45+ })
46+ ]
47+ }
You can’t perform that action at this time.
0 commit comments