zarchitect 1.0.5 → 1.1.2
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/zarchitect/content.rb +129 -107
- data/lib/zarchitect/post.rb +23 -11
- data/lib/zarchitect.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9c2a266a2aed9e06c3f2aa9c29182481059242cb679eb5c143f222b4115b8a4e
|
|
4
|
+
data.tar.gz: '0279504f34f412438e6e8037e4c64db6520f353d7175c16898d4fc17d298e4bf'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d0e01b26b527255f421c6a726039063bcd6956910465f976002a6bac0c29c8599655e616bf4816bb710ff7f8550abacc985dbdfe984f940383c7c3e397a93c3
|
|
7
|
+
data.tar.gz: 31ac7b963d024001e2a9579e6aff6eaf784419931ceabb4a3a4c4f6dba2bdd51b155a7dcb0bffbca6d6b2097806d4bbfbca2fbadd4992e604171c35919a491e5
|
data/lib/zarchitect/content.rb
CHANGED
|
@@ -26,120 +26,126 @@ class Content < Zarchitect
|
|
|
26
26
|
def markup
|
|
27
27
|
from_script if @post.conf.has_option?("script")
|
|
28
28
|
return if @post.conf.has_option?("script")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if @m
|
|
45
|
-
GPI.print "matched regex", GPI::CLU.check_option('v')
|
|
46
|
-
# file tag found
|
|
47
|
-
# replace with corresponding html :)
|
|
48
|
-
# m[0] whole tag
|
|
49
|
-
@caption = @m[:caption]
|
|
50
|
-
new_html = ""
|
|
51
|
-
case @m[:filetype]
|
|
52
|
-
when 'img'
|
|
53
|
-
html = media_img
|
|
54
|
-
when 'img_full'
|
|
55
|
-
html = media_img_full
|
|
56
|
-
when 'video'
|
|
57
|
-
html = media_video
|
|
58
|
-
when 'audio'
|
|
59
|
-
html = media_audio
|
|
60
|
-
when 'yt'
|
|
61
|
-
html = media_youtube
|
|
62
|
-
else
|
|
63
|
-
html = "[failed to render media]"
|
|
29
|
+
if !File.exist?(@post.html_path) ||
|
|
30
|
+
(File.stat(@post.source_path).mtime > File.stat(@post.html_path).mtime)
|
|
31
|
+
GPI.print "Processing markdown", GPI::CLU.check_option('v')
|
|
32
|
+
chtml = @raw
|
|
33
|
+
@img_id = 0
|
|
34
|
+
@img_id_inc = 1
|
|
35
|
+
new_string = ""
|
|
36
|
+
regexp = /
|
|
37
|
+
\A
|
|
38
|
+
MEDIA:(?<filetype>img|img_full|video|yt|audio):
|
|
39
|
+
(?<id>[a-zA-Z0-9|._\-\/]+):"(?<caption>.*)":?(?<width>[0-9px%]*)
|
|
40
|
+
/x
|
|
41
|
+
chtml.each_line do |str|
|
|
42
|
+
if str.include?('MEDIA')
|
|
43
|
+
GPI.print "media processor: #{str}", GPI::CLU.check_option('v')
|
|
64
44
|
end
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
45
|
+
@m = regexp.match(str)
|
|
46
|
+
if @m
|
|
47
|
+
GPI.print "matched regex", GPI::CLU.check_option('v')
|
|
48
|
+
# file tag found
|
|
49
|
+
# replace with corresponding html :)
|
|
50
|
+
# m[0] whole tag
|
|
51
|
+
@caption = @m[:caption]
|
|
52
|
+
new_html = ""
|
|
53
|
+
case @m[:filetype]
|
|
54
|
+
when 'img'
|
|
55
|
+
html = media_img
|
|
56
|
+
when 'img_full'
|
|
57
|
+
html = media_img_full
|
|
58
|
+
when 'video'
|
|
59
|
+
html = media_video
|
|
60
|
+
when 'audio'
|
|
61
|
+
html = media_audio
|
|
62
|
+
when 'yt'
|
|
63
|
+
html = media_youtube
|
|
68
64
|
else
|
|
69
|
-
|
|
65
|
+
html = "[failed to render media]"
|
|
66
|
+
end
|
|
67
|
+
html.each_line do |substr|
|
|
68
|
+
if substr.lstrip
|
|
69
|
+
new_html << substr.lstrip
|
|
70
|
+
else
|
|
71
|
+
new_html << substr
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
if new_html.include?('\n')
|
|
75
|
+
str.sub!(@m[0], new_html.chomp!)
|
|
76
|
+
else
|
|
77
|
+
str.sub!(@m[0], new_html)
|
|
70
78
|
end
|
|
71
79
|
end
|
|
72
|
-
|
|
73
|
-
str.sub!(@m[0], new_html.chomp!)
|
|
74
|
-
else
|
|
75
|
-
str.sub!(@m[0], new_html)
|
|
76
|
-
end
|
|
80
|
+
new_string << str
|
|
77
81
|
end
|
|
78
|
-
new_string << str
|
|
79
|
-
end
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
# process tables
|
|
84
|
+
tfound = false
|
|
85
|
+
tables = Array.new
|
|
86
|
+
ar = new_string.split("\n")
|
|
87
|
+
ar.each_with_index do |l,i|
|
|
88
|
+
if l[0] == "|" && l[-1] == "|"
|
|
89
|
+
if tfound # part of current table
|
|
90
|
+
tables.last.add_line l
|
|
91
|
+
else # first line of a table
|
|
92
|
+
tables.push HTMLTable.new
|
|
93
|
+
tables.last.add_line l
|
|
94
|
+
tables.last.starts_at i
|
|
95
|
+
tfound = true
|
|
96
|
+
end
|
|
97
|
+
else
|
|
98
|
+
if tfound # first line after a table!
|
|
99
|
+
tables.last.ends_at i-1
|
|
100
|
+
tfound = false
|
|
101
|
+
tables.last.process
|
|
102
|
+
end
|
|
100
103
|
end
|
|
101
104
|
end
|
|
102
|
-
end
|
|
103
105
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
tables.each do |t|
|
|
107
|
+
ar = t.replace(ar)
|
|
108
|
+
end
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
ar.delete_if { |x| x.nil? }
|
|
111
|
+
str = ar.join("\n")
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
113
|
+
if @post.conf.has_option?("katex")
|
|
114
|
+
str2 = ""
|
|
115
|
+
tmp = ""
|
|
116
|
+
i = 0
|
|
117
|
+
l = str.length
|
|
118
|
+
while (i < l)
|
|
119
|
+
if str[i] == "<" && str[i+1] == "?" && str[i+2] == "k" &&
|
|
120
|
+
str[i+3] == "t" && str[i+4] == "x"
|
|
121
|
+
i += 5
|
|
122
|
+
tmp = ""
|
|
123
|
+
loop do
|
|
124
|
+
if str[i] == "?" && str[i+1] == ">"
|
|
125
|
+
GPI.print "Rendering Katex string", GPI::CLU.check_option('v')
|
|
126
|
+
str2 << Katex.render(tmp.strip)
|
|
127
|
+
i += 1
|
|
128
|
+
break
|
|
129
|
+
else
|
|
130
|
+
tmp << str[i]
|
|
131
|
+
i += 1
|
|
132
|
+
end
|
|
129
133
|
end
|
|
134
|
+
else
|
|
135
|
+
str2 << str[i]
|
|
130
136
|
end
|
|
131
|
-
|
|
132
|
-
str2 << str[i]
|
|
137
|
+
i += 1
|
|
133
138
|
end
|
|
134
|
-
|
|
139
|
+
str = str2
|
|
135
140
|
end
|
|
136
|
-
|
|
137
|
-
end
|
|
138
|
-
markdown = Redcarpet::Markdown.new(RougeHTML,
|
|
141
|
+
markdown = Redcarpet::Markdown.new(RougeHTML,
|
|
139
142
|
autolink: true)
|
|
140
|
-
|
|
143
|
+
chtml = markdown.render(str)
|
|
141
144
|
|
|
142
|
-
|
|
145
|
+
parse(chtml)
|
|
146
|
+
else
|
|
147
|
+
parse(nil)
|
|
148
|
+
end
|
|
143
149
|
|
|
144
150
|
end
|
|
145
151
|
|
|
@@ -176,25 +182,41 @@ class Content < Zarchitect
|
|
|
176
182
|
end
|
|
177
183
|
|
|
178
184
|
def parse(html)
|
|
185
|
+
node_dir = Util.mkdir(File.join(NODEDIR, @source))
|
|
179
186
|
debug_dir = File.join(File.join(BUILDIR, DEBUGSDIR), @source)
|
|
180
187
|
if GPI::CLU.check_option('d')
|
|
181
188
|
debug_dir = Util.mkdir(debug_dir)
|
|
182
189
|
end
|
|
183
190
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
191
|
+
if html.nil? || html == "nil\n"
|
|
192
|
+
@post.write_block = true
|
|
193
|
+
GPI.print "Reading notes from build dir", GPI::CLU.check_option('v')
|
|
194
|
+
ar = Dir.files(File.join(node_dir)).sort
|
|
195
|
+
ar.each do |f|
|
|
196
|
+
@nodes.push(Marshal.load(File.read(File.join(node_dir,f))))
|
|
197
|
+
if GPI::CLU.check_option('d') # debug
|
|
198
|
+
f = File.join(File.join(debug_dir), "#{i}.txt")
|
|
199
|
+
File.open(f, "w") { |f| f.write(@nodes.last.html) }
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
else
|
|
203
|
+
node = Nokogiri::HTML.fragment(html) do |config|
|
|
204
|
+
config.strict.noblanks
|
|
205
|
+
end
|
|
187
206
|
|
|
188
|
-
|
|
207
|
+
nodes = node.children.select { |c| c.class == Nokogiri::XML::Element }
|
|
189
208
|
|
|
190
|
-
|
|
191
|
-
|
|
209
|
+
nodes.each_with_index do |n,i|
|
|
210
|
+
@nodes.push ContentNode.new(n)
|
|
211
|
+
File.write(File.join(File.join(node_dir), "#{i}.node"),
|
|
212
|
+
Marshal.dump(@nodes.last))
|
|
192
213
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
214
|
+
if GPI::CLU.check_option('d') # debug
|
|
215
|
+
f = File.join(File.join(debug_dir), "#{i}.txt")
|
|
216
|
+
File.open(f, "w") { |f| f.write(@nodes.last.html) }
|
|
217
|
+
end
|
|
197
218
|
|
|
219
|
+
end
|
|
198
220
|
end
|
|
199
221
|
end
|
|
200
222
|
|
data/lib/zarchitect/post.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class Post < Zarchitect
|
|
2
|
-
attr_reader :source_path, :conf, :content, :name, :draft, :date,
|
|
2
|
+
attr_reader :source_path, :html_path, :conf, :content, :name, :draft, :date,
|
|
3
3
|
:description, :url, :category
|
|
4
|
+
attr_accessor :write_block
|
|
4
5
|
|
|
5
6
|
def initialize(path, section)
|
|
6
7
|
GPI.print "Initializing post #{path}.", GPI::CLU.check_option('v')
|
|
@@ -10,19 +11,23 @@ class Post < Zarchitect
|
|
|
10
11
|
@conf.validate_post
|
|
11
12
|
@conf.setup
|
|
12
13
|
@id = @conf.id.clone if @conf.has_option?("id")
|
|
14
|
+
if @conf.has_option?("always_write")
|
|
15
|
+
@always_write = @conf.always_write.clone
|
|
16
|
+
else
|
|
17
|
+
@always_write = false
|
|
18
|
+
end
|
|
13
19
|
@category = nil
|
|
20
|
+
@write_block = false
|
|
14
21
|
set_draft
|
|
15
22
|
set_rss
|
|
16
23
|
set_date
|
|
17
24
|
fetch_category if @conf.has_option?("category")
|
|
18
25
|
create_dir
|
|
26
|
+
set_url
|
|
27
|
+
set_html_path
|
|
19
28
|
fetch_content
|
|
20
29
|
set_description
|
|
21
30
|
set_name
|
|
22
|
-
set_url
|
|
23
|
-
set_html_path
|
|
24
|
-
# construct path for html // maybe only necessray when writing html?
|
|
25
|
-
# set date
|
|
26
31
|
setup_html
|
|
27
32
|
rss.try_item(self)
|
|
28
33
|
end
|
|
@@ -41,8 +46,14 @@ class Post < Zarchitect
|
|
|
41
46
|
end
|
|
42
47
|
|
|
43
48
|
def write_html
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
if @write_block && !@always_write
|
|
50
|
+
GPI.print "Skipping HTML write from #{@source_path}.",
|
|
51
|
+
GPI::CLU.check_option('v')
|
|
52
|
+
else
|
|
53
|
+
GPI.print "Writing HTML from #{@source_path}.",
|
|
54
|
+
GPI::CLU.check_option('v')
|
|
55
|
+
@html.write
|
|
56
|
+
end
|
|
46
57
|
end
|
|
47
58
|
|
|
48
59
|
def rss?
|
|
@@ -90,7 +101,8 @@ class Post < Zarchitect
|
|
|
90
101
|
|
|
91
102
|
def set_html_path
|
|
92
103
|
@html_path = @url.clone
|
|
93
|
-
|
|
104
|
+
#@html_path = File.join(Dir.getwd, HTMLDIR, @url)
|
|
105
|
+
@html_path = File.join(HTMLDIR, @url)
|
|
94
106
|
end
|
|
95
107
|
|
|
96
108
|
def create_dir
|
|
@@ -146,15 +158,15 @@ class Post < Zarchitect
|
|
|
146
158
|
|
|
147
159
|
def set_description
|
|
148
160
|
if @conf.has_option?('description')
|
|
149
|
-
@description = @conf.description
|
|
161
|
+
@description = @conf.description
|
|
150
162
|
elsif @conf.has_option?('preview')
|
|
151
|
-
@description = Sanitize.fragment(@conf.preview)
|
|
163
|
+
@description = Sanitize.fragment(@conf.preview)
|
|
152
164
|
else
|
|
153
165
|
nodes = @content.nodes.select { |n| n.type == "p" }
|
|
154
166
|
if nodes.count > 0
|
|
155
167
|
@description = Sanitize.fragment(nodes[0].html)
|
|
156
168
|
if @description.length > 120
|
|
157
|
-
@description = @description[0..120] << "
|
|
169
|
+
@description = @description[0..120] << "…"
|
|
158
170
|
end
|
|
159
171
|
else
|
|
160
172
|
@description = ""
|
data/lib/zarchitect.rb
CHANGED
|
@@ -10,6 +10,7 @@ class Zarchitect
|
|
|
10
10
|
|
|
11
11
|
HTMLDIR = "_html"
|
|
12
12
|
BUILDIR = "_build"
|
|
13
|
+
NODEDIR = "_build/nodes"
|
|
13
14
|
FILEDIR = "_files"
|
|
14
15
|
ASSETDIR = "_assets"
|
|
15
16
|
DRAFTDIR = "_drafts"
|
|
@@ -83,6 +84,18 @@ class Zarchitect
|
|
|
83
84
|
private
|
|
84
85
|
|
|
85
86
|
def self.rebuild
|
|
87
|
+
# delte all nodes
|
|
88
|
+
Dir[ File.join(NODEDIR, "**", "*") ].reverse.reject do |fullpath|
|
|
89
|
+
if File.directory?(fullpath)
|
|
90
|
+
GPI.print "deleting dir #{fullpath}"
|
|
91
|
+
Dir.delete(fullpath)
|
|
92
|
+
GPI.print "deleted dir #{fullpath}"
|
|
93
|
+
else
|
|
94
|
+
GPI.print "deleting file #{fullpath}"
|
|
95
|
+
File.delete(fullpath)
|
|
96
|
+
GPI.print "deleted file #{fullpath}"
|
|
97
|
+
end
|
|
98
|
+
end
|
|
86
99
|
# delete all contents of _html
|
|
87
100
|
Dir[ File.join(HTMLDIR, "**", "*") ].reverse.reject do |fullpath|
|
|
88
101
|
if File.directory?(fullpath)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zarchitect
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ryu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Yet another static website generator
|
|
14
14
|
email: ryu@tohya.net
|