Add titles for pages

This commit is contained in:
clerie 2024-07-27 22:10:29 +02:00
parent 6e0f2683cb
commit 26ea045216

View File

@ -115,7 +115,7 @@ async fn main() {
let app = Router::new() let app = Router::new()
.route("/", get(route_index)) .route("/", get(route_index))
.route("/station/:station", get(route_station_overview)) .route("/station/:station_id", get(route_station_overview))
.route("/station/:station_id/to/:dest_station_id", get(route_station_to_dest_station)) .route("/station/:station_id/to/:dest_station_id", get(route_station_to_dest_station))
.with_state(state); .with_state(state);
@ -130,7 +130,11 @@ async fn route_index(
) -> Result<Html<String>, String> { ) -> Result<Html<String>, String> {
let mut out = String::new(); let mut out = String::new();
out.push_str("<html><body><ul>\n"); out.push_str("<html><body>\n");
out.push_str("<h1>Nur ausstieg</h1>\n");
out.push_str("<p>Es gibt Züge die innerhalb Berlins fahren, aber nicht im Fahrplan Routing der DB auftauchen, weil sie entweder in Berlin enden oder in Berlin beginnen.<br>\n");
out.push_str("Diese Seite zeigt für verschiene Stationen genau diese Züge an.</p>\n");
out.push_str("<ul>\n");
for (id, station) in state.stations.into_iter() { for (id, station) in state.stations.into_iter() {
out.push_str(&format!("<li><a href=\"/station/{}\">{}</a></li>\n", id, station.name)); out.push_str(&format!("<li><a href=\"/station/{}\">{}</a></li>\n", id, station.name));
@ -143,18 +147,25 @@ async fn route_index(
async fn route_station_overview( async fn route_station_overview(
State(state): State<AppState>, State(state): State<AppState>,
Path(station): Path<String> Path(station_id): Path<String>
) -> Result<Html<String>, (StatusCode, String)> { ) -> Result<Html<String>, (StatusCode, String)> {
if !state.stations.contains_key(&station) { if !state.stations.contains_key(&station_id) {
return Err((StatusCode::NOT_FOUND, String::from("Unknown departing station"))); return Err((StatusCode::NOT_FOUND, String::from("Unknown departing station")));
} }
let station_properties = match state.stations.get(&station_id) {
Some(v) => v,
None => return Err((StatusCode::INTERNAL_SERVER_ERROR, String::from("Station properties for departing station missing"))),
};
let mut out = String::new(); let mut out = String::new();
out.push_str("<html><body><ul>\n"); out.push_str("<html><body>\n");
out.push_str(&format!("<h1>Ziele für {}</h1>\n", station_properties.name));
out.push_str("<ul>\n");
for (dest_station_id, dest_station) in state.stations.into_iter() { for (dest_station_id, dest_station) in state.stations.into_iter() {
out.push_str(&format!("<li><a href=\"/station/{}/to/{}\">{}</a></li>\n", station, dest_station_id, dest_station.name)); out.push_str(&format!("<li><a href=\"/station/{}/to/{}\">{}</a></li>\n", station_id, dest_station_id, dest_station.name));
} }
out.push_str("</ul></body></html>\n"); out.push_str("</ul></body></html>\n");
@ -202,7 +213,9 @@ async fn route_station_to_dest_station(
let mut out = String::new(); let mut out = String::new();
out.push_str("<html><body><ul>\n"); out.push_str("<html><body>\n");
out.push_str(&format!("<h1>Abfahren für {} nach {}</h1>\n", station_properties.name, dest_station_properties.name));
out.push_str("<ul>\n");
for departure in stationdata.departures { for departure in stationdata.departures {
let departure_info = match departure.departure { let departure_info = match departure.departure {