jekyll-articled-webpush 1.0.5
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/articled.json +3 -0
- data/lib/jekyll-articled-webpush.rb +144 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d9dbcb08dce8c640663758a5e68c908bef98a637e2a6e501c11a0c045966931
|
4
|
+
data.tar.gz: 92ea4060748e63d902483fbbd91f43a510a9cd4e5f6ac43399a439c7db63ce86
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba3c7659a894f01d56d47c3781a95b1fa076e30e5cf4ca0015c4fbd03ba520fe767d722151e4a9e9605b4e361a157662c63d2ccc95fb8b08458d9577cc370fb6
|
7
|
+
data.tar.gz: 91116a4b3797977099cd210306f58cdca67df7033768331d4760602040766d615ec2b7edc50af1816eca919d42e58e2a2628c0a6592c11122c0d5dc97250e51c
|
data/lib/articled.json
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require "json"
|
4
|
+
require "jekyll"
|
5
|
+
|
6
|
+
class ArticledWidget < Liquid::Tag
|
7
|
+
|
8
|
+
def initialize(tagName, content, tokens)
|
9
|
+
super
|
10
|
+
@content = content
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
def render(context)
|
16
|
+
|
17
|
+
articled_config = context.registers[:site].config["articled"] || false
|
18
|
+
|
19
|
+
#checking _config.yml
|
20
|
+
if !articled_config
|
21
|
+
raise "jekyll-articled-webpush: Missing configuration!"
|
22
|
+
end
|
23
|
+
|
24
|
+
if !articled_config.key?("api_public_key")
|
25
|
+
raise "jekyll-articled-webpush: Mising API Public Key In _config.yml"
|
26
|
+
end
|
27
|
+
|
28
|
+
if !articled_config.key?("app_public_key")
|
29
|
+
raise "jekyll-articled-webpush: Mising APP Public Key In _config.yml"
|
30
|
+
end
|
31
|
+
|
32
|
+
if articled_config.key?("service_worker")
|
33
|
+
if articled_config["service_worker"] != "service-worker.js"
|
34
|
+
raise "jekyll-articled-webpush: Can not use '" + articled_config["service_worker"] + "' as a service worker. Please rename your service worker to 'service-worker.js'"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
#read articled settings
|
40
|
+
articled_file = File.join(File.dirname(__FILE__), "articled.json")
|
41
|
+
articled_json = File.read(articled_file)
|
42
|
+
articled = JSON.parse(articled_json)
|
43
|
+
|
44
|
+
if articled["running"]
|
45
|
+
|
46
|
+
userDir = articled["userDir"]
|
47
|
+
appName = articled["appName"]
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
#widget script
|
52
|
+
%Q{#{widget_articled(userDir, appName)}}
|
53
|
+
|
54
|
+
else
|
55
|
+
|
56
|
+
#setup service worker
|
57
|
+
sw_file = context.registers[:site].in_source_dir("service-worker.js")
|
58
|
+
|
59
|
+
if articled_config.key?("service_worker")
|
60
|
+
if !File.exist?(context.registers[:site].in_source_dir("articled-worker.js"))
|
61
|
+
aw_file = context.registers[:site].in_source_dir("articled-worker.js")
|
62
|
+
File.write(aw_file, sw_articled)
|
63
|
+
File.write(sw_file, " importScripts(\"articled-worker.js\");", mode: "a")
|
64
|
+
end
|
65
|
+
else
|
66
|
+
File.write(sw_file, sw_articled)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
userDir = ""
|
72
|
+
appName = ""
|
73
|
+
|
74
|
+
#get user dir
|
75
|
+
articled_server = Net::HTTP.post_form( URI.parse("https://articled.io/api/user/public"), [["apiPublicKey", articled_config["api_public_key"]]] )
|
76
|
+
user_dir_data = JSON.parse(articled_server.body)
|
77
|
+
|
78
|
+
if user_dir_data["status"]
|
79
|
+
userDir = user_dir_data["userDir"]
|
80
|
+
else
|
81
|
+
raise "jekyll-articled-webpush: Invalid Public API Key"
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
#get app name
|
87
|
+
articled_server = Net::HTTP.post_form( URI.parse("https://webpush.articled.io/api/app/public"), [["apiPublicKey", articled_config["api_public_key"]]] )
|
88
|
+
apps_data = JSON.parse(articled_server.body)
|
89
|
+
|
90
|
+
apps = apps_data["apps"]
|
91
|
+
for app in apps do
|
92
|
+
if app["appPublicKey"] == articled_config["app_public_key"]
|
93
|
+
appName = app["name"]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
if appName.length == 0
|
98
|
+
raise "jekyll-articled-webpush: Could not find any apps matching the provided Public APP Key"
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
#save json
|
104
|
+
new_json = { "running": true, "userDir": userDir, "appName": appName }
|
105
|
+
File.write(File.join(File.dirname(__FILE__), "articled.json"), JSON.generate(new_json))
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
#widget script
|
110
|
+
%Q{#{widget_articled(userDir, appName)}}
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
#service worker string
|
119
|
+
def sw_articled
|
120
|
+
return "self.addEventListener(\"push\",function(event){var data={};if(event.data){data=event.data.json();} var title=data.title||\"Untitled\";var message=data.message||\"Empty\";var tag=data.tag||null;var icon=data.icon||null;var url=data.url;var image=data.image;event.waitUntil(self.registration.showNotification(title,{body:message,tag:tag,icon:icon,image:image,data:url}));});self.addEventListener(\"notificationclick\",function(event){var url=event.notification.data;if(url){clients.openWindow(url);}else{return;}});self.addEventListener(\"activate\",function(event){event.waitUntil(self.clients.claim());});"
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
#widget script
|
126
|
+
def widget_articled(userDir, appName)
|
127
|
+
return "<script>\n" +
|
128
|
+
"(function(a,r,t,i,c,l) {\n" +
|
129
|
+
"i=r.getElementsByTagName(\"head\")[0],\n" +
|
130
|
+
"c=r.createElement(\"script\"), \n" +
|
131
|
+
"l=r.createElement(\"link\");" +
|
132
|
+
"c.type=\"text/javascript\";c.src=t+a+\".js\";\n" +
|
133
|
+
"l.type=\"text/css\";l.rel=\"stylesheet\";\n" +
|
134
|
+
"l.href=t+a+\".css\";i.appendChild(l);\n" +
|
135
|
+
"i.appendChild(c);\n" +
|
136
|
+
"})(\"articled\",document,\"https://articled.io/widget/" + userDir + "/" + appName + "/\");\n" +
|
137
|
+
"</script>"
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
Liquid::Template.register_tag "articled_widget", self
|
144
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-articled-webpush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Articled.io
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Integrate the Articled.io widget with your Jekyll blog and start sending
|
14
|
+
webpush notifications immediately!
|
15
|
+
email: plugins@articled.io
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/articled.json
|
21
|
+
- lib/jekyll-articled-webpush.rb
|
22
|
+
homepage: https://github.com/articled-io/jekyll-articled-webpush
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.7.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Integrate the Articled.io widget with your Jekyll blog and start sending
|
46
|
+
webpush notifications immediately!
|
47
|
+
test_files: []
|