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 mermaid: bool,
|
||||
pub syntax_highlight: bool,
|
||||
pub mail_obfsucated: bool,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
|
@ -212,6 +213,7 @@ fn fix_images_and_integration(path: &str, html: String) -> (String, Metadata) {
|
|||
math: false,
|
||||
mermaid: 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 children_metadata;
|
||||
let mail_obfsucated;
|
||||
(html_content, children_metadata) = fix_images_and_integration(path, html_content);
|
||||
html_content = custom_img_size(html_content);
|
||||
(html_content, mail_obfsucated) = mail_obfuscation(html_content);
|
||||
|
||||
let mut final_metadata = Metadata {
|
||||
info: metadata,
|
||||
mermaid: check_mermaid(root, mermaid_name),
|
||||
syntax_highlight: check_code(root, &[mermaid_name.into()]),
|
||||
math: check_math(&html_content),
|
||||
mail_obfsucated,
|
||||
};
|
||||
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,
|
||||
syntax_highlight: false,
|
||||
math: false,
|
||||
mail_obfsucated: false,
|
||||
},
|
||||
content: format!(
|
||||
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}}
|
||||
{{#math}}{{>libs/katex_footer.html}}{{/math}}
|
||||
{{#syntax_highlight}}{{>libs/hljs_footer.html}}{{/syntax_highlight}}
|
||||
{{#mail_obfsucated}}{{>libs/mail_obfuscater.html}}{{/mail_obfsucated}}
|
||||
{{/metadata}} {{/post}} {{/data}}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
{{#metadata}} {{#mermaid}}{{>libs/mermaid_footer.html}}{{/mermaid}}
|
||||
{{#math}}{{>libs/katex_footer.html}}{{/math}}
|
||||
{{#syntax_highlight}}{{>libs/hljs_footer.html}}{{/syntax_highlight}}
|
||||
{{#mail_obfsucated}}{{>libs/mail_obfuscater.html}}{{/mail_obfsucated}}
|
||||
{{/metadata}} {{/content}} {{/data}}
|
||||
<script src="/js/cours.js"></script>
|
||||
</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