Skip to content

Commit 743bd30

Browse files
GuillaumeGomezsyphar
authored andcommitted
Move about page tabs system in header dropdown
1 parent b903fcb commit 743bd30

File tree

11 files changed

+74
-106
lines changed

11 files changed

+74
-106
lines changed

src/web/build_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
extractors::{DbConnection, Path},
99
file::File,
1010
filters,
11-
page::templates::{RenderRegular, RenderSolid},
11+
page::templates::{RenderBrands, RenderRegular, RenderSolid},
1212
},
1313
};
1414
use anyhow::Context as _;

src/web/builds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
error::{AxumResult, EscapedURI},
1414
extractors::{DbConnection, Path},
1515
filters, match_version,
16-
page::templates::{RenderRegular, RenderSolid},
16+
page::templates::{RenderBrands, RenderRegular, RenderSolid},
1717
},
1818
};
1919
use anyhow::{Result, anyhow};

src/web/crate_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
cache::CachePolicy,
1313
error::{AxumNope, AxumResult, EscapedURI},
1414
extractors::{DbConnection, Path},
15-
page::templates::{RenderRegular, RenderSolid, filters},
15+
page::templates::{RenderBrands, RenderRegular, RenderSolid, filters},
1616
rustdoc::RustdocHtmlParams,
1717
},
1818
};

src/web/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
filters,
1010
headers::CanonicalUrl,
1111
match_version,
12-
page::templates::{RenderRegular, RenderSolid},
12+
page::templates::{RenderBrands, RenderRegular, RenderSolid},
1313
},
1414
};
1515
use anyhow::anyhow;

src/web/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::db::ReleaseId;
88
use crate::db::types::BuildStatus;
99
use crate::utils::get_correct_docsrs_style_file;
1010
use crate::utils::report_error;
11-
use crate::web::page::templates::{RenderSolid, filters};
11+
use crate::web::page::templates::{RenderBrands, RenderSolid, filters};
1212
use anyhow::{Context as _, Result, anyhow, bail};
1313
use askama::Template;
1414
use axum_extra::middleware::option_layer;

src/web/releases.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
error::{AxumNope, AxumResult},
1111
extractors::{DbConnection, Path},
1212
match_version,
13-
page::templates::{RenderRegular, RenderSolid, filters},
13+
page::templates::{RenderBrands, RenderRegular, RenderSolid, filters},
1414
},
1515
};
1616
use anyhow::{Context as _, Result, anyhow};

src/web/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
match_version,
2121
page::{
2222
TemplateData,
23-
templates::{RenderRegular, RenderSolid, filters},
23+
templates::{RenderBrands, RenderRegular, RenderSolid, filters},
2424
},
2525
},
2626
};

src/web/sitemap.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ macro_rules! about_page {
129129
($ty:ident, $template:literal) => {
130130
#[derive(Template)]
131131
#[template(path = $template)]
132-
struct $ty {
133-
active_tab: &'static str,
134-
}
132+
struct $ty;
135133

136134
impl_axum_webpage! { $ty }
137135
};
@@ -151,30 +149,12 @@ pub(crate) async fn about_handler(subpage: Option<Path<String>>) -> AxumResult<i
151149
};
152150

