wip: mail obfuscation (#51)
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending approval
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending approval
This commit is contained in:
parent
ab5ce11037
commit
d352206e29
6 changed files with 44 additions and 0 deletions
|
@ -100,6 +100,7 @@ pub struct Metadata {
|
||||||
pub math: bool,
|
pub math: bool,
|
||||||
pub mermaid: bool,
|
pub mermaid: bool,
|
||||||
pub syntax_highlight: bool,
|
pub syntax_highlight: bool,
|
||||||
|
pub mail_obfsucated: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
|
@ -212,6 +213,7 @@ fn fix_images_and_integration(path: &str, html: String) -> (String, Metadata) {
|
||||||
math: false,
|
math: false,
|
||||||
mermaid: false,
|
mermaid: false,
|
||||||
syntax_highlight: false,
|
syntax_highlight: false,
|
||||||
|
mail_obfsucated: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -284,14 +286,17 @@ pub fn read_md(
|
||||||
let mut html_content = String::from_utf8(html).unwrap();
|
let mut html_content = String::from_utf8(html).unwrap();
|
||||||
|
|
||||||
let children_metadata;
|
let children_metadata;
|
||||||
|
let mail_obfsucated;
|
||||||
(html_content, children_metadata) = fix_images_and_integration(path, html_content);
|
(html_content, children_metadata) = fix_images_and_integration(path, html_content);
|
||||||
html_content = custom_img_size(html_content);
|
html_content = custom_img_size(html_content);
|
||||||
|
(html_content, mail_obfsucated) = mail_obfuscation(html_content);
|
||||||
|
|
||||||
let mut final_metadata = Metadata {
|
let mut final_metadata = Metadata {
|
||||||
info: metadata,
|
info: metadata,
|
||||||
mermaid: check_mermaid(root, mermaid_name),
|
mermaid: check_mermaid(root, mermaid_name),
|
||||||
syntax_highlight: check_code(root, &[mermaid_name.into()]),
|
syntax_highlight: check_code(root, &[mermaid_name.into()]),
|
||||||
math: check_math(&html_content),
|
math: check_math(&html_content),
|
||||||
|
mail_obfsucated,
|
||||||
};
|
};
|
||||||
final_metadata.merge(children_metadata);
|
final_metadata.merge(children_metadata);
|
||||||
|
|
||||||
|
@ -424,3 +429,32 @@ fn hljs_replace<'a>(root: &'a AstNode<'a>, mermaid_str: &str) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Obfuscate email if email found
|
||||||
|
fn mail_obfuscation(html: String) -> (String, bool) {
|
||||||
|
let modified = Arc::new(AtomicBool::new(false));
|
||||||
|
(
|
||||||
|
rewrite_str(
|
||||||
|
&html,
|
||||||
|
RewriteStrSettings {
|
||||||
|
element_content_handlers: vec![element!("a[href^='mailto:']", |el| {
|
||||||
|
modified.store(true, Ordering::SeqCst);
|
||||||
|
|
||||||
|
let link = el.get_attribute("href").unwrap();
|
||||||
|
let (_uri, mail) = &link.split_at(7);
|
||||||
|
let (before, after) = mail.split_once('@').unwrap();
|
||||||
|
|
||||||
|
let modified_mail = format!("{}<span class='at'>(at)</span>{}", before, after);
|
||||||
|
|
||||||
|
el.set_inner_content(&modified_mail, ContentType::Html);
|
||||||
|
|
||||||
|
// TODO: Change href
|
||||||
|
Ok(el.set_attribute("href", &link)?)
|
||||||
|
})],
|
||||||
|
..RewriteStrSettings::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
modified.load(Ordering::SeqCst),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ fn read_pdf(data: Vec<u8>) -> File {
|
||||||
mermaid: false,
|
mermaid: false,
|
||||||
syntax_highlight: false,
|
syntax_highlight: false,
|
||||||
math: false,
|
math: false,
|
||||||
|
mail_obfsucated: false,
|
||||||
},
|
},
|
||||||
content: format!(
|
content: format!(
|
||||||
r#"<embed
|
r#"<embed
|
||||||
|
|
6
static/js/mail_obfuscation.js
Normal file
6
static/js/mail_obfuscation.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
window.addEventListener("load", () => {
|
||||||
|
Array.from(document.getElementsByClassName("at")).forEach((elem) => {
|
||||||
|
// TODO: Change link
|
||||||
|
elem.textContent = "@";
|
||||||
|
});
|
||||||
|
});
|
|
@ -36,6 +36,7 @@
|
||||||
{{#mermaid}}{{>libs/mermaid_footer.html}}{{/mermaid}}
|
{{#mermaid}}{{>libs/mermaid_footer.html}}{{/mermaid}}
|
||||||
{{#math}}{{>libs/katex_footer.html}}{{/math}}
|
{{#math}}{{>libs/katex_footer.html}}{{/math}}
|
||||||
{{#syntax_highlight}}{{>libs/hljs_footer.html}}{{/syntax_highlight}}
|
{{#syntax_highlight}}{{>libs/hljs_footer.html}}{{/syntax_highlight}}
|
||||||
|
{{#mail_obfsucated}}{{>libs/mail_obfuscater.html}}{{/mail_obfsucated}}
|
||||||
{{/metadata}} {{/post}} {{/data}}
|
{{/metadata}} {{/post}} {{/data}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
{{#metadata}} {{#mermaid}}{{>libs/mermaid_footer.html}}{{/mermaid}}
|
{{#metadata}} {{#mermaid}}{{>libs/mermaid_footer.html}}{{/mermaid}}
|
||||||
{{#math}}{{>libs/katex_footer.html}}{{/math}}
|
{{#math}}{{>libs/katex_footer.html}}{{/math}}
|
||||||
{{#syntax_highlight}}{{>libs/hljs_footer.html}}{{/syntax_highlight}}
|
{{#syntax_highlight}}{{>libs/hljs_footer.html}}{{/syntax_highlight}}
|
||||||
|
{{#mail_obfsucated}}{{>libs/mail_obfuscater.html}}{{/mail_obfsucated}}
|
||||||
{{/metadata}} {{/content}} {{/data}}
|
{{/metadata}} {{/content}} {{/data}}
|
||||||
<script src="/js/cours.js"></script>
|
<script src="/js/cours.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
1
templates/libs/mail_obfuscater.html
Normal file
1
templates/libs/mail_obfuscater.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<script src="/js/mail_obfuscation.js"></script>
|
Loading…
Reference in a new issue