Merge pull request #472 from MananJethwani/issue/407

added root functionality for block external link feature
This commit is contained in:
Kelson 2021-03-23 10:54:22 +01:00 committed by GitHub
commit 1f45c42c32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -221,9 +221,9 @@ void ContentResponse::inject_externallinks_blocker()
kainjow::mustache::data data; kainjow::mustache::data data;
data.set("root", m_root); data.set("root", m_root);
auto script_tag = render_template(RESOURCE::templates::external_blocker_part_html, data); auto script_tag = render_template(RESOURCE::templates::external_blocker_part_html, data);
m_content = appendToFirstOccurence( m_content = prependToFirstOccurence(
m_content, m_content,
"<head>", "</head[ \\t]*>",
script_tag); script_tag);
} }

View File

@ -1,5 +1,6 @@
const root = document.querySelector( `link[type='root']` ).getAttribute("href");
// `block_path` variable used by openzim/warc2zim to detect whether URL blocking is enabled or not // `block_path` variable used by openzim/warc2zim to detect whether URL blocking is enabled or not
var block_path = "/catch/external"; var block_path = `${root}/catch/external`;
// called only on external links // called only on external links
function capture_event(e, target) { target.setAttribute("href", encodeURI(block_path + "?source=" + target.href)); } function capture_event(e, target) { target.setAttribute("href", encodeURI(block_path + "?source=" + target.href)); }