zarchitect 1.0.3 → 1.1.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/zarchitect/content.rb +133 -83
- data/lib/zarchitect/post.rb +20 -8
- data/lib/zarchitect.rb +14 -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: cd8b90e59014447960fa45a91254772db7ec7cfacae1114ae091e8e91c7f21d1
|
|
4
|
+
data.tar.gz: d96209b417853a4f8f1247958b12bdfb569cc8a9e0b0d10e41880e38c6d6ddb2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 76917b275599638f9893d83edc46f675e4950043cc0a816ee704a88eeae62cf96c58a947dd0609665508855c8b2ab92cde5f806a2c86943071813737636de9d7
|
|
7
|
+
data.tar.gz: c9ef305baed4ae733bd44b6fd22774cb21155a341bc8d272dcc2154c52b864f025362390af19855f335ac6f5760b0fb84b9461d255592ee90d631251a29612b1
|
data/lib/zarchitect/content.rb
CHANGED
|
@@ -26,92 +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
|
-
|
|
110
|
+
ar.delete_if { |x| x.nil? }
|
|
111
|
+
str = ar.join("\n")
|
|
109
112
|
|
|
110
|
-
|
|
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
|
|
133
|
+
end
|
|
134
|
+
else
|
|
135
|
+
str2 << str[i]
|
|
136
|
+
end
|
|
137
|
+
i += 1
|
|
138
|
+
end
|
|
139
|
+
str = str2
|
|
140
|
+
end
|
|
141
|
+
markdown = Redcarpet::Markdown.new(RougeHTML,
|
|
111
142
|
autolink: true)
|
|
112
|
-
|
|
143
|
+
chtml = markdown.render(str)
|
|
113
144
|
|
|
114
|
-
|
|
145
|
+
parse(chtml)
|
|
146
|
+
else
|
|
147
|
+
parse(nil)
|
|
148
|
+
end
|
|
115
149
|
|
|
116
150
|
end
|
|
117
151
|
|
|
@@ -148,25 +182,41 @@ class Content < Zarchitect
|
|
|
148
182
|
end
|
|
149
183
|
|
|
150
184
|
def parse(html)
|
|
185
|
+
node_dir = Util.mkdir(File.join(NODEDIR, @source))
|
|
151
186
|
debug_dir = File.join(File.join(BUILDIR, DEBUGSDIR), @source)
|
|
152
187
|
if GPI::CLU.check_option('d')
|
|
153
188
|
debug_dir = Util.mkdir(debug_dir)
|
|
154
189
|
end
|
|
155
190
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
|
159
206
|
|
|
160
|
-
|
|
207
|
+
nodes = node.children.select { |c| c.class == Nokogiri::XML::Element }
|
|
161
208
|
|
|
162
|
-
|
|
163
|
-
|
|
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))
|
|
164
213
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
|
169
218
|
|
|
219
|
+
end
|
|
170
220
|
end
|
|
171
221
|
end
|
|
172
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
|
data/lib/zarchitect.rb
CHANGED
|
@@ -4,11 +4,13 @@ require 'erb'
|
|
|
4
4
|
require 'sanitize'
|
|
5
5
|
require 'rss'
|
|
6
6
|
require 'nokogiri'
|
|
7
|
+
require 'katex'
|
|
7
8
|
|
|
8
9
|
class Zarchitect
|
|
9
10
|
|
|
10
11
|
HTMLDIR = "_html"
|
|
11
12
|
BUILDIR = "_build"
|
|
13
|
+
NODEDIR = "_build/nodes"
|
|
12
14
|
FILEDIR = "_files"
|
|
13
15
|
ASSETDIR = "_assets"
|
|
14
16
|
DRAFTDIR = "_drafts"
|
|
@@ -82,6 +84,18 @@ class Zarchitect
|
|
|
82
84
|
private
|
|
83
85
|
|
|
84
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
|
|
85
99
|
# delete all contents of _html
|
|
86
100
|
Dir[ File.join(HTMLDIR, "**", "*") ].reverse.reject do |fullpath|
|
|
87
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.0
|
|
4
|
+
version: 1.1.0
|
|
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
|