Refactor and improve

This commit is contained in:
Andras Schmelczer 2026-02-03 20:26:57 +00:00
parent 1f148b2185
commit 242acff987
22 changed files with 754 additions and 1053 deletions

View file

@ -5,10 +5,11 @@ use axum::extract::Request;
use axum::http::header;
use axum::middleware::Next;
use axum::response::Response;
use regex::Regex;
use crate::state::AppState;
const OG_PLACEHOLDER: &str = r#"<meta name="x-og-placeholder" content="__NARROWIT_OG_TAGS__"/>"#;
pub async fn og_middleware(request: Request, next: Next) -> Response {
// Capture the query string before passing the request through
let query_string = request.uri().query().unwrap_or("").to_string();
@ -46,19 +47,18 @@ pub async fn og_middleware(request: Request, next: Next) -> Response {
};
let og_tags = format!(
r#"<title>Narrowit</title>
<meta property="og:title" content="Narrowit — UK Property Map" />
<meta property="og:description" content="Interactive property data visualization for England &amp; Wales" />
<meta property="og:image" content="{og_image_url}" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="{og_image_url}" />"#
r#"<meta property="og:title" content="Narrowit Every neighbourhood in England & Wales" />
<meta property="og:description" content="Explore property prices, energy ratings, crime stats, school ratings, and more across England & Wales on one interactive map." />
<meta property="og:type" content="website" />
<meta property="og:image" content="{og_image_url}" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Narrowit — Every neighbourhood in England & Wales" />
<meta name="twitter:description" content="Explore property prices, energy ratings, crime stats, school ratings, and more across England & Wales on one interactive map." />"#
);
// Replace the <title> tag with title + OG meta tags
let re = Regex::new(r"<title>Narrowit</title>").unwrap();
let html = re.replace(index_html, og_tags.as_str()).to_string();
let html = index_html.replace(OG_PLACEHOLDER, &og_tags);
let (parts, _body) = response.into_parts();
Response::from_parts(parts, Body::from(html))