tangled
alpha
login
or
join now
cherry.computer
/
website
My personal site
cherry.computer
htmx
tailwind
axum
askama
0
fork
atom
overview
issues
pulls
pipelines
feat: link to source code in footer
cherry.computer
2 months ago
361bde4c
94dde481
verified
This commit was signed with the committer's
known signature
.
cherry.computer
SSH Key Fingerprint:
SHA256:SIA77Ll0IpMb8Xd3RtaGT+PBIGIePhJJg5W2r6Td7cc=
+46
-5
4 changed files
expand all
collapse all
unified
split
justfile
server
src
main.rs
templates
index.rs
templates
index.html
+1
-1
justfile
···
8
8
watchexec --restart --watch esbuild.js npm start
9
9
10
10
[working-directory('server')]
11
11
-
serve-rs args="" $RUST_LOG=env('RUST_LOG', 'debug,selectors=warn,html5ever=warn'):
11
11
+
serve-rs args="" $RUST_LOG=env('RUST_LOG', 'debug,selectors=warn,html5ever=warn') $MYIVO_GIT_SHA=`jj log -r@ --no-graph -T commit_id`:
12
12
watchexec --restart --ignore "target/**" cargo run {{ args }}
+11
-4
server/src/main.rs
···
1
1
mod scrapers;
2
2
mod templates;
3
3
4
4
-
use std::{net::SocketAddr, sync::Arc};
4
4
+
use std::{env, net::SocketAddr, sync::Arc};
5
5
6
6
use crate::scrapers::{MediaType, apple_music::AppleMusicClient};
7
7
#[cfg(debug_assertions)]
8
8
use crate::templates::am_auth_flow::AuthFlowTemplate;
9
9
use crate::templates::{
10
10
-
index::{IndexOptions, RootTemplate},
10
10
+
index::{IndexOptions, RootTemplate, Shas},
11
11
media::{MediaTemplate, fetch_media_of_type},
12
12
};
13
13
···
27
27
#[derive(Clone)]
28
28
struct AppState {
29
29
apple_music_client: Arc<AppleMusicClient>,
30
30
+
shas: Shas,
30
31
}
31
32
32
33
#[tokio::main]
···
34
35
tracing_subscriber::fmt::init();
35
36
36
37
let apple_music_client = Arc::new(AppleMusicClient::new()?);
37
37
-
let state = AppState { apple_music_client };
38
38
+
let shas = Shas {
39
39
+
website: env::var("MYIVO_GIT_SHA").ok(),
40
40
+
};
41
41
+
let state = AppState {
42
42
+
apple_music_client,
43
43
+
shas,
44
44
+
};
38
45
39
46
let app = Router::new()
40
47
.route("/", get(render_index_handler))
···
63
70
Query(options): Query<IndexOptions>,
64
71
State(state): State<AppState>,
65
72
) -> impl IntoResponse {
66
66
-
let template = RootTemplate::new(state.apple_music_client, &options);
73
73
+
let template = RootTemplate::new(state.apple_music_client, state.shas, &options);
67
74
template.render().map(Html).map_err(|err| {
68
75
tracing::error!("failed to render index: {err:?}");
69
76
StatusCode::INTERNAL_SERVER_ERROR
+8
server/src/templates/index.rs
···
15
15
16
16
type MediaList = [(MediaType, Option<Media>); 3];
17
17
18
18
+
#[derive(Debug, Clone)]
19
19
+
pub struct Shas {
20
20
+
pub website: Option<String>,
21
21
+
}
22
22
+
18
23
#[derive(Template, Debug, Clone)]
19
24
#[template(path = "index.html")]
20
25
pub struct RootTemplate {
21
26
media: MediaList,
22
27
consumption_verb: &'static str,
28
28
+
shas: Shas,
23
29
}
24
30
25
31
impl RootTemplate {
26
32
pub fn new(
27
33
apple_music_client: Arc<AppleMusicClient>,
34
34
+
shas: Shas,
28
35
#[allow(unused_variables)] options: &IndexOptions,
29
36
) -> RootTemplate {
30
37
#[cfg(debug_assertions)]
···
41
48
RootTemplate {
42
49
media,
43
50
consumption_verb,
51
51
+
shas,
44
52
}
45
53
}
46
54
+26
server/templates/index.html
···
54
54
</div>
55
55
<p class="font-serif text-3xl text-pink-50">Free Palestine 🇵🇸</p>
56
56
</div>
57
57
+
<div class="bg-gray-800">
58
58
+
<div
59
59
+
class="flex w-full justify-around px-5 py-2 leading-5 text-pink-50 italic"
60
60
+
>
61
61
+
<p>
62
62
+
running on
63
63
+
<a
64
64
+
href="https://tangled.org/cherry.computer/nixos"
65
65
+
target="_blank"
66
66
+
class="text-pink-300 hover:text-pink-500"
67
67
+
>NixOS</a
68
68
+
>
69
69
+
</p>
70
70
+
{% if let Some(website_rev) = shas.website %}
71
71
+
<p>
72
72
+
site revision
73
73
+
<a
74
74
+
href="https://tangled.org/cherry.computer/website/tree/{{website_rev}}"
75
75
+
target="_blank"
76
76
+
class="text-pink-300 hover:text-pink-500"
77
77
+
>{{ website_rev | fmt("{:.8}") }}</a
78
78
+
>
79
79
+
</p>
80
80
+
{% endif %}
81
81
+
</div>
82
82
+
</div>
57
83
</div>
58
84
</body>
59
85
</html>