Skip to content

Rustdoc Index Page should use not use hard-coded values #144147

@TroyKomodo

Description

@TroyKomodo

Code

If we include this script on the top level index.html the page no longer needs to be updated when additional crates are generated.

<script src="./crates.js"></script>
<script>
const ul = document.querySelector("ul.all-items");

for (const crate of window.ALL_CRATES) {
    const li = document.createElement("li");
    const a = document.createElement("a");
    a.href = `${crate}/index.html`;
    a.textContent = crate;
    li.appendChild(a);
    ul.appendChild(li);
}
<script>
<body class="rustdoc mod sys">
    <!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]-->
    <nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a
            class="logo-container" href="./index.html"><img class="rust-logo"
                src="./static.files/rust-logo-9a9549ea.svg" alt=""></a></nav>
    <nav class="sidebar">
        <div class="sidebar-crate"><a class="logo-container" href="./index.html"><img class="rust-logo"
                    src="./static.files/rust-logo-9a9549ea.svg" alt="logo"></a>
            <h2><a href="./index.html">Rustdoc</a><span class="version">1.88.0</span></h2>
        </div>
        <div class="version">(6b00bc388 2025-06-23)</div>
    </nav>
    <div class="sidebar-resizer"></div>
    <main>
        <div class="width-limiter"><rustdoc-search></rustdoc-search>
            <section id="main-content" class="content">
                <h1>List of all crates</h1>
                <ul class="all-items">
                    <li><a href="c/index.html">c</a></li> <!-- remove this part and insert the script above here. -->
                </ul>
            </section>
        </div>
    </main>
</body>

Version

rustdoc 1.88.0 (6b00bc388 2025-06-23)
binary: rustdoc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions