From 512455bf72a451e293d5bcbd8940650060a63289 Mon Sep 17 00:00:00 2001 From: NetworkCats Date: Fri, 6 Mar 2026 20:28:03 +0800 Subject: [PATCH] feat: add noindex meta tag to IP query result pages --- src/handlers.rs | 3 +++ templates/index.html | 8 ++++++-- tests/integration.rs | 35 ++++++++++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index d1b7bd3..0a5a968 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -34,6 +34,7 @@ pub struct AppState { struct IndexTemplate { ip: String, query: String, + is_query: bool, site_domain: Arc, css_version: u64, asn: String, @@ -554,9 +555,11 @@ pub async fn root( let t = build_translations(locale); + let is_query = query.ip.is_some(); let template = IndexTemplate { ip: info.ip.clone(), query: query.ip.unwrap_or_default(), + is_query, site_domain: state.site_domain.clone(), css_version: static_assets::asset_version("style.css"), asn: format_asn(&info), diff --git a/templates/index.html b/templates/index.html index 91014ae..37c9996 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,10 +3,11 @@ {% block title %}{{ t_title }} - {{ site_domain }}{% endblock %} {% block head_meta %} + {% if is_query %} + + {% else %} - - @@ -18,6 +19,9 @@ {% endfor %} + {% endif %} + + {% endblock %} {% block head_preconnect %} diff --git a/tests/integration.rs b/tests/integration.rs index 80c86cc..b088f04 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -674,11 +674,14 @@ async fn html_contains_seo_meta_tags() { let app = build_test_app(); let (status, body) = get_with_headers( &app, - "/en?ip=45.77.77.77", - vec![( - "User-Agent", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", - )], + "/en", + vec![ + ( + "User-Agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", + ), + ("CF-Connecting-IP", "45.77.77.77"), + ], ) .await; assert_eq!(status, StatusCode::OK); @@ -692,6 +695,28 @@ async fn html_contains_seo_meta_tags() { assert!(body.contains("hreflang=\"en\"")); assert!(body.contains("hreflang=\"x-default\"")); assert!(body.contains("hreflang=\"es\"")); + assert!(!body.contains("noindex")); +} + +#[tokio::test] +async fn html_query_result_has_noindex() { + let app = build_test_app(); + let (status, body) = get_with_headers( + &app, + "/en?ip=45.77.77.77", + vec![( + "User-Agent", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", + )], + ) + .await; + assert_eq!(status, StatusCode::OK); + assert!(body.contains("")); + assert!(!body.contains("