New docs template

This commit is contained in:
Anthony Bullard 2024-12-15 08:55:15 -06:00
parent 8f2ff5158d
commit 11e736f3e8
No known key found for this signature in database
3 changed files with 556 additions and 480 deletions

View file

@ -1,6 +1,7 @@
<!doctype html>
<html lang="en">
<head>
<head>
<meta charset="utf-8" />
<!-- Page title -->
<!-- <meta name="description" content="TODO populate this based on the module's description"> -->
@ -14,94 +15,98 @@
-->
<link rel="mask-icon" href="/favicon.svg" color="#7d59dd" />
<!-- Prefetch links -->
</head>
</head>
<body>
<body>
<nav id="sidebar-nav">
<div class="pkg-and-logo">
<a class="logo" href="/" aria-labelledby="logo-link">
<svg viewBox="0 -6 51 58" fill="none" xmlns="http://www.w3.org/2000/svg" aria-labelledby="logo-link"
role="img">
<title id="logo-link">Return to Roc packages</title>
<polygon role="presentation"
points="0,0 23.8834,3.21052 37.2438,19.0101 45.9665,16.6324 50.5,22 45,22 44.0315,26.3689 26.4673,39.3424 27.4527,45.2132 17.655,53 23.6751,22.7086" />
</svg>
</a>
<!-- Package Name -->
<button class="menu-toggle">
<svg viewBox="0 0 72 72" id="emoji" xmlns="http://www.w3.org/2000/svg" fill="currentcolor">
<g id="SVGRepo_iconCarrier">
<g id="color"></g>
<g id="hair"></g>
<g id="skin"></g>
<g id="skin-shadow"></g>
<g id="line">
<line x1="16" x2="56" y1="26" y2="26" fill="none" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2">
</line>
<line x1="16" x2="56" y1="36" y2="36" fill="none" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2">
</line>
<line x1="16" x2="56" y1="46" y2="46" fill="none" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2">
</line>
</g>
</g>
</svg>
</button>
</div>
<div class="module-links">
<!-- Module links -->
</div>
</nav>
<div class="header-start-extension">
<!-- if the window gets big, this extends the purple bar on the top header to the left edge of the window -->
</div>
<header class="top-header">
<div class="pkg-and-logo">
<a class="logo" href="/" aria-labelledby="logo-link">
<svg
viewBox="0 -6 51 58"
fill="none"
xmlns="http://www.w3.org/2000/svg"
aria-labelledby="logo-link"
role="img"
>
<title id="logo-link">Return to Roc packages</title>
<polygon
role="presentation"
points="0,0 23.8834,3.21052 37.2438,19.0101 45.9665,16.6324 50.5,22 45,22 44.0315,26.3689 26.4673,39.3424 27.4527,45.2132 17.655,53 23.6751,22.7086"
/>
</svg>
</a>
<!-- Package Name -->
</div>
<main>
<form id="module-search-form">
<input
id="module-search"
aria-labelledby="search-label"
type="text"
placeholder="Search"
role="combobox"
aria-autocomplete="list"
aria-expanded="false"
aria-controls="search-type-ahead"
/>
<label for="module-search" id="search-label"
>(press
<span id="search-shortcut-key" aria-hidden="true">s</span
>)</label
>
<button class="menu-toggle">
<svg viewBox="0 0 72 72" id="emoji" xmlns="http://www.w3.org/2000/svg" fill="currentcolor">
<g id="SVGRepo_iconCarrier">
<g id="color"></g>
<g id="hair"></g>
<g id="skin"></g>
<g id="skin-shadow"></g>
<g id="line">
<line x1="16" x2="56" y1="26" y2="26" fill="none" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2">
</line>
<line x1="16" x2="56" y1="36" y2="36" fill="none" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2">
</line>
<line x1="16" x2="56" y1="46" y2="46" fill="none" stroke="currentColor"
stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2">
</line>
</g>
</g>
</svg>
</button>
<input id="module-search" aria-labelledby="search-label" type="text"
placeholder="Search <!-- Package Name String -->" role="combobox" aria-autocomplete="list"
aria-expanded="false" aria-controls="search-type-ahead" />
<label for="module-search" id="search-label">(press
<span id="search-shortcut-key" aria-hidden="true">s</span>)</label>
<!-- Magnifying Glass icon -->
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
class="search-icon"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="24px"
height="24px"
viewBox="0 0 512 512"
xml:space="preserve"
>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" class="search-icon"
xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 512 512"
xml:space="preserve">
<g>
<path
d="M449.803,62.197C408.443,20.807,353.85-0.037,299.646-0.006C245.428-0.037,190.85,20.807,149.49,62.197
<path d="M449.803,62.197C408.443,20.807,353.85-0.037,299.646-0.006C245.428-0.037,190.85,20.807,149.49,62.197
C108.1,103.557,87.24,158.15,87.303,212.338c-0.047,37.859,10.359,75.766,30.547,109.359L15.021,424.525
c-20.016,20.016-20.016,52.453,0,72.469c20,20.016,52.453,20.016,72.453,0L190.318,394.15
c33.578,20.203,71.5,30.594,109.328,30.547c54.203,0.047,108.797-20.797,150.156-62.188
c41.375-41.359,62.234-95.938,62.188-150.172C512.053,158.15,491.178,103.557,449.803,62.197z M391.818,304.541
c-25.547,25.531-58.672,38.125-92.172,38.188c-33.5-0.063-66.609-12.656-92.188-38.188c-25.531-25.578-38.125-58.688-38.188-92.203
c0.063-33.484,12.656-66.609,38.188-92.172c25.578-25.531,58.688-38.125,92.188-38.188c33.5,0.063,66.625,12.656,92.188,38.188
c25.531,25.563,38.125,58.688,38.188,92.172C429.959,245.854,417.365,278.963,391.818,304.541z"
></path>
c25.531,25.563,38.125,58.688,38.188,92.172C429.959,245.854,417.365,278.963,391.818,304.541z"></path>
</g>
</svg>
<ul
id="search-type-ahead"
role="listbox"
aria-label="Search Results"
class="hidden"
>
<ul id="search-type-ahead" role="listbox" aria-label="Search Results" class="hidden">
<!-- Search Type Ahead -->
</ul>
</form>
</header>
<div class="header-end-extension">
<!-- if the window gets big, this extends the purple bar on the top header to the right edge of the window -->
</div>
<main>
<!-- Module Docs -->
</main>
<footer>
<p>Made by people who like to make nice things.</p>
</footer>
</body>
</main>
</body>
</html>

