Working template, revived JS.

This commit is contained in:
2026-06-13 11:20:18 +01:00
parent 02992f56ec
commit 2c4f4bb90e
2 changed files with 131 additions and 11 deletions
+120
View File
@@ -0,0 +1,120 @@
<!DOCTYPE HTML>
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Merriweather+Sans:ital,wght@0,300..800;1,300..800&display=swap">
<link rel="stylesheet" href="https://cdn.ballast-data.co.uk/theme.css">
<link rel="icon" type="image/x-icon" href="https://cdn.ballast-data.co.uk/Icon.svg">
<script>
function querySt(attribute) {
url = window.location.search.substring(1);
substrings = url.split('&');
for (i=0;i<substrings.length;i++) {
ft = substrings[i].split('=');
if (ft[0] == attribute) {
return ft[1];
}
}
}
function prefill(attribute) {
var value = querySt(attribute);
value = decodeURIComponent(value);
if(value !== 'undefined'){
document.getElementById(attribute).value = value;
} else {
document.getElementById(attribute).value = '';
}
}
</script>
</head>
<body>
<div class="wrapper">
<div class="header">
<table>
<tr>
<td>
<a href="/fares"><img src="https://cdn.ballast-data.co.uk/Icon-NB.svg"></a>
</td>
<td>
Ballast-Data Product <br>
<a href="/">Home</a> |
<a href="/fares">Fares</a> |
<a href="/stations">Stations</a> |
<a href="/about">About Us</a>
</td>
</tr>
</table>
</div>
<div class="content">
<div class="branding" style="margin-left: auto; margin-right: auto; width: fit-content; padding: var(--pad);">
<a href="/fares"><img height=80px src="https://cdn.ballast-data.co.uk/Logo.svg"></a>
<b style="font-size: 4em; line-height: 1; font-weight: 600; color: var(--A1)"> Fares </b>
</div>
<div class="query">
<form method="get" action="/fares">
<input
name="origin"
id="origin"
required
autocomplete="on"
placeholder="Origin*"
style="width: 10em;"
/>
<script>prefill('origin')</script>
<input
name="destination"
id="destination"
required
autocomplete="on"
placeholder="Destination*"
style="width: 10em;"
/>
<script>prefill('destination')</script>
<input
name="toc"
id="toc"
autocomplete="on"
placeholder="TOC"
style="width: 5em;"
/>
<script>prefill('toc')</script>
<input type="submit" value="Go!" style="width: 5em;">
</form>
</div>
<!-- Content -->
</div>
<br>
<div class="footer">
<span>
Powered by National Rail Enquiries. This site is not accredited by National Rail. <br>
We use information from
<a href="https://opendata.nationalrail.co.uk/" target="_blank">National Rail Open Data</a>
and
<a href="https://raildata.org.uk/" target="_blank">Rail Data Marketplace</a>. <br>
This service is not to be used for safety critical purposes. <br>
</span>
</div>
</div>
</body>
</html>
+11 -11
View File
@@ -1,20 +1,20 @@
use axum::{Router, routing::get};
use std::fs;
use axum::{Router, response::Html, routing::get};
#[tokio::main]
async fn main() {
let app = Router::new()
.route(
"/",
get(|| async { "Incorrect reverse-proxy, '/' should be handled elsewhere." }),
)
.route("/fares", get(app));
.route("/", get(|| async { "Incorrect reverse-proxy for '/'." }))
.route("/fares", get(app_content));
let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn app() -> String {
let tree = html::text_content::Division::builder()
.text("Hello Fares!")
.build();
tree.to_string()
async fn app_content() -> Html<String> {
Html(
fs::read_to_string("./media/template.html")
.unwrap_or_default()
.to_string(),
)
}