zarchitect 1.0.4 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 469554302adb7c026b4d3fce6688def41c093072aae0f1d92c728ab65644d7c1
4
- data.tar.gz: afebeacb1f9fa7ed5721d9a915260d4146608e3ab9b4f67f95687544a97ef71a
3
+ metadata.gz: 125b9fe09ed687c0d528fda4690c0226fb41a224951a87415cfbac2d2cc29c24
4
+ data.tar.gz: 2749112b098facb3e31595d78b1b983176d070fd3c5baeb76e1cd82b40e29248
5
5
  SHA512:
6
- metadata.gz: aefca6ec59f4bb36de7580e9e1eae6f62f1540c4b298dbdaff6198a69f6314f3ee30ab81c6babf2506da6fc15b016d9733e9c24760c86f5f1136a7851c7cf281
7
- data.tar.gz: 607cc4bbdf68f8731de85ed3f194b787168cb3afd6ac7e9d8ec421de4521b3d893115f56f72c51e03e3d212fdc506e37a1fe8a92fe058652cab70e235766db16
6
+ metadata.gz: 478c2b63250c223640c07135e8b57739a92765ccb32461af4c9e9423321a91527bb96a7269e4eee63d89e00db5762fbdbfb75471553a3e2f883a3a5184b3843e
7
+ data.tar.gz: 2f6c2a8ec07c575dc5b156e7a2de15b5f3474162ae0fcb26f6fd492c2e9be816557aff5dd4f9becc9b3517acd2fc458f369ccfef77edb03adff94d9384c20f11
@@ -26,96 +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
- GPI.print "Processing markdown", GPI::CLU.check_option('v')
30
- chtml = @raw
31
- @img_id = 0
32
- @img_id_inc = 1
33
- new_string = ""
34
- regexp = /
35
- \A
36
- MEDIA:(?<filetype>img|img_full|video|yt|audio):
37
- (?<id>[a-zA-Z0-9|._\-\/]+):"(?<caption>.*)":?(?<width>[0-9px%]*)
38
- /x
39
- chtml.each_line do |str|
40
- if str.include?('MEDIA')
41
- GPI.print "media processor: #{str}", GPI::CLU.check_option('v')
42
- end
43
- @m = regexp.match(str)
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
- html.each_line do |substr|
66
- if substr.lstrip
67
- new_html << substr.lstrip
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
- new_html << substr
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
- if new_html.include?('\n')
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
- # process tables
82
- tfound = false
83
- tables = Array.new
84
- ar = new_string.split("\n")
85
- ar.each_with_index do |l,i|
86
- if l[0] == "|" && l[-1] == "|"
87
- if tfound # part of current table
88
- tables.last.add_line l
89
- else # first line of a table
90
- tables.push HTMLTable.new
91
- tables.last.add_line l
92
- tables.last.starts_at i
93
- tfound = true
94
- end
95
- else
96
- if tfound # first line after a table!
97
- tables.last.ends_at i-1
98
- tfound = false
99
- tables.last.process
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
- tables.each do |t|
105
- ar = t.replace(ar)
106
- end
106
+ tables.each do |t|
107
+ ar = t.replace(ar)
108
+ end
107
109
 
108
- ar.delete_if { |x| x.nil? }
109
- str = ar.join("\n")
110
+ ar.delete_if { |x| x.nil? }
111
+ str = ar.join("\n")
110
112
 
111
- if @post.conf.has_option?("katex")
112
- str = Katex.render(str)
113
- end
114
- markdown = Redcarpet::Markdown.new(RougeHTML,
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,
115
142
  autolink: true)
116
- chtml = markdown.render(str)
143
+ chtml = markdown.render(str)
117
144
 
118
- parse(chtml)
145
+ parse(chtml)
146
+ else
147
+ parse(nil)
148
+ end
119
149
 
120
150
  end
121
151
 
@@ -152,25 +182,41 @@ class Content < Zarchitect
152
182
  end
153
183
 
154
184
  def parse(html)
185
+ node_dir = Util.mkdir(File.join(NODEDIR, @source))
155
186
  debug_dir = File.join(File.join(BUILDIR, DEBUGSDIR), @source)
156
187
  if GPI::CLU.check_option('d')
157
188
  debug_dir = Util.mkdir(debug_dir)
158
189
  end
159
190
 
160
- node = Nokogiri::HTML.fragment(html) do |config|
161
- config.strict.noblanks
162
- end
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
163
206
 
164
- nodes = node.children.select { |c| c.class == Nokogiri::XML::Element }
207
+ nodes = node.children.select { |c| c.class == Nokogiri::XML::Element }
165
208
 
166
- nodes.each_with_index do |n,i|
167
- @nodes.push ContentNode.new(n)
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))
168
213
 
169
- if GPI::CLU.check_option('d') # debug
170
- f = File.join(debug_dir, "#{i}.txt")
171
- File.open(f, "w") { |f| f.write(@nodes.last.html) }
172
- end
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
173
218
 
219
+ end
174
220
  end
175
221
  end
176
222
 
@@ -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
- GPI.print "Writing HTML from #{@source_path}.", GPI::CLU.check_option('v')
45
- @html.write
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
- @html_path = File.join(Dir.getwd, HTMLDIR, @url)
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.0.4
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-23 00:00:00.000000000 Z
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