Skip to content
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

add: sort on function names in the docs #6526

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 39,19 @@ pub fn generate_docs_html(root_file: PathBuf, build_dir: &Path) {
// Otherwise, include as string literal

struct Assets<S: AsRef<str>> {
search_js: S,
aux_js: S,
styles_css: S,
raw_template_html: S,
}

#[cfg(not(debug_assertions))]
let assets = {
let search_js = include_str!("./static/search.js");
let aux_js = include_str!("./static/aux.js");
let styles_css = include_str!("./static/styles.css");
let raw_template_html = include_str!("./static/index.html");

Assets {
search_js,
aux_js,
styles_css,
raw_template_html,
}
Expand All @@ -64,12 64,12 @@ pub fn generate_docs_html(root_file: PathBuf, build_dir: &Path) {
let static_dir = Path::new(workspace_dir).join("crates/docs/src/static");

// Read the assets from the filesystem
let search_js = fs::read_to_string(static_dir.join("search.js")).unwrap();
let aux_js = fs::read_to_string(static_dir.join("aux.js")).unwrap();
let styles_css = fs::read_to_string(static_dir.join("styles.css")).unwrap();
let raw_template_html = fs::read_to_string(static_dir.join("index.html")).unwrap();

Assets {
search_js,
aux_js,
styles_css,
raw_template_html,
}
Expand All @@ -78,7 78,7 @@ pub fn generate_docs_html(root_file: PathBuf, build_dir: &Path) {
// Write CSS, JS, and favicon
// (The HTML requires more work!)
for (file, contents) in [
("search.js", assets.search_js),
("aux.js", assets.aux_js),
("styles.css", assets.styles_css),
] {
let dir = build_dir.join(file);
Expand Down
13 changes: 13 additions & 0 deletions crates/docs/src/static/search.js → crates/docs/src/static/aux.js
Original file line number Diff line number Diff line change
@@ -1,7 1,20 @@
(() => {
let sidebar = document.getElementById("sidebar-nav");
let sortButton = document.getElementById("sort-button");
let searchBox = document.getElementById("module-search");

if (sortButton != null) {
function sort() {
[...sidebar.querySelectorAll(".sidebar-sub-entries")]
.forEach(entry =>
[...entry.querySelectorAll("a")]
.sort((a, b) => a.innerText > b.innerText)
.forEach(n => entry.appendChild(n)));

}
sortButton.onclick = sort;
}

if (searchBox != null) {
function search() {
let text = searchBox.value.toLowerCase(); // Search is case-insensitive.
Expand Down
13 changes: 9 additions & 4 deletions crates/docs/src/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 7,7 @@
<!-- <meta name="description" content="TODO populate this based on the module's description"> -->
<meta name="viewport" content="width=device-width">
<base href="<!-- base -->">
<script type="text/javascript" src="search.js" defer></script>
<script type="text/javascript" src="aux.js" defer></script>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="/favicon.svg">
<!-- Safari ignores rel="icon" and only respects rel="mask-icon". It will render the SVG with
Expand All @@ -19,9 19,14 @@

<body>
<nav id="sidebar-nav">
<input id="module-search" aria-labelledby="search-link" type="text" placeholder="Search" />
<label for="module-search" id="search-link"><span id="search-link-text">Search</span> <span
id="search-link-hint">(press <span id="search-shortcut-key">s</span>)</span></label>
<div id="toolbar">
<input id="module-search" aria-label="Run a search on the references" type="search" placeholder="Search (press s)" >
<button id="sort-button">Sort
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-sort-down" viewBox="0 0 16 16">
<path d="M3.5 2.5a.5.5 0 0 0-1 0v8.793l-1.146-1.147a.5.5 0 0 0-.708.708l2 1.999.007.007a.497.497 0 0 0 .7-.006l2-2a.5.5 0 0 0-.707-.708L3.5 11.293zm3.5 1a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5M7.5 6a.5.5 0 0 0 0 1h5a.5.5 0 0 0 0-1zm0 3a.5.5 0 0 0 0 1h3a.5.5 0 0 0 0-1zm0 3a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1z"/>
</svg>
</button>
</div>
<div class="module-links">
<!-- Module links -->
</div>
Expand Down
25 changes: 13 additions & 12 deletions crates/docs/src/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 439,10 @@ pre>samp {
display: none !important;
}

#module-search:placeholder-shown {
padding: 0;
opacity: 0;
height: 0;
}

#module-search,
#module-search:focus {
opacity: 1;
padding: 12px 16px;
height: 48px;
}

/* Show the "Search" label link when the text input has a placeholder */
Expand All @@ -464,16 457,14 @@ pre>samp {

#module-search {
display: block;
box-sizing: border-box;
width: 100%;
box-sizing: border-box;
font-size: 18px;
line-height: 18px;
margin-top: 6px;
border: none;
color: var(--faded-color);
background-color: var(--code-bg);
font-family: var(--font-serif);
flex-grow: 1;
}

#module-search::placeholder {
Expand All @@ -488,7 479,6 @@ pre>samp {
font-size: 18px;
line-height: 18px;
padding: 12px 16px;
height: 48px;
cursor: pointer;
}

Expand All @@ -497,7 487,6 @@ pre>samp {
}

#search-link-hint {
margin-left: 1em;
opacity: 0.6;
}

Expand All @@ -508,6 497,18 @@ pre>samp {
font-style: normal;
line-height: 15px;
}
#toolbar {
display: flex;
justify-content: start;
margin-top: 6px;
}
#sort-button {
margin-left: 8px;
border-radius: 2px;
border-color: var(--border-color);
color: var(--text-color);
background-color: var(--body-bg-color);
}

.builtins-tip {
padding: 1em;
Expand Down