Skip to content
Closed
142 changes: 142 additions & 0 deletions sass/_valkey.scss
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,76 @@ p {
}
}
}

// The docs menu (templates/left-aside.html) goes above the page on narrow
// screens. On wide screens .docs-sidebar has the padding instead.
.docs-aside {
order: -1;

@include respond-min(1024px) {
order: 0;
padding: 0;
}
}
}

// Narrow screens: a toggle that opens the menu. Wide screens: the menu sticks
// to the top of the window, at most a window tall, and scrolls on its own.
.docs-sidebar {
> summary {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 1.6rem;
border-radius: 10px;
background-color: #fff;
font-weight: 700;
color: #000;
cursor: pointer;
list-style: none;

&::-webkit-details-marker {
display: none;
}

// Chevron, as in the menu's sections.
&::after {
content: '';
width: 0.7rem;
height: 0.7rem;
border-right: 2px solid currentColor;
border-bottom: 2px solid currentColor;
transform: rotate(-45deg);
}

&:focus-visible {
outline: 2px solid #2054B2;
outline-offset: 1px;
}
}

&[open] > summary {
margin-bottom: 1rem;

&::after {
transform: rotate(45deg);
}
}

@include respond-min(1024px) {
position: sticky;
top: 0;
max-height: 100vh;
overflow-y: auto;
overscroll-behavior: contain;
scrollbar-width: thin;
scrollbar-color: #c5cdea transparent;
padding: 2rem;

> summary {
display: none;
}
}
}

