Skip to content

Commit

Permalink
Improve rendering speed by moving settings generation after theme ren…
Browse files Browse the repository at this point in the history
…dering
  • Loading branch information
GuillaumeGomez committed Oct 3, 2024
1 parent e0b0851 commit 47f40d4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
11 changes: 8 additions & 3 deletions tests/compile-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use clippy_lints::LintInfo;
use clippy_lints::declared_lints::LINTS;
use clippy_lints::deprecated_lints::{DEPRECATED, DEPRECATED_VERSION, RENAMED};
use pulldown_cmark::{Options, Parser, html};
use rinja::{Template, filters::Safe};
use rinja::Template;
use rinja::filters::Safe;
use serde::Deserialize;
use test_utils::IS_RUSTC_TEST_SUITE;
use ui_test::custom_flags::Flag;
Expand Down Expand Up @@ -394,7 +395,7 @@ struct Renderer<'a> {
}

impl<'a> Renderer<'a> {
fn markdown(&self, input: &str) -> Safe<String> {
fn markdown(input: &str) -> Safe<String> {
let parser = Parser::new_ext(input, Options::all());
let mut html_output = String::new();
html::push_html(&mut html_output, parser);
Expand Down Expand Up @@ -465,7 +466,11 @@ impl DiagnosticCollector {
.collect();
metadata.sort_unstable_by(|a, b| a.id.cmp(&b.id));

fs::write("util/gh-pages/index.html", Renderer { lints: &metadata }.render().unwrap()).unwrap();
fs::write(
"util/gh-pages/index.html",
Renderer { lints: &metadata }.render().unwrap(),
)
.unwrap();
});

(Self { sender }, handle)
Expand Down
4 changes: 2 additions & 2 deletions util/gh-pages/index_template.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<!--
Welcome to a Clippy's lint list, at least the source code of it. If you are
interested in contributing to this website checkout `util/gh-pages/index.html`
interested in contributing to this website checkout `util/gh-pages/index_template.html`
inside the rust-clippy repository.
Otherwise, have a great day =^.^=
Expand Down Expand Up @@ -164,7 +164,7 @@ <h2 class="panel-title">
</header>

<div class="list-group lint-docs">
<div class="list-group-item lint-doc-md">{(markdown(lint.docs))}</div>
<div class="list-group-item lint-doc-md">{(Self::markdown(lint.docs))}</div>
<div class="lint-additional-info-container">
{# Applicability #}
<div class="lint-additional-info-item">
Expand Down
49 changes: 26 additions & 23 deletions util/gh-pages/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ function setTheme(theme, store) {
}
}

// loading the theme after the initial load
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
const theme = loadValue('theme');
if (prefersDark.matches && !theme) {
setTheme("coal", false);
} else {
setTheme(theme, false);
}
let disableShortcuts = loadValue('disable-shortcuts') === "true";
document.getElementById("disable-shortcuts").checked = disableShortcuts;

window.searchState = {
timeout: null,
inputElem: document.getElementById("search-input"),
Expand Down Expand Up @@ -161,9 +150,6 @@ function handleShortcut(ev) {
}
}

document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);

function toggleElements(filter, value) {
let needsUpdate = false;
let count = 0;
Expand Down Expand Up @@ -271,13 +257,13 @@ const GROUPS_FILTER_DEFAULT = {
cargo: true,
complexity: true,
correctness: true,
deprecated: false,
nursery: true,
pedantic: true,
perf: true,
restriction: true,
style: true,
suspicious: true,
deprecated: false,
};
const LEVEL_FILTERS_DEFAULT = {
allow: true,
Expand All @@ -287,7 +273,6 @@ const LEVEL_FILTERS_DEFAULT = {
};
const APPLICABILITIES_FILTER_DEFAULT = {
Unspecified: true,
Unresolved: true,
MachineApplicable: true,
MaybeIncorrect: true,
HasPlaceholders: true,
Expand Down Expand Up @@ -570,9 +555,6 @@ function generateSearch() {
searchState.inputElem.addEventListener("paste", handleInputChanged);
}

generateSettings();
generateSearch();

function scrollToLint(lintId) {
const target = document.getElementById(lintId);
if (!target) {
Expand Down Expand Up @@ -617,7 +599,28 @@ function parseURLFilters() {
}
}

parseURLFilters();
scrollToLintByURL();
filters.filterLints();
onEachLazy(document.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
// loading the theme after the initial load
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
const theme = loadValue('theme');
if (prefersDark.matches && !theme) {
setTheme("coal", false);
} else {
setTheme(theme, false);
}

let disableShortcuts = loadValue('disable-shortcuts') === "true";
// To prevent having a "flash", we give back time to the web browser to finish rendering with
// theme applied before finishing the rendering.
setTimeout(() => {
document.getElementById("disable-shortcuts").checked = disableShortcuts;

document.addEventListener("keypress", handleShortcut);
document.addEventListener("keydown", handleShortcut);

generateSettings();
generateSearch();
parseURLFilters();
scrollToLintByURL();
filters.filterLints();
onEachLazy(document.querySelectorAll("pre > code.language-rust"), el => hljs.highlightElement(el));
}, 0);

0 comments on commit 47f40d4

Please sign in to comment.