From f6ae927d5cd59c2d720d5cc5d7938c0741c223c6 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Mon, 27 Nov 2023 17:21:45 +0000 Subject: [PATCH] Add a logo as favicon --- .gitignore | 1 + crates/librqbit/src/http_api.rs | 13 ++++- crates/librqbit/webui/.gitignore | 1 - crates/librqbit/webui/assets/logo.svg | 55 +++++++++++++++++++ .../webui/dist/{app.js => assets/index.js} | 0 crates/librqbit/webui/dist/assets/logo.svg | 55 +++++++++++++++++++ crates/librqbit/webui/dist/index.html | 5 +- crates/librqbit/webui/dist/manifest.json | 11 ++++ crates/librqbit/webui/index.html | 3 +- crates/librqbit/webui/post-build | 24 ++++---- 10 files changed, 151 insertions(+), 17 deletions(-) create mode 100644 crates/librqbit/webui/assets/logo.svg rename crates/librqbit/webui/dist/{app.js => assets/index.js} (100%) create mode 100644 crates/librqbit/webui/dist/assets/logo.svg create mode 100644 crates/librqbit/webui/dist/manifest.json diff --git a/.gitignore b/.gitignore index ea8c4bf..212de44 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.DS_Store \ No newline at end of file diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index 0eb8f5b..440164d 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -198,11 +198,20 @@ impl HttpApi { }), ) .route( - "/app.js", + "/assets/index.js", get(|| async { ( [("Content-Type", "application/javascript")], - include_str!("../webui/dist/app.js"), + include_str!("../webui/dist/assets/index.js"), + ) + }), + ) + .route( + "/assets/logo.svg", + get(|| async { + ( + [("Content-Type", "image/svg+xml")], + include_str!("../webui/dist/assets/logo.svg"), ) }), ); diff --git a/crates/librqbit/webui/.gitignore b/crates/librqbit/webui/.gitignore index 97025fd..251ce6d 100644 --- a/crates/librqbit/webui/.gitignore +++ b/crates/librqbit/webui/.gitignore @@ -8,7 +8,6 @@ pnpm-debug.log* lerna-debug.log* node_modules -# dist we need this one! dist-ssr *.local diff --git a/crates/librqbit/webui/assets/logo.svg b/crates/librqbit/webui/assets/logo.svg new file mode 100644 index 0000000..37e6a2b --- /dev/null +++ b/crates/librqbit/webui/assets/logo.svg @@ -0,0 +1,55 @@ + + + + diff --git a/crates/librqbit/webui/dist/app.js b/crates/librqbit/webui/dist/assets/index.js similarity index 100% rename from crates/librqbit/webui/dist/app.js rename to crates/librqbit/webui/dist/assets/index.js diff --git a/crates/librqbit/webui/dist/assets/logo.svg b/crates/librqbit/webui/dist/assets/logo.svg new file mode 100644 index 0000000..37e6a2b --- /dev/null +++ b/crates/librqbit/webui/dist/assets/logo.svg @@ -0,0 +1,55 @@ + + + + diff --git a/crates/librqbit/webui/dist/index.html b/crates/librqbit/webui/dist/index.html index ce34a3d..7e8ded4 100644 --- a/crates/librqbit/webui/dist/index.html +++ b/crates/librqbit/webui/dist/index.html @@ -4,13 +4,14 @@ - rqbit web 0.0.1-alpha + rqbit web 4.0.0-beta.0 + - + diff --git a/crates/librqbit/webui/dist/manifest.json b/crates/librqbit/webui/dist/manifest.json new file mode 100644 index 0000000..5f70725 --- /dev/null +++ b/crates/librqbit/webui/dist/manifest.json @@ -0,0 +1,11 @@ +{ + "assets/logo.svg": { + "file": "assets/logo-083ce41b.svg", + "src": "assets/logo.svg" + }, + "index.html": { + "file": "assets/index-1c38bddb.js", + "isEntry": true, + "src": "index.html" + } +} \ No newline at end of file diff --git a/crates/librqbit/webui/index.html b/crates/librqbit/webui/index.html index 2e09371..9f68944 100644 --- a/crates/librqbit/webui/index.html +++ b/crates/librqbit/webui/index.html @@ -4,7 +4,8 @@ - rqbit web 0.0.1-alpha + rqbit web 4.0.0-beta.0 + diff --git a/crates/librqbit/webui/post-build b/crates/librqbit/webui/post-build index 05ab978..9562269 100755 --- a/crates/librqbit/webui/post-build +++ b/crates/librqbit/webui/post-build @@ -2,24 +2,26 @@ import os import json +import re os.chdir('dist') with open('manifest.json', 'r') as f: manifest = json.load(f) -for replacements in manifest.values(): - js_file = replacements['file'] - target_file = replacements['src'] - with open(target_file, 'r') as f: - target_content = f.read() +# For rust to "include_str!", we need to have predictable filenames. +# So strip all hashes out of the generated files. - target_content = target_content.replace("/" + js_file, 'app.js') - with open(target_file, 'w') as f: - f.write(target_content) +with open('index.html', 'r') as f: + index_html = f.read() - os.rename(js_file, 'app.js') +for key, item in manifest.items(): + generated_file = item['file'] + new_file = re.sub(r'^(assets/.+)-.+(\..+)$', r'\1\2', generated_file) -os.rmdir('assets') -os.remove('manifest.json') \ No newline at end of file + index_html = index_html.replace("/" + generated_file, new_file) + os.rename(generated_file, new_file) + +with open('index.html', 'w') as f: + f.write(index_html) \ No newline at end of file