jekyll-js-protect 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jekyll-js-protect.rb +45 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 44f817aad1d66db0da5bb348f6517394f9442e642419e5cad2ae04d83a400b3a
|
4
|
+
data.tar.gz: f700a7e50426263e37f6a08e21b0642d0c0df6074ba14381b7ca90ba2320fe63
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bd9bed6c26758afbee100aa634a3dc20a6db725661c7b2d7be897163b7e500d466c75fe57d2519b2b487f37a9410f4f2eb14d4d5f91b6f56d3a13b59d2023e7
|
7
|
+
data.tar.gz: ebf838fbd8e848c406c4eef23fa6397088a5ac3ffab44369a91048e7afa55515300f3e140f577a6e95dcec1a6dacc9a5a026f13989a1f4ee3e2cdac7e26b53ac
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module Filter
|
5
|
+
def email_protect(input)
|
6
|
+
render(input, 'email_protect')
|
7
|
+
end
|
8
|
+
|
9
|
+
def tel_protect(input)
|
10
|
+
render(input, 'tel_protect')
|
11
|
+
end
|
12
|
+
|
13
|
+
def string_protect(input)
|
14
|
+
render(input, 'string_protect')
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def render(text, tag_name)
|
20
|
+
prefix = {"email_protect" => "_e", "tel_protect" => "_p", "string_protect" => "_n"}
|
21
|
+
encoded_string = Base64.encode64(text)
|
22
|
+
tag = if tag_name == "string_protect" then "span" else "a" end
|
23
|
+
"<#{tag} class=\"protect\">#{prefix[tag_name]}#{encoded_string}</#{tag}>" + "<noscript>(Base 64 Decode \"#{encoded_string}\" to see)</noscript>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
class Hook
|
27
|
+
class << self
|
28
|
+
def add_to_head(page)
|
29
|
+
require 'nokogiri'
|
30
|
+
if page.output.include? "<head"
|
31
|
+
doc = Nokogiri::HTML(page.output)
|
32
|
+
head = doc.at("head")
|
33
|
+
head.add_child("<script> document.addEventListener(\"DOMContentLoaded\",()=>{const e=document.querySelectorAll(\".protect\");e.forEach(e=>{base64=e.innerHTML;if(base64.length>=2){switch(base64.slice(0,2)){case\"_e\":e.innerHTML=a(base64);e.href=\"mailto:\"+unmask;break;case\"_p\":e.innerHTML=a(base64);e.href=\"tel:\"+unmask;break;case\"_n\":e.innerHTML=a(base64);default:break}}})});function a(e){e=e.slice(2);unmask=atob(e);return unmask}</script>")
|
34
|
+
head.add_child("<noscript><style> .protect {display: none;}</style></noscript>")
|
35
|
+
page.output = doc.to_html
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Jekyll::Hooks.register [:pages, :documents], :post_render do |page|
|
43
|
+
Jekyll::Hook.add_to_head(page)
|
44
|
+
end
|
45
|
+
Liquid::Template.register_filter(Jekyll::Filter)
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-js-protect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arsh Kohli
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: kohliarsh92@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/jekyll-js-protect.rb
|
34
|
+
homepage: https://github.com/arshxyz/jekyll-js-protect
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.3.26
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Protect sensitive details from bots in your Jekyll site
|
57
|
+
test_files: []
|