wallpapers: map of all wallpapers
This commit is contained in:
parent
e61ef1d4c3
commit
19622b8dff
6 changed files with 99 additions and 22 deletions
|
|
@ -7,7 +7,7 @@ use std::path::PathBuf;
|
|||
const WALLPAPERS_PATH: &str = "/public/wallpapers";
|
||||
const CRATE_PATH: &str = env!("CARGO_MANIFEST_DIR");
|
||||
|
||||
const IMPORTS: &str = r#"use crate::types::{Location,Wallpaper};"#;
|
||||
const IMPORTS: &str = r#"use crate::types::{Gps, Location, Wallpaper};"#;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Metadata {
|
||||
|
|
@ -185,8 +185,19 @@ fn main() {
|
|||
println!("Precise location is `{}`", precise);
|
||||
println!("Broad location is `{}`", broad);
|
||||
|
||||
// Construct struct
|
||||
let wallpaper_struct = format!("&Wallpaper {{ file: \"{}\", date: \"{}\", location: Location {{ precise: \"{}\", broad: \"{}\", latitude: {}, longitude: {} }} }},\n", wallpaper.file, wallpaper.date, precise, broad, wallpaper.latitude, wallpaper.longitude);
|
||||
// Construct structs
|
||||
let gps_struct = format!(
|
||||
"Gps {{ latitude: {}, longitude: {} }}",
|
||||
wallpaper.latitude, wallpaper.longitude
|
||||
);
|
||||
let location_struct = format!(
|
||||
"Location {{ precise: \"{}\", broad: \"{}\", gps: {} }}",
|
||||
precise, broad, gps_struct
|
||||
);
|
||||
let wallpaper_struct = format!(
|
||||
"&Wallpaper {{ file: \"{}\", date: \"{}\", location: {} }},\n",
|
||||
wallpaper.file, wallpaper.date, location_struct
|
||||
);
|
||||
|
||||
wallpapers.push_str(&wallpaper_struct);
|
||||
}
|
||||
|
|
|
|||
21
src/main.rs
21
src/main.rs
|
|
@ -12,10 +12,15 @@ mod wallpapers;
|
|||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
rocket::build()
|
||||
let server = rocket::build()
|
||||
.mount("/", FileServer::from("public"))
|
||||
.mount("/", routes![root, email])
|
||||
.register("/", catchers![not_found])
|
||||
.mount("/", routes![root, email, wallpapers_route])
|
||||
.register("/", catchers![not_found]);
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
server
|
||||
} else {
|
||||
server
|
||||
.attach(
|
||||
rocket_async_compression::CachedCompression::path_suffix_fairing(vec![
|
||||
// Code
|
||||
|
|
@ -28,6 +33,7 @@ fn rocket() -> _ {
|
|||
)
|
||||
.attach(cache::CacheControl::default())
|
||||
.attach(minify::Minify)
|
||||
}
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
|
|
@ -59,3 +65,12 @@ fn email() -> templates::Email<'static> {
|
|||
year: chrono::Utc::now().year(),
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/wallpapers")]
|
||||
fn wallpapers_route() -> templates::Wallpapers<'static> {
|
||||
templates::Wallpapers {
|
||||
title: "Wallpapers",
|
||||
year: chrono::Utc::now().year(),
|
||||
wallpapers: WALLPAPERS,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
use crate::filters;
|
||||
use crate::types::*;
|
||||
use askama::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[derive(askama::Template)]
|
||||
#[template(path = "pages/root.html")]
|
||||
pub struct Root<'a> {
|
||||
pub title: &'a str,
|
||||
|
|
@ -20,7 +19,7 @@ struct RootResponder<'a> {
|
|||
template: Root<'a>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[derive(askama::Template)]
|
||||
#[template(path = "pages/404.html")]
|
||||
pub struct NotFound<'a> {
|
||||
pub title: &'a str,
|
||||
|
|
@ -32,7 +31,7 @@ struct NotFoundResponder<'a> {
|
|||
template: NotFound<'a>,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[derive(askama::Template)]
|
||||
#[template(path = "pages/email.html")]
|
||||
pub struct Email<'a> {
|
||||
pub title: &'a str,
|
||||
|
|
@ -43,3 +42,16 @@ pub struct Email<'a> {
|
|||
struct EmailResponder<'a> {
|
||||
template: Email<'a>,
|
||||
}
|
||||
|
||||
#[derive(askama::Template)]
|
||||
#[template(path = "pages/wallpapers.html")]
|
||||
pub struct Wallpapers<'a> {
|
||||
pub title: &'a str,
|
||||
pub year: i32,
|
||||
pub wallpapers: &'static [&'static Wallpaper],
|
||||
}
|
||||
|
||||
#[derive(rocket::Responder)]
|
||||
struct WallpapersResponder<'a> {
|
||||
template: Wallpapers<'a>,
|
||||
}
|
||||
|
|
|
|||
11
src/types.rs
11
src/types.rs
|
|
@ -26,9 +26,20 @@ pub struct Link {
|
|||
pub struct Location {
|
||||
pub precise: &'static str,
|
||||
pub broad: &'static str,
|
||||
pub gps: Gps,
|
||||
}
|
||||
|
||||
pub struct Gps {
|
||||
pub latitude: f32,
|
||||
pub longitude: f32,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Gps {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "[{}, {}]", self.latitude, self.longitude)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Wallpaper {
|
||||
pub file: &'static str,
|
||||
pub date: &'static str,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ module.exports = {
|
|||
extend: {
|
||||
height: {
|
||||
almostscreen: '90vh',
|
||||
halfscreen: '60vh',
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
27
templates/pages/wallpapers.html
Normal file
27
templates/pages/wallpapers.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{% extends "content.html" %}
|
||||
|
||||
{% block content %}
|
||||
<p class="mb-2">Pictures I took around the world</p>
|
||||
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
||||
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
|
||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
||||
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
|
||||
|
||||
<div id="map" class="w-full h-halfscreen"></div>
|
||||
|
||||
<script>
|
||||
let map = L.map('map').setView([0, 0], 1);
|
||||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
maxZoom: 19,
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||
}).addTo(map);
|
||||
</script>
|
||||
|
||||
{% for wallpaper in wallpapers %}
|
||||
<script>
|
||||
var marker = L.marker({{ wallpaper.location.gps }}).addTo(map);
|
||||
marker.bindPopup(`<a target="_blank" href="{{ wallpaper.file }}">{{ wallpaper.location.precise }}</a><br>{{ wallpaper.location.broad }}<br><b>{{ wallpaper.date }}</b>`);
|
||||
</script>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue