Skip to content

Commit 0e30925

Browse files
Create DEFAULT_MAX_TARGETS constant
1 parent 20a14d4 commit 0e30925

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

src/docbuilder/limits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Default for Limits {
1818
Self {
1919
memory: 3 * 1024 * 1024 * 1024, // 3 GB
2020
timeout: Duration::from_secs(15 * 60), // 15 minutes
21-
targets: 10,
21+
targets: crate::DEFAULT_MAX_TARGETS,
2222
networking: false,
2323
max_log_size: 100 * 1024, // 100 KB
2424
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ pub const BUILD_VERSION: &str = concat!(
6262
/// Example:
6363
/// `s3://rust-docs-rs//rustdoc-static/something.css`
6464
pub const RUSTDOC_STATIC_STORAGE_PREFIX: &str = "/rustdoc-static/";
65+
66+
/// Maximum number of targets allowed for a crate to be documented on.
67+
pub const DEFAULT_MAX_TARGETS: usize = 10;

src/web/page/web_page.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ macro_rules! impl_axum_webpage {
9393

9494

9595
response.extensions_mut().insert($crate::web::page::web_page::DelayedTemplateRender {
96-
context: ::tera::Context::from_serialize(&self)
97-
.expect("could not create tera context from web-page"),
96+
context: {
97+
let mut c = ::tera::Context::from_serialize(&self)
98+
.expect("could not create tera context from web-page");
99+
c.insert("DEFAULT_MAX_TARGETS", &$crate::DEFAULT_MAX_TARGETS);
100+
c
101+
},
98102
template: {
99103
let template: fn(&Self) -> ::std::borrow::Cow<'static, str> = $template;
100104
template(&self).to_string()

src/web/rustdoc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ impl RustdocPage {
317317
let is_latest_url = self.is_latest_url;
318318

319319
// Build the page of documentation
320-
let ctx = tera::Context::from_serialize(self).context("error creating tera context")?;
320+
let mut ctx = tera::Context::from_serialize(self).context("error creating tera context")?;
321+
ctx.insert("DEFAULT_MAX_TARGETS", &crate::DEFAULT_MAX_TARGETS);
321322

322323
// Extract the head and body of the rustdoc file so that we can insert it into our own html
323324
// while logging OOM errors from html rewriting

templates/rustdoc/topbar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@
209209

210210
{# Build the dropdown list showing available targets #}
211211
<ul class="pure-menu-children" id="platforms">
212-
{%- if metadata.doc_targets|length < 6 -%}
213-
{%- include "rustdoc/targets.tml" -%}
212+
{%- if metadata.doc_targets|length < DEFAULT_MAX_TARGETS -%}
213+
{%- include "rustdoc/platforms.html" -%}
214214
{%- else -%}
215215
<span class="rotate">{{ "spinner" | fas }}</span>
216216
{%- endif -%}

0 commit comments

Comments
 (0)