153151
let response = match &subpage[..] {
154-
"about" | "index" => AboutPage {
155-
active_tab: "index",
156-
}
157-
.into_response(),
158-
"badges" => AboutPageBadges {
159-
active_tab: "badges",
160-
}
161-
.into_response(),
162-
"metadata" => AboutPageMetadata {
163-
active_tab: "metadata",
164-
}
165-
.into_response(),
166-
"redirections" => AboutPageRedirection {
167-
active_tab: "redirections",
168-
}
169-
.into_response(),
170-
"download" => AboutPageDownload {
171-
active_tab: "download",
172-
}
173-
.into_response(),
174-
"rustdoc-json" => AboutPageRustdocJson {
175-
active_tab: "rustdoc-json",
176-
}
177-
.into_response(),
152+
"about" | "index" => AboutPage.into_response(),
153+
"badges" => AboutPageBadges.into_response(),
154+
"metadata" => AboutPageMetadata.into_response(),
155+
"redirections" => AboutPageRedirection.into_response(),
156+
"download" => AboutPageDownload.into_response(),
157+
"rustdoc-json" => AboutPageRustdocJson.into_response(),
178158
_ => {
179159
let msg = "This /about page does not exist. \
180160
Perhaps you are interested in <a href=\"https://github.com/rust-lang/docs.rs/tree/master/templates/core/about\">creating</a> it?";

templates/about-base.html

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,6 @@
44
centered
55
{%- endblock body_classes -%}
66

7-
{% block header %}
8-
<div class="docsrs-package-container">
9-
<div class="container">
10-
<div class="description-container">
11-
<h1 id="crate-title" class="no-description">Docs.rs documentation</h1>
12-
<div class="pure-menu pure-menu-horizontal">
13-
<ul class="pure-menu-list">
14-
{% set text = crate::icons::IconCircleInfo.render_solid(false, false, "") %}
15-
{% set text = "{} <span class='title'>About</span>"|format(text) %}
16-
{% call macros::active_link(expected="index", href="/about", text=text) %}
17-
18-
{% set text = crate::icons::IconFonticons.render_brands(false, false, "") %}
19-
{% set text = "{} <span class='title'>Badges</span>"|format(text) %}
20-
{% call macros::active_link(expected="badges", href="/about/badges", text=text) %}
21-
22-
{% set text = crate::icons::IconGears.render_solid(false, false, "") %}
23-
{% set text = "{} <span class='title'>Builds</span>"|format(text) %}
24-
{% call macros::active_link(expected="builds", href="/about/builds", text=text) %}
25-
26-
{% set text = crate::icons::IconTable.render_solid(false, false, "") %}
27-
{% set text = "{} <span class='title'>Metadata</span>"|format(text) %}
28-
{% call macros::active_link(expected="metadata", href="/about/metadata", text=text) %}
29-
30-
{% set text = crate::icons::IconRoad.render_solid(false, false, "") %}
31-
{% set text = "{} <span class='title'>Shorthand URLs</span>"|format(text) %}
32-
{% call macros::active_link(expected="redirections", href="/about/redirections", text=text) %}
33-
34-
{% set text = crate::icons::IconDownload.render_solid(false, false, "") %}
35-
{% set text = "{} <span class='title'>Download</span>"|format(text) %}
36-
{% call macros::active_link(expected="download", href="/about/download", text=text) %}
37-
38-
{% set text = crate::icons::IconFileCode.render_solid(false, false, "") %}
39-
{% set text = "{} <span class='title'>Rustdoc JSON</span>"|format(text) %}
40-
{% call macros::active_link(expected="rustdoc-json", href="/about/rustdoc-json", text=text) %}
41-
</ul>
42-
</div>
43-
</div>
44-
</div>
45-
</div>
46-
{% endblock %}
47-
487
{%- block topbar -%}
498
{% let search_query = Some(String::new()) %}
509
{%- include "header/topbar.html" -%}

templates/header/topbar_end.html

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,51 @@
1010
#}<li class="pure-menu-item pure-menu-has-children">
1111
<a href="#" class="pure-menu-link" aria-label="docs.rs">docs.rs</a>
1212
<ul class="pure-menu-children">
13-
{% call macros::menu_link(
13+
{%- call macros::menu_link_with_icon_solid(
1414
href="/about",
1515
text="About docs.rs",
16-
target="",
17-
) %}
18-
{% call macros::menu_link(
16+
icon=crate::icons::IconCircleInfo,
17+
) -%}
18+
{%- call macros::menu_link_with_icon_brand(
19+
href="/about/badges",
20+
text="Badges",
21+
icon=crate::icons::IconFonticons,
22+
) -%}
23+
{%- call macros::menu_link_with_icon_solid(
24+
href="/about/builds",
25+
text="Builds",
26+
icon=crate::icons::IconGears,
27+
) -%}
28+
{%- call macros::menu_link_with_icon_solid(
29+
href="/about/metadata",
30+
text="Metadata",
31+
icon=crate::icons::IconTable,
32+
) -%}
33+
{%- call macros::menu_link_with_icon_solid(
34+
href="/about/redirections",
35+
text="Shorthand URLs",
36+
icon=crate::icons::IconRoad,
37+
) -%}
38+
{%- call macros::menu_link_with_icon_solid(
39+
href="/about/download",
40+
text="Download",
41+
icon=crate::icons::IconDownload,
42+
) -%}
43+
{%- call macros::menu_link_with_icon_solid(
44+
href="/about/rustdoc-json",
45+
text="Rustdoc JSON",
46+
icon=crate::icons::IconFileCode,
47+
) -%}
48+
{%- call macros::menu_link_with_icon_solid(
49+
href="/releases/queue",
50+
text="Build queue",
51+
icon=crate::icons::IconGears,
52+
) -%}
53+
{%- call macros::menu_link(
1954
href="https://foundation.rust-lang.org/policies/privacy-policy/#docs.rs",
2055
text="Privacy policy",
2156
target="_blank"
22-
) %}
23-
{% call macros::menu_link(
24-
href="/releases/queue",
25-
text="Build queue",
26-
target="",
27-
) %}
57+
) -%}
2858
</ul>
2959
</li>
3060
</ul>

templates/macros.html

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
{#
2-
Creates a list entry for active tabs. When the active tab is the same as `expected`, it will show the current tab as active.
3-
* `expected` A string that represents the current tab, when `active_tab == expected` the current will be shown as active
4-
* `href` A string used as the tab's link
5-
* `text` A string used as the tab's text
6-
#}
7-
{% macro active_link(expected, href, text) %}
8-
<li class="pure-menu-item">
9-
<a class="pure-menu-link {% if active_tab == *expected %} pure-menu-active {% endif %}" href="{{ href }}">
10-
{# safe: allow passing in HTML #}
11-
{{ text|safe }}
12-
</a>
13-
</li>
14-
{% endmacro active_link %}
15-
161
{#
172
Creates a list entry
183
* `href` A string used as the tab's link
194
* `text` A string used as the tab's text
205
* `target` An optional target
216
* `extra_classes` Optional extra css classes
227
#}
23-
{% macro menu_link(href, text, target) %}
24-
<li class="pure-menu-item">
25-
<a class="pure-menu-link" href="{{ href }}" {% if !target.is_empty() -%} target="{{ target }}" {%- endif %}>
26-
{{ text }}
27-
</a>
8+
{% macro menu_link(href, text, target) -%}
9+
<li class="pure-menu-item"> {#- -#}
10+
<a class="pure-menu-link" href="{{ href }}"{% if !target.is_empty() %} target="{{ target }}" {%- endif %}>{{ text }}</a> {#- -#}
11+
</li>
12+
{%- endmacro menu_link %}
13+
14+
{% macro menu_link_with_icon_solid(href, text, icon) -%}
15+
<li class="pure-menu-item"> {#- -#}
16+
<a class="pure-menu-link" href="{{ href }}">
17+
{{- icon.render_solid(false, false, "") }} {{ text -}}
18+
</a> {#- -#}
19+
</li>
20+
{%- endmacro menu_link_with_icon_solid %}
21+
22+
{% macro menu_link_with_icon_brand(href, text, icon) -%}
23+
<li class="pure-menu-item"> {#- -#}
24+
<a class="pure-menu-link" href="{{ href }}">
25+
{{- icon.render_brands(false, false, "") }} {{ text -}}
26+
</a> {#- -#}
2827
</li>
29-
{% endmacro menu_link %}
28+
{%- endmacro menu_link_with_icon_brand %}
3029

3130
{#
3231
Creates a formatted table showing the resource limits of a crate

0 commit comments

Comments
 (0)