View file

@ -28,7 +28,7 @@
let topSearchResultListItem = undefined;
// Hide the results whenever anyone clicks outside the search results.
window.addEventListener("click", function(event) {
window.addEventListener("click", function (event) {
if (!searchForm?.contains(event.target)) {
searchTypeAhead.classList.add("hidden");
}
@ -40,19 +40,28 @@
case "ArrowDown": {
event.preventDefault();
const focused = document.querySelector("#search-type-ahead > li:not([class*='hidden']) > a:focus");
const focused = document.querySelector(
"#search-type-ahead > li:not([class*='hidden']) > a:focus",
);
// Find the next element to focus.
let nextToFocus = focused?.parentElement?.nextElementSibling;
while (nextToFocus != null && nextToFocus.classList.contains("hidden")) {
while (
nextToFocus != null &&
nextToFocus.classList.contains("hidden")
) {
nextToFocus = nextToFocus.nextElementSibling;
}
if (nextToFocus == null) {
// If none of the links were focused, focus the first one.
// Also if we've reached the last one in the list, wrap around to the first.
document.querySelector("#search-type-ahead > li:not([class*='hidden']) > a")?.focus();
document
.querySelector(
"#search-type-ahead > li:not([class*='hidden']) > a",
)
?.focus();
} else {
nextToFocus.querySelector("a").focus();
}
@ -62,11 +71,16 @@
case "ArrowUp": {
event.preventDefault();
const focused = document.querySelector("#search-type-ahead > li:not([class*='hidden']) > a:focus");
const focused = document.querySelector(
"#search-type-ahead > li:not([class*='hidden']) > a:focus",
);
// Find the next element to focus.
let nextToFocus = focused?.parentElement?.previousElementSibling;
while (nextToFocus != null && nextToFocus.classList.contains("hidden")) {
while (
nextToFocus != null &&
nextToFocus.classList.contains("hidden")
) {
nextToFocus = nextToFocus.previousElementSibling;
}
@ -97,7 +111,7 @@
searchTypeAhead.querySelectorAll("li").forEach((entry) => {
const entryModule = entry
.querySelector(".type-ahead-module-name")
.textContent.toLowerCase()
.textContent.toLowerCase();
const entryName = entry
.querySelector(".type-ahead-def-name")
.textContent.toLowerCase();
@ -106,9 +120,12 @@
?.textContent?.toLowerCase()
?.replace(/\s+/g, "");
const qualifiedEntryName = `${entryModule}.${entryName}`
const qualifiedEntryName = `${entryModule}.${entryName}`;
if ((qualifiedEntryName.includes(text) || entrySignature?.includes(text.replace(/\s+/g, "")))) {
if (
qualifiedEntryName.includes(text) ||
entrySignature?.includes(text.replace(/\s+/g, ""))
) {
totalResults++;
entry.classList.remove("hidden");
if (topSearchResultListItem === undefined) {
@ -229,3 +246,25 @@
}
});
})();
(() => {
let body = document.body;
const sidebarOpen = "sidebar-open";
const removeOpenClass = () => {
body.classList.remove(sidebarOpen);
document.body
.querySelector("main")
.removeEventListener("click", removeOpenClass);
};
Array.from(document.body.querySelectorAll(".menu-toggle")).forEach(
(menuToggle) => {
menuToggle.addEventListener("click", (e) => {
body.classList.toggle(sidebarOpen);
e.stopPropagation();
if (body.classList.contains(sidebarOpen)) {
document.body.addEventListener("click", removeOpenClass);
}
});
},
);
})();

View file

@ -63,26 +63,30 @@ table tr td {
.pkg-full-name {
display: flex;
align-items: center;
font-size: 32px;
font-size: 24px;
margin: 0 8px;
font-weight: normal;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
height: 100%;
}
.entry-name {
white-space: pre-wrap;
font-family: var(--font-mono);
font-size: 18px;
font-size: 16px;
font-weight: normal;
color: var(--violet);
background-color: var(--violet-bg);
color: white;
width: auto;
margin-top: 0;
margin-bottom: 24px;
padding: 8px 16px;
border-left: 2px solid var(--violet);
padding: 12px 16px;
border: 2px solid var(--violet);
}
.entry-name strong {
color: var(--violet);
}
.entry-name a {
@ -109,6 +113,9 @@ table tr td {
.pkg-full-name a {
padding-top: 12px;
padding-bottom: 16px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
a {
@ -124,8 +131,12 @@ a:hover code {
min-width: 0; /* necessary for text-overflow: ellipsis to work in descendants */
display: flex;
align-items: center;
height: 100%;
justify-content: space-between;
gap: 16px;
background-color: var(--violet-bg);
padding-block: 16px;
position: sticky;
top: 0px;
}
.pkg-and-logo a,
@ -154,36 +165,48 @@ a:hover code {
body {
display: grid;
grid-template-columns:
[before-sidebar] 1fr [sidebar] var(--sidebar-width)
[main-content] fit-content(calc(1280px - var(--sidebar-width)))
[end] 1fr;
grid-template-rows: [top-header] var(--top-header-height) [above-footer] auto [footer] auto;
[sidebar] var(--sidebar-width)
[main-content] 1fr
[content-end];
grid-template-rows: 1fr;
height: 100dvh;
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: var(--font-sans);
color: var(--text-color);
background-color: var(--body-bg-color);
overflow: hidden;
}
main {
grid-column-start: main-content;
grid-column-end: main-content;
grid-row-start: above-footer;
grid-row-end: above-footer;
grid-column-end: content-end;
box-sizing: border-box;
position: relative;
font-size: 18px;
font-size: 16px;
line-height: 1.85em;
margin-top: 2px;
padding: 48px;
max-width: 740px;
padding: 16px;
padding-top: 0px;
/* necessary for text-overflow: ellipsis to work in descendants */
min-width: 0;
overflow-x: auto;
/* fixes issues with horizonatal scroll in cases where word is too long,
like in one of the examples at https://www.roc-lang.org/builtins/Num#Dec */
overflow-wrap: break-word;
overflow-y: auto;
display: grid;
grid-template-columns: [main-start] 1fr [main-content-start] 60ch [main-content-end] 1fr [main-end];
grid-template-rows: auto;
flex-direction: column;
scrollbar-color: var(--violet) var(--body-bg-color);
scrollbar-gutter: stable both-edges;
}
main > * {
grid-column-start: main-content-start;
grid-column-end: main-content-end;
}
/* Module links on the package index page (/index.html) */
@ -195,7 +218,7 @@ main {
section {
padding: 0px 0px 16px 0px;
margin: 72px 0px;
margin: 36px 0px;
}
section blockquote {
@ -230,32 +253,18 @@ padding: 0px 16px;
#sidebar-nav {
grid-column-start: sidebar;
grid-column-end: sidebar;
grid-row-start: above-footer;
grid-row-end: above-footer;
grid-column-end: main-content;
position: relative;
display: flex;
flex-direction: column;
box-sizing: border-box;
padding-left: 56px;
padding-top: 6px;
width: 100%;
}
.header-start-extension {
grid-column-start: before-sidebar;
grid-column-end: sidebar;
grid-row-start: top-header;
grid-row-end: top-header;
background-color: var(--violet-bg);
}
.header-end-extension {
grid-column-start: end;
grid-column-end: end;
grid-row-start: top-header;
grid-row-end: top-header;
background-color: var(--violet-bg);
overflow-y: auto;
scrollbar-color: var(--violet) var(--violet-bg);
scrollbar-gutter: stable both-edges;
view-transition-name: sidebar;
transition: 1s linear;
}
.top-header {
@ -269,7 +278,7 @@ padding: 0px 16px;
flex-wrap: nowrap;
box-sizing: border-box;
font-family: var(--font-sans);
font-size: 24px;
font-size: 20px;
height: 100%;
background-color: var(--violet-bg);
/* min-width must be set to something (even 0) for text-overflow: ellipsis to work in descendants, but we want this anyway. */
@ -282,10 +291,6 @@ p {
}
footer {
grid-column-start: main-content;
grid-column-end: main-content;
grid-row-start: footer;
grid-row-end: footer;
max-width: var(--main-content-max-width);
font-size: 14px;
box-sizing: border-box;
@ -312,9 +317,9 @@ footer p {
.sidebar-entry a {
box-sizing: border-box;
min-height: 48px;
min-height: 40px;
min-width: 48px;
padding: 12px 16px;
padding: 8px 16px;
font-family: var(--font-mono);
}
@ -323,6 +328,10 @@ footer p {
color: var(--text-color);
}
.sidebar-sub-entries {
font-size: 14px;
}
.sidebar-sub-entries a {
display: block;
line-height: 24px;
@ -332,14 +341,15 @@ footer p {
margin-left: 14px;
padding-left: 26px;
border-left: 2px solid var(--violet);
white-space: nowrap;
}
.module-name {
font-size: 56px;
font-size: 28px;
line-height: 1em;
font-family: var(--font-mono);
font-weight: bold;
margin-top: 18px;
margin-top: 48px;
margin-bottom: 48px;
color: var(--violet);
}
@ -355,7 +365,7 @@ color: inherit;
.sidebar-module-link {
box-sizing: border-box;
font-size: 18px;
font-size: 16px;
line-height: 24px;
font-family: var(--font-mono);
display: block;
@ -446,11 +456,17 @@ pre>samp {
align-items: center;
align-content: center;
height: 100%;
background-color: var(--violet-bg);
position: relative;
position: sticky;
flex-grow: 1;
box-sizing: border-box;
padding: 0px var(--module-search-form-padding-width);
padding-top: 16px;
background-color: var(--body-bg-color);
top: 0;
z-index: 1;
}
.menu-toggle {
display:none;
}
#module-search,
@ -467,12 +483,13 @@ pre>samp {
box-sizing: border-box;
width: 100%;
box-sizing: border-box;
font-size: 18px;
font-size: 16px;
line-height: 18px;
border: none;
color: var(--faded-color);
background-color: var(--body-bg-color);
font-family: var(--font-serif);
border: 2px solid var(--violet-bg);
}
#module-search::placeholder {
@ -481,7 +498,7 @@ pre>samp {
}
#module-search:focus, #module-search:hover {
outline: 2px solid var(--faded-color);
outline: 2px solid var(--violet);
}
#search-type-ahead {
@ -563,13 +580,9 @@ pre>samp {
box-sizing: border-box;
align-items: center;
font-size: 18px;
line-height: 18px;
padding: 12px 16px;
height: 48px;
pointer-events: none;
position: absolute;
top: 12px;
left: 96px;
right: 72px;
}
#search-shortcut-key {
@ -602,7 +615,6 @@ pre>samp {
.module-name {
flex-grow: 1;
margin-bottom: 0;
}
@media (prefers-color-scheme: dark) {
@ -637,28 +649,31 @@ pre>samp {
@media only screen and (max-device-width: 480px) and (orientation: portrait) {
body {
grid-template-areas:
"header"
"main"
"sidebar"
"footer";
display: block;
overflow-y: auto;
overflow-x: hidden;
}
#sidebar-nav {
grid-area: sidebar;
display: none;
left: calc(-1 * var(--sidebar-width));
top: 0;
bottom: 0;
position: fixed;
z-index: 2;
transition: 1s linear;
}
body.sidebar-open #sidebar-nav {
display: block;
left: 0;
}
main {
grid-area: main;
display: block;
margin: 0 16px;
}
.top-header {
grid-area: header;
}
footer {
grid-area: footer;
}
:root {
--top-header-height: 160px;
}
@ -668,10 +683,30 @@ pre>samp {
}
#module-search-form {
padding: 0 16px;
width: 100%;
padding: 16px 16px;
height: auto;
margin-bottom: 16px;
grid-column-start: main-content-start;
grid-column-end: main-content-end;
position: fixed;
left: 0;
right: 0;
}
.menu-toggle {
display: inline-block;
margin-right: 8px;
appearance: none;
background-color: transparent;
outline: none;
border: none;
color: var(--text-color);
padding: 0;
}
.menu-toggle svg {
height: 48px;
width: 48px;
}
/* Hide the Copy Link button on mobile. */
@ -679,8 +714,9 @@ pre>samp {
display: none;
}
.search-button {
.search-icon {
display: block; /* This is only visible in mobile. */
top: calc(1lh / 2 + 16px);
}
.top-header {
@ -692,9 +728,7 @@ pre>samp {
}
.pkg-full-name {
margin-left: 8px;
margin-right: 12px;
font-size: 24px;
font-size: 20px;
padding-bottom: 14px;
}
@ -704,7 +738,6 @@ pre>samp {
}
.logo {
padding-left: 2px;
width: 50px;
height: 54px;
}
@ -717,7 +750,7 @@ pre>samp {
}
.module-name {
font-size: 36px;
font-size: 24px;
margin-top: 8px;
margin-bottom: 8px;
overflow: hidden;
@ -727,13 +760,13 @@ pre>samp {
main {
padding: 18px;
font-size: 16px;
max-width: 480px;
padding-top: calc(16px + 16px + 1lh + 16px);
}
#sidebar-nav {
margin-top: 0;
padding-left: 0;
width: auto;
width: var(--sidebar-width);
}
#sidebar-heading {
@ -752,10 +785,9 @@ pre>samp {
}
body {
grid-template-columns: auto;
margin: 0;
min-width: 320px;
max-width: 100%;
max-width: 100dvw;
}
.top-header-triangle {