mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 00:59:02 +03:00
refactor: no inline scripts in HTML (#391)
* Moved 'ready' func call from index.html Inline script moved to index.js * Moved <script> out from index.html * moved inline-styling to css * minor formatting changes * changed ratio from const to let * refactor * fix tests --------- Co-authored-by: sigoden <sigoden@gmail.com>
This commit is contained in:
@@ -115,7 +115,7 @@ fn assets_override(tmpdir: TempDir, port: u16) -> Result<(), Error> {
|
||||
let url = format!("http://localhost:{port}");
|
||||
let resp = reqwest::blocking::get(&url)?;
|
||||
assert!(resp.text()?.starts_with(&format!(
|
||||
"/__dufs_v{}__/index.js;DATA",
|
||||
"/__dufs_v{}__/index.js;<template id=\"index-data\">",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
)));
|
||||
let resp = reqwest::blocking::get(&url)?;
|
||||
|
||||
@@ -65,7 +65,7 @@ pub fn tmpdir() -> TempDir {
|
||||
if *directory == DIR_ASSETS {
|
||||
tmpdir
|
||||
.child(format!("{}{}", directory, "index.html"))
|
||||
.write_str("__ASSETS_PREFIX__index.js;DATA = __INDEX_DATA__")
|
||||
.write_str("__ASSETS_PREFIX__index.js;<template id=\"index-data\">__INDEX_DATA__</template>")
|
||||
.unwrap();
|
||||
} else {
|
||||
for file in FILES {
|
||||
|
||||
@@ -62,8 +62,18 @@ pub fn encode_uri(v: &str) -> String {
|
||||
#[allow(dead_code)]
|
||||
pub fn retrieve_json(content: &str) -> Option<Value> {
|
||||
let lines: Vec<&str> = content.lines().collect();
|
||||
let line = lines.iter().find(|v| v.contains("DATA ="))?;
|
||||
let line_col = line.find("DATA =").unwrap() + 6;
|
||||
let value: Value = line[line_col..].parse().unwrap();
|
||||
let start_tag = "<template id=\"index-data\">";
|
||||
let end_tag = "</template>";
|
||||
|
||||
let line = lines.iter().find(|v| v.contains(start_tag))?;
|
||||
|
||||
let start_index = line.find(start_tag)?;
|
||||
let start_content_index = start_index + start_tag.len();
|
||||
|
||||
let end_index = line[start_content_index..].find(end_tag)?;
|
||||
let end_content_index = start_content_index + end_index;
|
||||
|
||||
let value = line[start_content_index..end_content_index].parse().ok()?;
|
||||
|
||||
Some(value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user