Skip to content

Commit a561dd6

Browse files
authored
Merge pull request #11 from santoshxshrestha/no_internet
No internet
2 parents d204011 + 897731a commit a561dd6

File tree

6 files changed

+1331
-65
lines changed

6 files changed

+1331
-65
lines changed

src/main.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,18 @@ use tokio::sync::mpsc;
2626
#[prefix = "static/"]
2727
struct Static;
2828

29-
impl Static {
30-
fn get_styles() -> String {
31-
match Static::get("static/global.css") {
32-
Some(file) => match std::str::from_utf8(&file.data) {
33-
Ok(css) => css.to_string(),
34-
Err(e) => {
35-
eprintln!("Failed to read CSS file: {e}");
36-
String::new()
37-
}
38-
},
39-
None => {
40-
eprintln!("CSS file not found in embedded assets.");
41-
String::new()
42-
}
43-
}
44-
}
45-
46-
fn get_scripts() -> String {
47-
match Static::get("static/client.js") {
48-
Some(file) => match std::str::from_utf8(&file.data) {
49-
Ok(js) => js.to_string(),
50-
Err(e) => {
51-
eprintln!("Failed to read JS file: {e}");
52-
String::new()
53-
}
54-
},
55-
None => {
56-
eprintln!("JS file not found in embedded assets.");
29+
fn get_embedded_file(file_path: &str) -> String {
30+
match Static::get(file_path) {
31+
Some(file) => match std::str::from_utf8(&file.data) {
32+
Ok(content) => content.to_string(),
33+
Err(e) => {
34+
eprintln!("Failed to read embedded file: {e}");
5735
String::new()
5836
}
37+
},
38+
None => {
39+
eprintln!("File not found in embedded files.");
40+
String::new()
5941
}
6042
}
6143
}
@@ -134,6 +116,23 @@ struct Mdwatch {
134116
title: String,
135117
style: String,
136118
script: String,
119+
lib: Libs,
120+
}
121+
122+
struct Libs {
123+
hljs_theme_dark: String,
124+
hljs_theme_light: String,
125+
hljs_script: String,
126+
}
127+
128+
impl Default for Libs {
129+
fn default() -> Self {
130+
Self {
131+
hljs_theme_dark: get_embedded_file("static/lib/github-dark.min.css"),
132+
hljs_theme_light: get_embedded_file("static/lib/github-light.min.css"),
133+
hljs_script: get_embedded_file("static/lib/highlight.min.js"),
134+
}
135+
}
137136
}
138137

139138
#[get("/")]
@@ -174,8 +173,9 @@ async fn home(file: web::Data<String>) -> actix_web::Result<HttpResponse> {
174173
let template = Mdwatch {
175174
content: html_output,
176175
title: file_name.to_string_lossy().to_string(),
177-
style: Static::get_styles(),
178-
script: Static::get_scripts(),
176+
style: get_embedded_file("static/global.css"),
177+
script: get_embedded_file("static/client.js"),
178+
lib: Libs::default(),
179179
};
180180

181181
match template.render() {

static/client.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
function setThemeIcon(theme) {
22
const button = document.querySelector(".theme-toggle");
33
if (!button) return;
4+
45
button.innerHTML =
56
theme === "light"
6-
? '<i class="fa-regular fa-sun"></i>'
7-
: '<i class="fa-solid fa-moon"></i>';
7+
? `
8+
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" class="size-6">
9+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z" />
10+
</svg>
11+
`
12+
: `
13+
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" class="size-6">
14+
<path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z" />
15+
</svg>
16+
`;
817
}
918

1019
function highlightBlocks(root = document) {

static/lib/github-dark.min.css

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/lib/github-light.min.css

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)