jekyll-hackclub 1.0.0 → 1.2.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 +4 -4
- data/lib/channel-tag.rb +24 -0
- data/lib/emoji.rb +18 -0
- data/lib/jekyll-hackclub.rb +5 -61
- data/lib/mentions.rb +24 -0
- data/lib/server-bridge.rb +79 -0
- data/lib/user-tag.rb +24 -0
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de886c16f8e0135c5cf61d9918210a0ea31905bb51f5292d539fcd1ff27aaf4c
|
4
|
+
data.tar.gz: 6649112e691948cb83a94829364d5a4c0b22b617c4c3e5d600aeccab79973200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fef2b54b058eba122b6ef06cf801d271fdefc4d00e71b9a5c554f09a6fe03272f194a5f0d629c45f8a812ba1a1ec0091f0f0795df31cf9df4f99bcbfe0ef6af
|
7
|
+
data.tar.gz: f39585ba8cc849022224092743768f83c8d2864942523526aade46a4326b6de4efcb2603ca1ec81d89572c97c840c808bdc7c581799026d78de2b5d1b4dc63fe
|
data/lib/channel-tag.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "./server-bridge"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class HackclubChannelTag < Liquid::Tag
|
6
|
+
def initialize(tagName, content, tokens)
|
7
|
+
super
|
8
|
+
content = content.strip()
|
9
|
+
@id, *rest = content.split(" ", 2)
|
10
|
+
keys = rest.join.split(".")
|
11
|
+
@data = HackclubRequest.raw_channel(@id).dig("channel").dig(*keys)
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(context)
|
15
|
+
if @data == nil
|
16
|
+
%Q{null}
|
17
|
+
else
|
18
|
+
%Q{#{@data}}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Liquid::Template.register_tag "channel", HackclubChannelTag
|
24
|
+
end
|
data/lib/emoji.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "./server-bridge"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class HackclubEmoji < Liquid::Tag
|
6
|
+
def initialize(tagName, content, tokens)
|
7
|
+
super
|
8
|
+
@id = content.gsub(/\A:+|:+\z/, '').strip
|
9
|
+
@img_url = HackclubRequest.resolve_emoji(@id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(context)
|
13
|
+
%Q{<img src="#{@img_url}" title=":#{@id}:" alt=":#{@id}:" class="hackclub-emoji">}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Liquid::Template.register_tag "emoji", HackclubEmoji
|
18
|
+
end
|
data/lib/jekyll-hackclub.rb
CHANGED
@@ -1,61 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
module Jekyll
|
7
|
-
class HackclubMention < Liquid::Tag
|
8
|
-
def resolve_username(userid)
|
9
|
-
uri = URI(@host+"/users.info/"+userid)
|
10
|
-
res = Net::HTTP.get_response(uri)
|
11
|
-
begin
|
12
|
-
data = JSON.parse(res.body)
|
13
|
-
rescue
|
14
|
-
return "unavailable"
|
15
|
-
end
|
16
|
-
|
17
|
-
if res.is_a?(Net::HTTPSuccess)
|
18
|
-
data = JSON.parse(res.body)
|
19
|
-
return data.dig("user", "name")
|
20
|
-
else
|
21
|
-
return "unknown"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def resolve_channel(channelid)
|
26
|
-
uri = URI(@host+"/conversations.info/"+channelid)
|
27
|
-
res = Net::HTTP.get_response(uri)
|
28
|
-
begin
|
29
|
-
data = JSON.parse(res.body)
|
30
|
-
rescue
|
31
|
-
return "unavailable"
|
32
|
-
end
|
33
|
-
|
34
|
-
if res.is_a?(Net::HTTPSuccess)
|
35
|
-
data = JSON.parse(res.body)
|
36
|
-
return data.dig("channel", "name")
|
37
|
-
else
|
38
|
-
return "unknown"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def initialize(tagName, content, tokens)
|
43
|
-
super
|
44
|
-
@host = Jekyll.configuration({})['HACKCLUB_API'] || "https://slack.mathias.hackclub.app"
|
45
|
-
@args = content.split(" ; ").map(&:strip)
|
46
|
-
@id = @args[0]
|
47
|
-
end
|
48
|
-
|
49
|
-
def render(context)
|
50
|
-
if @id && @id.start_with?("U")
|
51
|
-
display_name = @args[1] || resolve_username(@id)
|
52
|
-
%Q{<a href="https://hackclub.slack.com/team/#{@id}" class="hackclub-mention hackclub-user" target="_blank">@#{display_name}</a>}
|
53
|
-
elsif @id && @id.start_with?("C")
|
54
|
-
display_name = @args[1] || resolve_channel(@id)
|
55
|
-
%Q{<a href="https://hackclub.slack.com/archives/#{@id}" class="hackclub-mention hackclub-channel" target="_blank">##{display_name}</a>}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
Liquid::Template.register_tag "hackclub", self
|
60
|
-
end
|
61
|
-
end
|
1
|
+
require_relative "./emoji"
|
2
|
+
require_relative "./mentions"
|
3
|
+
require_relative "./server-bridge"
|
4
|
+
require_relative "./user-tag"
|
5
|
+
require_relative "./channel-tag"
|
data/lib/mentions.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "./server-bridge"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class HackclubMention < Liquid::Tag
|
6
|
+
def initialize(tagName, content, tokens)
|
7
|
+
super
|
8
|
+
@args = content.split(" ; ").map(&:strip)
|
9
|
+
@id = @args[0]
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(context)
|
13
|
+
if @id && @id.start_with?("U")
|
14
|
+
display_name = @args[1] || HackclubRequest.resolve_username(@id)
|
15
|
+
%Q{<a href="https://hackclub.slack.com/team/#{@id}" class="hackclub-mention hackclub-user" target="_blank">@#{display_name}</a>}
|
16
|
+
elsif @id && @id.start_with?("C")
|
17
|
+
display_name = @args[1] || HackclubRequest.resolve_channel(@id)
|
18
|
+
%Q{<a href="https://hackclub.slack.com/archives/#{@id}" class="hackclub-mention hackclub-channel" target="_blank">##{display_name}</a>}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Liquid::Template.register_tag "mention", HackclubMention
|
24
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
module HackclubRequest
|
6
|
+
DEFAULT_EMOJI = "https://emoji.slack-edge.com/T0266FRGM/alibaba-question/c5ba32ce553206b8.png" # :alibaba-question:
|
7
|
+
@host = Jekyll.configuration({})['HACKCLUB_API'] || "https://slack.mathias.hackclub.app"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :host
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.resolve_emoji(id)
|
14
|
+
uri = URI("#{host}/emoji/#{id.strip}")
|
15
|
+
res = Net::HTTP.get_response(uri)
|
16
|
+
|
17
|
+
if res.is_a?(Net::HTTPSuccess)
|
18
|
+
res.body
|
19
|
+
else
|
20
|
+
DEFAULT_EMOJI
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.raw_user(userid)
|
25
|
+
uri = URI("#{host}/users.info/#{userid}")
|
26
|
+
res = Net::HTTP.get_response(uri)
|
27
|
+
|
28
|
+
data = JSON.parse(res.body)
|
29
|
+
if res.is_a?(Net::HTTPSuccess)
|
30
|
+
data
|
31
|
+
else
|
32
|
+
{}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.resolve_username(userid)
|
37
|
+
uri = URI("#{host}/users.info/#{userid}")
|
38
|
+
res = Net::HTTP.get_response(uri)
|
39
|
+
|
40
|
+
begin
|
41
|
+
data = JSON.parse(res.body)
|
42
|
+
if res.is_a?(Net::HTTPSuccess)
|
43
|
+
data.dig("user", "name") || "unknown"
|
44
|
+
else
|
45
|
+
"unknown"
|
46
|
+
end
|
47
|
+
rescue
|
48
|
+
"unavailable"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.raw_channel(channelid)
|
53
|
+
uri = URI("#{host}/conversations.info/#{channelid}")
|
54
|
+
res = Net::HTTP.get_response(uri)
|
55
|
+
|
56
|
+
data = JSON.parse(res.body)
|
57
|
+
if res.is_a?(Net::HTTPSuccess)
|
58
|
+
data
|
59
|
+
else
|
60
|
+
{}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.resolve_channel(channelid)
|
65
|
+
uri = URI("#{host}/conversations.info/#{channelid}")
|
66
|
+
res = Net::HTTP.get_response(uri)
|
67
|
+
|
68
|
+
begin
|
69
|
+
data = JSON.parse(res.body)
|
70
|
+
if res.is_a?(Net::HTTPSuccess)
|
71
|
+
data.dig("channel", "name") || "unknown"
|
72
|
+
else
|
73
|
+
"unknown"
|
74
|
+
end
|
75
|
+
rescue
|
76
|
+
"unavailable"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/user-tag.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require_relative "./server-bridge"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class HackclubUserTag < Liquid::Tag
|
6
|
+
def initialize(tagName, content, tokens)
|
7
|
+
super
|
8
|
+
content = content.strip()
|
9
|
+
@id, *rest = content.split(" ", 2)
|
10
|
+
keys = rest.join.split(".")
|
11
|
+
@data = HackclubRequest.raw_user(@id).dig("user").dig(*keys)
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(context)
|
15
|
+
if @data == nil
|
16
|
+
%Q{null}
|
17
|
+
else
|
18
|
+
%Q{#{@data}}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Liquid::Template.register_tag "user", HackclubUserTag
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-hackclub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MathiasDPX
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: jekyll
|
@@ -38,18 +37,19 @@ dependencies:
|
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0'
|
41
|
-
description:
|
42
|
-
email:
|
43
40
|
executables: []
|
44
41
|
extensions: []
|
45
42
|
extra_rdoc_files: []
|
46
43
|
files:
|
44
|
+
- lib/channel-tag.rb
|
45
|
+
- lib/emoji.rb
|
47
46
|
- lib/jekyll-hackclub.rb
|
48
|
-
|
47
|
+
- lib/mentions.rb
|
48
|
+
- lib/server-bridge.rb
|
49
|
+
- lib/user-tag.rb
|
49
50
|
licenses:
|
50
51
|
- MIT
|
51
52
|
metadata: {}
|
52
|
-
post_install_message:
|
53
53
|
rdoc_options: []
|
54
54
|
require_paths:
|
55
55
|
- lib
|
@@ -64,8 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
68
|
-
signing_key:
|
67
|
+
rubygems_version: 3.6.7
|
69
68
|
specification_version: 4
|
70
69
|
summary: Jekyll plugin for HackClub
|
71
70
|
test_files: []
|