Skip to content

Extract vendored css from style.css into a separate file vendored.css… #993

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

Merged
merged 2 commits into from
Aug 22, 2020

Conversation

cynecx
Copy link
Contributor

@cynecx cynecx commented Aug 22, 2020

… (Fixes #992)

Closes #992.

I haven't actually tested this myself yet.

@jyn514 jyn514 self-assigned this Aug 22, 2020
@jyn514 jyn514 added S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed A-frontend Area: Web frontend labels Aug 22, 2020
@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

This breaks the CSS pretty badly unfortunately:
image

To test locally you can use cargo run start-web-server, there's instructions in the readme.

@cynecx
Copy link
Contributor Author

cynecx commented Aug 22, 2020

I'll look into it.

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

I think you just need to add <link rel="stylesheet" href="/-/static/vendored.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" /> to templates/rustdoc/head.html.

@cynecx
Copy link
Contributor Author

cynecx commented Aug 22, 2020

@jyn514 I considered that but my counter-thought was that an actual docs page wouldn't use pure-css or fontawesome. Well, I was/am wrong :)

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Yeah, docs.rs adds the header bar at the top which uses both.

@cynecx
Copy link
Contributor Author

cynecx commented Aug 22, 2020

Also I am getting an error when I am trying to run this locally:

2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable DOCSRS_BUILD_ATTEMPTS is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable REGISTRY_INDEX_PATH is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable DOCSRS_MAX_POOL_SIZE is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable DOCSRS_MIN_POOL_IDLE is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable DOCSRS_S3_BUCKET is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable CRATESFYI_GITHUB_USERNAME is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable CRATESFYI_GITHUB_ACCESSTOKEN is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable DOCSRS_MAX_FILE_SIZE is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable DOCSRS_MAX_FILE_SIZE_HTML is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable DOCSRS_MAX_PARSE_MEMORY is not set
2020/08/22 18:30:54 [DEBUG] cratesfyi::config: optional configuration variable DOCSRS_REGISTRY_GC_INTERVAL is not set
2020/08/22 18:30:54 [TRACE] cratesfyi::web::page::templates: Loading templates
2020/08/22 18:30:54 [ERROR] cratesfyi::web::page::templates: Failed to load rustc resource suffix: Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42P01"), message: "relation \"config\" does not exist", detail: None, hint: None, position: Some(Original(19)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_relation.c"), line: Some(1191), routine: Some("parserOpenTable") }) }
2020/08/22 18:30:54 [TRACE] cratesfyi::web::page::templates: Finished loading templates
2020/08/22 18:30:54 [INFO] cratesfyi::web: Running docs.rs web server on http://0.0.0.0:3000
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Db, cause: Some(DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState("42P01"), message: "relation \"crates\" does not exist", detail: None, hint: None, position: Some(Original(236)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_relation.c"), line: Some(1191), routine: Some("parserOpenTable") }) }', src/web/releases.rs:97:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Any idea?

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Run docker-compose up -d db s3.

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Oh hold on you already have the server running, run cargo run database migrate. I need to add that to the README.

@cynecx
Copy link
Contributor Author

cynecx commented Aug 22, 2020

@jyn514 Ah let me try that.

I am suspicious that adding <link rel="stylesheet" href="/-/static/vendored.css?{{ docsrs_version() | slugify }}" type="text/css" media="all" /> to templates/rustdoc/head.html won't help because the vendored.css file must be included before all the other css inclusions (like normalize.css, ...).

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

head.html doesn't inherit from base.html, so you should be able to put vendored.css before anything else.

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Oh I see, you mean in https://github.com/rust-lang/docs.rs/blob/master/src/utils/html.rs#L26 it gets appended instead of prepended. Well, we could probably change that to prepend if necessary.

@cynecx
Copy link
Contributor Author

cynecx commented Aug 22, 2020

@jyn514 Okay, I am currently running cargo run -- build crate regex 1.3.1, I guess that takes some time? I'll try applying the html rewriting changes in the meantime.

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

If you push your changes I could run a build locally so it doesn't take as long (I have all the stuff cached already).

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Opened #995 to make this less painful

let (head_selector, body_selector, first_stylesheet_selector) = (
"head".parse().unwrap(),
"body".parse().unwrap(),
"link[type='text/css'][href*='normalize']".parse().unwrap(),
Copy link
Contributor Author

@cynecx cynecx Aug 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consider this a hack because we are assuming that the first stylesheet included by rustdoc is normalize.css which might not be the case in the future (But I gotta say, having css style selectors is pretty nice :)).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't depend on it being first, though, does it? The reason it needs to come before normalize is because pure-css bundles its own whole separate copy, but I don't think pure-css duplicates any other of the rustdoc styles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't depend on it being first, though, does it?

Well, it just needs to be positioned before rustdoc.css. By just inserting the vendored.css link before or after all head elements doesn't seem to be a good idea either.

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Yeah, this looks a lot better :)

image

code, pre, a.test-arrow {
    font-family: "Source Code Pro",monospace;
}

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Could you also add a test that the code has the right font (not monospace)? It will be kuchiki test, see https://github.com/rust-lang/docs.rs/blob/master/src/web/rustdoc.rs#L1485 for an example and around https://github.com/rust-lang/docs.rs/blob/master/src/test/fakes.rs#L128 for things you can do with a fake_release().

@cynecx
Copy link
Contributor Author

cynecx commented Aug 22, 2020

@jyn514 Uhm, how does checking the evaluated font exactly work. I mean afaiu kuchiki will simply parse the html but won't evaluate the css?

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Hmm that's a good question .. I'm not sure :/ let me read through the docs.

@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Yeah I don't see a way to do this without adding full UI tests unfortunately :/ let's merge the fix for now and we can try to add the test later.

@jyn514 jyn514 merged commit b93e53f into rust-lang:master Aug 22, 2020
@jyn514
Copy link
Member

jyn514 commented Aug 22, 2020

Thanks for the PR!

@cynecx cynecx deleted the fix-vendored-css branch August 22, 2020 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Web frontend S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Monospace fonts are broken again
2 participants