Skip to content

Commit 30ae906

Browse files
committed
Documented vendored files, moved *.js and *.css files under /-/static and made fetching content from vendored directories automatic
1 parent 9e1b829 commit 30ae906

File tree

13 files changed

+224
-153
lines changed

13 files changed

+224
-153
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ cargo run -- daemon --registry-watcher=disabled
210210
cargo run -- queue add <CRATE> <VERSION>
211211
```
212212

213+
### Updating vendored sources
214+
215+
The instructions & links for updating Font Awesome can be found [on their website](https://fontawesome.com/how-to-use/on-the-web/using-with/sass). Similarly, Pure-CSS also [explains on theirs](https://purecss.io/start/).
216+
217+
When updating Font Awesome, make sure to change `$fa-font-path` in `scss/_variables.scss` (it should be at the top of the file) to `../-/static`. This will point font awesome at the correct path from which to request font and icon resources.
218+
<!--
219+
TODO: Whenever scss modules are avaliable, use [scss modules](https://sass-lang.com/documentation/at-rules/use#configuration)
220+
instead of manually editing the `_variables.scss` file. Something like this should work:
221+
```scss
222+
@use "fontawesome" with (
223+
$fa-font-path: "../-/static"
224+
);
225+
```
226+
-->
227+
213228
### Contact
214229

215230
Docs.rs is run and maintained by the [docs.rs team](https://www.rust-lang.org/governance/teams/dev-tools#docs-rs).

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn compile_sass() -> Result<(), Box<dyn Error>> {
6767
include_paths: vec![
6868
STYLE_DIR.to_owned(),
6969
concat!(env!("CARGO_MANIFEST_DIR"), "/vendor/fontawesome/scss").to_owned(),
70-
concat!(env!("CARGO_MANIFEST_DIR"), "/vendor/pure-css").to_owned(),
70+
concat!(env!("CARGO_MANIFEST_DIR"), "/vendor/pure-css/css").to_owned(),
7171
],
7272
..Default::default()
7373
});

dockerfiles/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ RUN find src -name "*.rs" -exec touch {} \;
5050
COPY templates/style templates/style
5151
COPY templates/index.js templates/
5252
COPY templates/menu.js templates/
53+
COPY vendor vendor/
5354

5455
RUN cargo build --release
5556

src/web/metrics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ mod tests {
117117
("/", "/"),
118118
("/crate/hexponent/0.2.0", "/crate/:name/:version"),
119119
("/crate/rcc/0.0.0", "/crate/:name/:version"),
120-
("/index.js", "static resource"),
121-
("/menu.js", "static resource"),
120+
("/-/static/index.js", "static resource"),
121+
("/-/static/menu.js", "static resource"),
122122
("/opensearch.xml", "static resource"),
123123
("/releases", "/releases"),
124124
("/releases/feed", "static resource"),
@@ -131,7 +131,7 @@ mod tests {
131131
("/releases/recent/1", "/releases/recent/:page"),
132132
("/robots.txt", "static resource"),
133133
("/sitemap.xml", "static resource"),
134-
("/style.css", "static resource"),
134+
("/-/static/style.css", "static resource"),
135135
];
136136

137137
wrapper(|env| {

src/web/mod.rs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ use std::{borrow::Cow, env, fmt, net::SocketAddr, path::PathBuf, sync::Arc, time
111111

112112
/// Duration of static files for staticfile and DatabaseFileHandler (in seconds)
113113
const STATIC_FILE_CACHE_DURATION: u64 = 60 * 60 * 24 * 30 * 12; // 12 months
114-
const STYLE_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/style.css"));
115-
const MENU_JS: &str = include_str!(concat!(env!("OUT_DIR"), "/menu.js"));
116-
const INDEX_JS: &str = include_str!(concat!(env!("OUT_DIR"), "/index.js"));
117114
const OPENSEARCH_XML: &[u8] = include_bytes!("opensearch.xml");
118115

119116
const DEFAULT_BIND: &str = "0.0.0.0:3000";
@@ -496,35 +493,6 @@ fn redirect_base(req: &Request) -> String {
496493
}
497494
}
498495

499-
fn style_css_handler(_: &mut Request) -> IronResult<Response> {
500-
let mut response = Response::with((status::Ok, STYLE_CSS));
501-
let cache = vec![
502-
CacheDirective::Public,
503-
CacheDirective::MaxAge(STATIC_FILE_CACHE_DURATION as u32),
504-
];
505-
506-
response
507-
.headers
508-
.set(ContentType("text/css".parse().unwrap()));
509-
response.headers.set(CacheControl(cache));
510-
511-
Ok(response)
512-
}
513-
514-
fn load_js(file_path_str: &'static str) -> IronResult<Response> {
515-
let mut response = Response::with((status::Ok, file_path_str));
516-
let cache = vec![
517-
CacheDirective::Public,
518-
CacheDirective::MaxAge(STATIC_FILE_CACHE_DURATION as u32),
519-
];
520-
response
521-
.headers
522-
.set(ContentType("application/javascript".parse().unwrap()));
523-
response.headers.set(CacheControl(cache));
524-
525-
Ok(response)
526-
}
527-
528496
fn opensearch_xml_handler(_: &mut Request) -> IronResult<Response> {
529497
let mut response = Response::with((status::Ok, OPENSEARCH_XML));
530498
let cache = vec![
@@ -540,26 +508,6 @@ fn opensearch_xml_handler(_: &mut Request) -> IronResult<Response> {
540508
Ok(response)
541509
}
542510

543-
fn ico_handler(req: &mut Request) -> IronResult<Response> {
544-
if let Some(&"favicon.ico") = req.url.path().last() {
545-
// if we're looking for exactly "favicon.ico", we need to defer to the handler that loads
546-
// from `public_html`, so return a 404 here to make the main handler carry on
547-
Err(IronError::new(
548-
error::Nope::ResourceNotFound,
549-
status::NotFound,
550-
))
551-
} else {
552-
// if we're looking for something like "favicon-20190317-1.35.0-nightly-c82834e2b.ico",
553-
// redirect to the plain one so that the above branch can trigger with the correct filename
554-
let url = ctry!(
555-
req,
556-
Url::parse(&format!("{}/favicon.ico", redirect_base(req))),
557-
);
558-
559-
Ok(redirect(url))
560-
}
561-
}
562-
563511
/// MetaData used in header
564512
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
565513
pub(crate) struct MetaData {

src/web/routes.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use super::metrics::RequestRecorder;
2-
use crate::web::{INDEX_JS, MENU_JS};
32
use iron::middleware::Handler;
4-
use iron::Request;
53
use router::Router;
64
use std::collections::HashSet;
75

@@ -12,9 +10,6 @@ pub(super) const DOC_RUST_LANG_ORG_REDIRECTS: &[&str] =
1210
pub(super) fn build_routes() -> Routes {
1311
let mut routes = Routes::new();
1412

15-
routes.static_resource("/style.css", super::style_css_handler);
16-
routes.static_resource("/index.js", |_: &mut Request| super::load_js(INDEX_JS));
17-
routes.static_resource("/menu.js", |_: &mut Request| super::load_js(MENU_JS));
1813
routes.static_resource("/robots.txt", super::sitemap::robots_txt_handler);
1914
routes.static_resource("/sitemap.xml", super::sitemap::sitemap_handler);
2015
routes.static_resource("/opensearch.xml", super::opensearch_xml_handler);

src/web/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
125125
{
126126
// route .ico files into their dedicated handler so that docs.rs's favicon is always
127127
// displayed
128-
return super::ico_handler(req);
128+
return super::statics::ico_handler(req);
129129
}
130130

131131
let router = extension!(req, Router);

0 commit comments

Comments
 (0)