.docs-menu {
Expand Down Expand Up @@ -2140,6 +2210,24 @@ html.banner-hidden .banner {
height: 1.6rem;
}

// "#" after each docs heading (heading_links in templates/macros/docs.html).
// Shown while the heading is hovered or the link has focus, and always on
// touch screens, which can't hover.
.heading-link {
margin-left: 0.4em;
opacity: 0;

h2:hover > &,
h3:hover > &,
&:focus {
opacity: 1;
}

@media (hover: none) {
opacity: 1;
}
}

// Amber rather than red: a release candidate is not broken, it is just not
// finished. #7A4A00 on #FFF6E5 is 7.4:1.
.release-prerelease-notice {
Expand Down Expand Up @@ -2410,6 +2498,60 @@ blockquote {
margin: 1.5rem 0 2.5rem;
}

// Previous and next topic links at the end of a topic (nav_pager in
// templates/macros/nav.html). The links look like the docs menu's. "Next"
// stays on the right when there's no "Previous".
.docs-pager {
display: flex;
justify-content: space-between;
gap: 1rem;
margin-top: 4rem;
padding-top: 1.5rem;
border-top: 1px solid #d5d9ec;

a {
display: flex;
flex-direction: column;
max-width: 50%;
padding: 0.6rem 1rem;
border-radius: 4px;
line-height: 1.35;

&:hover {
background-color: #d1d9ff;
}

&:focus-visible {
outline: 2px solid #2054B2;
outline-offset: 1px;
}
}

.docs-pager-next {
margin-left: auto;
align-items: flex-end;
text-align: right;
}

.docs-pager-label {
font-size: 1.3rem;
color: #444;
}

.docs-pager-title {
font-weight: 600;
}

@media (max-width: 768px) {
flex-direction: column;
gap: 0.5rem;

a {
max-width: none;
}
}
}

// Homepage blog cards: text-only cards stacked vertically, matching the release
// cards in the other column.
.homepage-blog-section {
Expand Down
12 changes: 9 additions & 3 deletions templates/command-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,14 @@ <h1 class="docs-page-title">{{ command_title }} {% if deprecated %}<small> {{ de

{% if command_description %}
{%- set command_description_with_fixed_links %}{{< fix_links_command content={command_description} />}}{% endset -%}
{%- set command_description_html %}{{ command_description_with_fixed_links | markdown | safe }}{% endset -%}

{{ command_description_with_fixed_links | markdown | safe }}
{{< heading_links content={command_description_html} />}}
{% else %}
<code>ERROR. Command description not loaded</code><br />
{% endif %}
{% if command_data_obj.replaced_by %}
<h3 id="deprecation-advice">Deprecation advice</h3>
{{< heading_links content='<h3 id="deprecation-advice">Deprecation advice</h3>' />}}
Instead of using <code>{{ command_title }}</code> use <div class="replaced-by">{{ command_data_obj.replaced_by | markdown | safe }}</div>

{% endif %}
Expand Down Expand Up @@ -205,7 +206,7 @@ <h3>RESP3 Reply</h3>
{% endif -%}

{% if command_data_obj and command_data_obj.history %}
<h3>History</h3>
{{< heading_links content='<h3 id="history">History</h3>' />}}
<table>
<thead>
<tr>
Expand All @@ -225,6 +226,11 @@ <h3>History</h3>
</table>
{% endif %}

{# Every command page, module commands included, is built from a description in valkey-doc (see build/init-commands.sh). #}
<div class="edit_box">
See an error?
<a href="https://github.com/valkey-io/valkey-doc/edit/main/commands/{{ page.slug }}.md">Update this Page on GitHub!</a>
</div>
{% endblock main_content %}

{% block related_content %}
Expand Down
13 changes: 7 additions & 6 deletions templates/docs-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ <h1 class="docs-page-title">{{ frontmatter_title }}</h1>
<hr />
{% endif %}
{%- set content_with_fixed_links %}{{< fix_links_docs content={page_contents} />}}{% endset -%}
{{ content_with_fixed_links | markdown | safe }}
{%- set content_html %}{{ content_with_fixed_links | markdown | safe }}{% endset -%}
{{< heading_links content={content_html} />}}
<div class="edit_box">
See an error?
<a href="https://github.com/valkey-io/valkey-doc/edit/main/topics/{{ page.slug }}.md">Update this Page on GitHub!</a>
</div>
{{< nav_pager nav={nav_data} slug={page.slug} extra={config.extra} />}}
{% endblock main_content %}

{% block related_content %}
Expand All @@ -68,9 +74,4 @@ <h1 class="docs-page-title">{{ frontmatter_title }}</h1>
{% set nav_map_json %}{{< nav_command_map nav={nav_data} index={nav_index} />}}{% endset %}
{% set nav_command_map = load_data(literal=nav_map_json, format="json") %}
{{< nav_menu nav={nav_data} extra={config.extra} current={page.slug} open={nav_location.section} command_map={nav_command_map} index={nav_index} />}}

<div class="edit_box">
See an error?
<a href="https://github.com/valkey-io/valkey-doc/edit/main/topics/{{ page.slug }}.md">Update this Page on GitHub!</a>
</div>
{% endblock related_content %}
28 changes: 26 additions & 2 deletions templates/left-aside.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,32 @@
{% block main_content %}{% endblock main_content %}
</div>
</main>
<aside>
{% block related_content %}{% endblock related_content %}
<aside class="docs-aside">
<details class="docs-sidebar" open>
<summary>Documentation menu</summary>
{% block related_content %}{% endblock related_content %}
</details>
<script>
// Wide screens always show the menu, which scrolls on its own (see
// .docs-sidebar). If the current page's entry is out of view,
// scroll the menu, not the page, to it. Narrow screens start with
// the menu closed.
(function () {
var sidebar = document.querySelector('.docs-sidebar');
var wide = window.matchMedia('(min-width: 1024px)');
sidebar.open = wide.matches;
wide.addEventListener('change', function () {
if (wide.matches) sidebar.open = true;
});
var current = sidebar.querySelector('.docs-menu-current') || sidebar.querySelector('.docs-menu-related');
if (wide.matches && current) {
var box = sidebar.getBoundingClientRect();
var entry = current.getBoundingClientRect();
var visible = Math.min(box.bottom, window.innerHeight) - box.top;
if (entry.bottom - box.top > visible) sidebar.scrollTop += entry.top - box.top - visible / 3;
}
})();
</script>
</aside>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions templates/macros/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,12 @@
| safe
}}
{% endcomponent fix_links_docs %}

{# Adds a "#" link to each h2 and h3 with an id, so a section can be linked to.
Zola's insert_anchor_links doesn't apply to the markdown filter. #}
{% component heading_links(content) %}
{{ content
| regex_replace(pattern='<h(?P<level>[23]) id="(?P<id>[^"]+)">(?P<text>.*?)</h[23]>', rep='<h${level} id="${id}">${text}<a class="heading-link" href="#${id}" aria-label="Link to this section">#</a></h${level}>')
| safe
}}
{% endcomponent heading_links %}
35 changes: 35 additions & 0 deletions templates/macros/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,41 @@
{{ found | json_encode | safe }}
{% endcomponent nav_topic_location %}

{#-
Links to the previous and next topic in menu order: each section's landing
page, then its topics, crossing into the next section at the end of one.
The command reference isn't a topic, so it's skipped. A topic that isn't in
the menu gets no links. Titles are the topics' own, not the shorter menu
titles, which only make sense under their section.
-#}
{% component nav_pager(nav, slug, extra) %}
{%- set order = [] -%}
{%- for section in nav -%}
{%- if section.landing -%}{%- set_global order = [...order, section.landing] -%}{%- endif -%}
{%- set_global order = [...order, ...[t.topic for t in section.topics]] -%}
{%- endfor -%}
{%- set at = [i for i in range(end=order | length) if order[i] == slug] -%}
{%- set i = at | first if at else -1 -%}
{%- set prev = order[i - 1] if i > 0 else "" -%}
{%- set next = order[i + 1] if i >= 0 and i + 1 < order | length else "" -%}
{%- if prev or next %}
<nav class="docs-pager" aria-label="Previous and next topics">
{%- if prev %}
<a class="docs-pager-prev" href="/topics/{{ prev }}/" rel="prev">
<span class="docs-pager-label">Previous</span>
<span class="docs-pager-title">{{< nav_topic_title slug={prev} extra={extra} />}}</span>
</a>
{%- endif %}
{%- if next %}
<a class="docs-pager-next" href="/topics/{{ next }}/" rel="next">
<span class="docs-pager-label">Next</span>
<span class="docs-pager-title">{{< nav_topic_title slug={next} extra={extra} />}}</span>
</a>
{%- endif %}
</nav>
{%- endif %}
{% endcomponent nav_pager %}

{#- A topic's title: `title` if set, otherwise the title in the topic's front matter. -#}
{% component nav_topic_title(slug, extra, title="") %}
{%- if title -%}{{ title }}{%- else -%}
Expand Down
Loading