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

Put SVG images into CSS #2623

Open
wants to merge 5 commits into
base: master
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
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ jobs:
with:
prefix-key: ${{ env.RUST_CACHE_KEY }}

- name: Build
run: cargo build --workspace --locked

- name: Launch postgres
run: |
cp .env.sample .env
Expand All @@ -52,12 +49,12 @@ jobs:
# Make sure the database is actually working
psql "${DOCSRS_DATABASE_URL}"

- name: run database migrations
run: cargo run -- database migrate

- name: install SQLX CLI
run: cargo install sqlx-cli --no-default-features --features postgres

- name: run database migrations
run: cargo sqlx migrate run --database-url $DOCSRS_DATABASE_URL

- name: run sqlx prepare --check
run: just sqlx-check

Expand Down Expand Up @@ -99,7 +96,7 @@ jobs:
sleep 5
# Make sure the database is actually working
psql "${DOCSRS_DATABASE_URL}"

- name: run workspace tests
run: |
cargo test --workspace --locked --no-fail-fast
Expand Down
2 changes: 1 addition & 1 deletion crates/font-awesome-as-a-crate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn write_fontawesome_sprite() {
pub struct {type_name};
impl IconStr for {type_name} {{
fn icon_name(&self) -> &'static str {{ r#\"{icon}\"# }}
fn icon_str(&self) -> &'static str {{ r#\"{data}\"# }}
fn icon_svg(&self) -> &'static str {{ r#\"{data}\"# }}
}}
{kinds}"
)
Expand Down
10 changes: 5 additions & 5 deletions crates/font-awesome-as-a-crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ If you have problems, [contact us](https://github.com/rust-lang/docs.rs/issues),
*/

use std::error::Error;
use std::fmt::{self, Display, Formatter};
use std::fmt::{self, Debug, Display, Formatter};

#[cfg(font_awesome_out_dir)]
include!(concat!(env!("OUT_DIR"), "/fontawesome.rs"));
Expand Down Expand Up @@ -91,20 +91,20 @@ pub trait IconStr {
/// Name of the icon, like "triangle-exclamation".
fn icon_name(&self) -> &'static str;
/// The SVG content of the icon.
fn icon_str(&self) -> &'static str;
fn icon_svg(&self) -> &'static str;
}

pub trait Brands: IconStr {
pub trait Brands: IconStr + Debug {
fn get_type() -> Type {
Type::Brands
}
}
pub trait Regular: IconStr {
pub trait Regular: IconStr + Debug {
fn get_type() -> Type {
Type::Regular
}
}
pub trait Solid: IconStr {
pub trait Solid: IconStr + Debug {
fn get_type() -> Type {
Type::Solid
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub use self::registry_api::RegistryApi;
pub use self::storage::{AsyncStorage, Storage};
pub use self::web::{start_background_metrics_webserver, start_web_server};

pub(crate) use font_awesome_as_a_crate as f_a;
pub use font_awesome_as_a_crate::icons;

mod build_queue;
pub mod cdn;
Expand Down
4 changes: 3 additions & 1 deletion src/web/build_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::{
error::{AxumNope, AxumResult},
extractors::{DbConnection, Path},
file::File,
filters, MetaData,
filters,
page::templates::{RenderRegular, RenderSolid},
MetaData,
},
AsyncStorage, Config,
};
Expand Down
4 changes: 3 additions & 1 deletion src/web/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::{
web::{
error::AxumResult,
extractors::{DbConnection, Path},
filters, match_version, MetaData, ReqVersion,
filters, match_version,
page::templates::{RenderRegular, RenderSolid},
MetaData, ReqVersion,
},
BuildQueue, Config,
};
Expand Down
4 changes: 2 additions & 2 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
encode_url_path,
error::{AxumNope, AxumResult},
extractors::{DbConnection, Path},
page::templates::filters,
page::templates::{filters, RenderRegular, RenderSolid},
rustdoc::RustdocHtmlParams,
MatchedRelease, ReqVersion,
},
Expand Down Expand Up @@ -1614,7 +1614,7 @@ mod tests {
.borrow()
.get("class")
.unwrap(),
"fa-svg"
"fa fa-solid fa-code-branch "
);

Ok(())
Expand Down
4 changes: 3 additions & 1 deletion src/web/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use crate::{
extractors::{DbConnection, Path},
filters,
headers::CanonicalUrl,
match_version, MetaData, ReqVersion,
match_version,
page::templates::{RenderRegular, RenderSolid},
MetaData, ReqVersion,
},
};
use anyhow::anyhow;
Expand Down
2 changes: 1 addition & 1 deletion src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod page;
use crate::db::types::BuildStatus;
use crate::utils::get_correct_docsrs_style_file;
use crate::utils::report_error;
use crate::web::page::templates::filters;
use crate::web::page::templates::{filters, RenderSolid};
use anyhow::{anyhow, bail, Context as _, Result};
use axum_extra::middleware::option_layer;
use rinja::Template;
Expand Down
2 changes: 1 addition & 1 deletion src/web/page/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub(crate) struct GlobalAlert {
pub(crate) url: &'static str,
pub(crate) text: &'static str,
pub(crate) css_class: &'static str,
pub(crate) fa_icon: crate::f_a::icons::IconTriangleExclamation,
pub(crate) fa_icon: crate::icons::IconTriangleExclamation,
}
77 changes: 40 additions & 37 deletions src/web/page/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,33 +200,6 @@ pub mod filters {
Ok(unindented)
}

pub fn fas<T: font_awesome_as_a_crate::Solid>(
value: T,
fw: bool,
spin: bool,
extra: &str,
) -> rinja::Result<Safe<String>> {
super::render_icon(value.icon_str(), fw, spin, extra)
}

pub fn far<T: font_awesome_as_a_crate::Regular>(
value: T,
fw: bool,
spin: bool,
extra: &str,
) -> rinja::Result<Safe<String>> {
super::render_icon(value.icon_str(), fw, spin, extra)
}

pub fn fab<T: font_awesome_as_a_crate::Brands>(
value: T,
fw: bool,
spin: bool,
extra: &str,
) -> rinja::Result<Safe<String>> {
super::render_icon(value.icon_str(), fw, spin, extra)
}

pub fn highlight(code: impl std::fmt::Display, lang: &str) -> rinja::Result<Safe<String>> {
let highlighted_code = crate::web::highlight::with_lang(Some(lang), &code.to_string());
Ok(Safe(format!(
Expand Down Expand Up @@ -255,27 +228,57 @@ pub mod filters {
}
}

fn render_icon(
icon_str: &str,
pub trait RenderSolid {
fn render_solid(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String>;
}

impl<T: font_awesome_as_a_crate::Solid> RenderSolid for T {
fn render_solid(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String> {
render("fa-solid", self.icon_name(), fw, spin, extra)
}
}

pub trait RenderRegular {
fn render_regular(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String>;
}

impl<T: font_awesome_as_a_crate::Regular> RenderRegular for T {
fn render_regular(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String> {
render("fa-regular", self.icon_name(), fw, spin, extra)
}
}

pub trait RenderBrands {
fn render_brands(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String>;
}

impl<T: font_awesome_as_a_crate::Brands> RenderBrands for T {
fn render_brands(&self, fw: bool, spin: bool, extra: &str) -> rinja::filters::Safe<String> {
render("fa-brands", self.icon_name(), fw, spin, extra)
}
}

fn render(
icon_kind: &str,
css_class: &str,
fw: bool,
spin: bool,
extra: &str,
) -> rinja::Result<rinja::filters::Safe<String>> {
let mut classes = vec!["fa-svg"];
) -> rinja::filters::Safe<String> {
let mut classes = Vec::new();
if fw {
classes.push("fa-svg-fw");
classes.push("fa-fw");
}
if spin {
classes.push("fa-svg-spin");
classes.push("fa-spin");
}
if !extra.is_empty() {
classes.push(extra);
}
let icon = format!(
"\
<span class=\"{class}\" aria-hidden=\"true\">{icon_str}</span>",
class = classes.join(" "),
"<span class=\"fa {icon_kind} fa-{css_class} {classes}\" aria-hidden=\"true\"></span>",
classes = classes.join(" "),
);

Ok(rinja::filters::Safe(icon))
rinja::filters::Safe(icon)
}
2 changes: 1 addition & 1 deletion src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
error::{AxumNope, AxumResult},
extractors::{DbConnection, Path},
match_version,
page::templates::filters,
page::templates::{filters, RenderRegular, RenderSolid},
ReqVersion,
},
BuildQueue, Config, InstanceMetrics,
Expand Down
2 changes: 1 addition & 1 deletion src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
extractors::{DbConnection, Path},
file::File,
match_version,
page::templates::filters,
page::templates::{filters, RenderRegular, RenderSolid},
page::TemplateData,
MetaData, ReqVersion,
},
Expand Down
2 changes: 1 addition & 1 deletion src/web/sitemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
web::{
error::{AxumNope, AxumResult},
extractors::{DbConnection, Path},
page::templates::filters,
page::templates::{filters, RenderBrands, RenderSolid},
AxumErrorPage,
},
Config,
Expand Down
9 changes: 7 additions & 2 deletions src/web/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ use crate::{
impl_axum_webpage,
storage::PathNotFoundError,
web::{
cache::CachePolicy, error::AxumNope, extractors::Path, file::File as DbFile, filters,
headers::CanonicalUrl, MetaData, ReqVersion,
cache::CachePolicy,
error::AxumNope,
extractors::Path,
file::File as DbFile,
headers::CanonicalUrl,
page::templates::{filters, RenderBrands, RenderRegular, RenderSolid},
MetaData, ReqVersion,
},
AsyncStorage,
};
Expand Down
File renamed without changes
Binary file added static/fa-brands-400.ttf
Binary file not shown.
Binary file added static/fa-brands-400.woff2
Binary file not shown.
Binary file added static/fa-regular-400.ttf
Binary file not shown.
Binary file added static/fa-regular-400.woff2
Binary file not shown.
Binary file added static/fa-solid-900.ttf
Binary file not shown.
Binary file added static/fa-solid-900.woff2
Binary file not shown.
Binary file added static/fa-v4compatibility.ttf
Binary file not shown.
Binary file added static/fa-v4compatibility.woff2
Binary file not shown.
12 changes: 6 additions & 6 deletions templates/about-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
<h1 id="crate-title" class="no-description">Docs.rs documentation</h1>
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
{% set text = crate::f_a::icons::IconCircleInfo|fas(false, false, "") %}
{% set text = crate::icons::IconCircleInfo.render_solid(false, false, "") %}
{% set text = "{} <span class='title'>About</span>"|format(text) %}
{% call macros::active_link(expected="index", href="/about", text=text) %}

{% set text = crate::f_a::icons::IconFonticons|fab(false, false, "") %}
{% set text = crate::icons::IconFonticons.render_brands(false, false, "") %}
{% set text = "{} <span class='title'>Badges</span>"|format(text) %}
{% call macros::active_link(expected="badges", href="/about/badges", text=text) %}

{% set text = crate::f_a::icons::IconGears|fas(false, false, "") %}
{% set text = crate::icons::IconGears.render_solid(false, false, "") %}
{% set text = "{} <span class='title'>Builds</span>"|format(text) %}
{% call macros::active_link(expected="builds", href="/about/builds", text=text) %}

{% set text = crate::f_a::icons::IconTable|fas(false, false, "") %}
{% set text = crate::icons::IconTable.render_solid(false, false, "") %}
{% set text = "{} <span class='title'>Metadata</span>"|format(text) %}
{% call macros::active_link(expected="metadata", href="/about/metadata", text=text) %}

{% set text = crate::f_a::icons::IconRoad|fas(false, false, "") %}
{% set text = crate::icons::IconRoad.render_solid(false, false, "") %}
{% set text = "{} <span class='title'>Shorthand URLs</span>"|format(text) %}
{% call macros::active_link(expected="redirections", href="/about/redirections", text=text) %}

{% set text = crate::f_a::icons::IconDownload|fas(false, false, "") %}
{% set text = crate::icons::IconDownload.render_solid(false, false, "") %}
{% set text = "{} <span class='title'>Download</span>"|format(text) %}
{% call macros::active_link(expected="download", href="/about/download", text=text) %}
</ul>
Expand Down
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{%- set build_slug = slug::slugify(crate::BUILD_VERSION) -%}
<link rel="stylesheet" href="/-/static/vendored.css?{{ build_slug }}" media="all" />
<link rel="stylesheet" href="/-/static/style.css?{{ build_slug }}" media="all" />
<link rel="stylesheet" href="/-/static/font-awesome.css?{{ build_slug }}" media="all" />

<link rel="search" href="/-/static/opensearch.xml" type="application/opensearchdescription+xml" title="Docs.rs" />

Expand Down
4 changes: 2 additions & 2 deletions templates/core/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

{%- block body -%}
<div class="container landing">
<h1 class="brand">{{ crate::f_a::icons::IconCubes|fas(false, false, "") }} Docs.rs</h1>
<h1 class="brand">{{ crate::icons::IconCubes.render_solid(false, false, "") }} Docs.rs</h1>

<form action="/releases/search" method="GET" class="landing-search-form">
<div>
Expand All @@ -36,7 +36,7 @@ <h1 class="brand">{{ crate::f_a::icons::IconCubes|fas(false, false, "") }} Docs.
<strong>Recent Releases</strong>
</a>
<a href="/releases/feed" title="Atom feed">
{{ crate::f_a::icons::IconSquareRss|fas(false, false, "") }}
{{ crate::icons::IconSquareRss.render_solid(false, false, "") }}
</a>
</div>

Expand Down
2 changes: 1 addition & 1 deletion templates/crate/build_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<li>
<a href="/crate/{{ metadata.name }}/{{ metadata.version }}/builds/{{ build_details.id }}/{{ filename }}" class="release">
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-24 build">{{ crate::f_a::icons::IconFileLines|fas(false, false, "") }}</div>
<div class="pure-u-1 pure-u-sm-1-24 build">{{ crate::icons::IconFileLines.render_solid(false, false, "") }}</div>
<div class="pure-u-1 pure-u-sm-10-24">
{% if current_filename.as_deref().unwrap_or_default() == filename.as_str() %}
<b>{{ filename }}</b>
Expand Down
8 changes: 4 additions & 4 deletions templates/crate/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
<div class="pure-g">
<div class="pure-u-1 pure-u-sm-1-24 build">
{%- if build.build_status == "success" -%}
{{ crate::f_a::icons::IconCheck|fas(false, false, "") }}
{{ crate::icons::IconCheck.render_solid(false, false, "") }}
{%- elif build.build_status == "failure" -%}
{{ crate::f_a::icons::IconTriangleExclamation|fas(false, false, "") }}
{{ crate::icons::IconTriangleExclamation.render_solid(false, false, "") }}
{%- elif build.build_status == "in_progress" -%}
{{ crate::f_a::icons::IconGear|fas(false, true, "") }}
{{ crate::icons::IconGear.render_solid(false, true, "") }}
{%- else -%}
{{ crate::f_a::icons::IconX|fas(false, false, "") }}
{{ crate::icons::IconX.render_solid(false, false, "") }}
{%- endif -%}
</div>
<div class="pure-u-1 pure-u-sm-10-24">
Expand Down
Loading
Loading