From 66b6ba3e1489a59a225fb5caa0ffa9090eec5543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 16 Sep 2025 16:07:10 +0200 Subject: [PATCH 1/3] Remove invalid community redirect --- src/redirect.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/redirect.rs b/src/redirect.rs index 5909ada0..32c6b9f6 100644 --- a/src/redirect.rs +++ b/src/redirect.rs @@ -2,7 +2,6 @@ use crate::render::{RenderCtx, render_redirect}; pub static PAGE_REDIRECTS: &[(&str, &str)] = &[ // Pre-2018 website pages - ("community.html", "community"), ("conduct.html", "policies/code-of-conduct"), ("contribute-bugs.html", "community"), ("contribute-community.html", "community"), From 6621b3eae0070c437cd49bd9d41cf12fba413d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 16 Sep 2025 16:08:33 +0200 Subject: [PATCH 2/3] Add check for aliased redirects --- src/render.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/render.rs b/src/render.rs index e87ba954..601221a0 100644 --- a/src/render.rs +++ b/src/render.rs @@ -261,6 +261,12 @@ pub fn render_directory(render_ctx: &RenderCtx, category: &str) -> anyhow::Resul } pub fn render_redirect(render_ctx: &RenderCtx, from: &str, to: &str) -> anyhow::Result<()> { + if from == format!("{to}.html") || format!("{from}.html") == to { + return Err(anyhow::anyhow!( + "Trying to setup redirect from {from} to {to}, which would alias" + )); + } + #[derive(Serialize)] struct Data { url: String, From b56fd83a66dfdf9d581bd31c049fb87b5a4b7b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 16 Sep 2025 16:15:42 +0200 Subject: [PATCH 3/3] Add sanity check for index files with a directory with the same name --- src/main.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8e55dde1..68977868 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use crate::teams::{encode_zulip_stream, load_rust_teams}; use anyhow::Context; use handlebars::{DirectorySourceOptions, Handlebars}; use handlebars_fluent::FluentHelper; +use std::ffi::OsStr; use std::path::{Path, PathBuf}; mod assets; @@ -94,7 +95,7 @@ fn main() -> anyhow::Result<()> { rust_version, teams, handlebars, - output_dir, + output_dir: output_dir.clone(), base_url, }; ctx.copy_asset_dir("static", "static")?; @@ -113,5 +114,42 @@ fn main() -> anyhow::Result<()> { ctx.page("404", "", &(), ENGLISH).render("404.html")?; create_redirects(&ctx)?; + sanity_check_index_pages(&output_dir)?; + + Ok(()) +} + +/// Make sure that there are no instances where we would have both `.html` and +/// a `` directory. +fn sanity_check_index_pages(directory: &Path) -> anyhow::Result<()> { + // Find all .html files + let mut html_files = vec![]; + gather_html_files(directory, &mut html_files)?; + + for file in html_files { + let basename = file.file_stem().unwrap(); + let dir = file.parent().unwrap().join(basename); + if dir.is_dir() { + return Err(anyhow::anyhow!( + "Both the `{file}` file and the `{dir}` directory exist, move `{file}` to `{dir_index}` instead", + file = file.display(), + dir = dir.display(), + dir_index = dir.join("index.html").display() + )); + } + } + + Ok(()) +} + +fn gather_html_files(path: &Path, files: &mut Vec) -> anyhow::Result<()> { + if path.is_file() && path.extension() == Some(OsStr::new("html")) { + files.push(path.to_path_buf()); + } else if path.is_dir() { + for entry in path.read_dir()? { + let entry = entry?; + gather_html_files(&entry.path(), files)?; + } + } Ok(()) }