zarchitect 1.0.5 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec1a57213025231ece03b982ebf9e7145cf521b5d1889f491dd6c1425defda0d
4
- data.tar.gz: 19decff40b55aff8b31cad0276eac7ac94713d74f68360c01795e2e0db06345f
3
+ metadata.gz: cd8b90e59014447960fa45a91254772db7ec7cfacae1114ae091e8e91c7f21d1
4
+ data.tar.gz: d96209b417853a4f8f1247958b12bdfb569cc8a9e0b0d10e41880e38c6d6ddb2
5
5
  SHA512:
6
- metadata.gz: bb657af48d43221378fcf2923c3f0e23840c602412178e0516e17c704abc55c6622a29ae1b0bd4fde4632c55a2bcc38c918082100c8102922b6280d7776d4d40
7
- data.tar.gz: 91a4123c607e751c52d1012beecbe04f77f43279335cee3ad4fbaf43a649deaeead16b41eec5540ceb836fe756904f21db6ef516f2df821885181060259416bf
6
+ metadata.gz: 76917b275599638f9893d83edc46f675e4950043cc0a816ee704a88eeae62cf96c58a947dd0609665508855c8b2ab92cde5f806a2c86943071813737636de9d7
7
+ data.tar.gz: c9ef305baed4ae733bd44b6fd22774cb21155a341bc8d272dcc2154c52b864f025362390af19855f335ac6f5760b0fb84b9461d255592ee90d631251a29612b1
@@ -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
- 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
- str2 = ""
113
- tmp = ""
114
- i = 0
115
- l = str.length
116
- while (i < l)
117
- if str[i] == "<" && str[i+1] == "?" && str[i+2] == "k" &&
118
- str[i+3] == "t" && str[i+4] == "x"
119
- i += 5
120
- tmp = ""
121
- loop do
122
- if str[i] == "?" && str[i+1] == ">"
123
- str2 << Katex.render(tmp.strip)
124
- i += 1
125
- break
126
- else
127
- tmp << str[i]
128
- i += 1
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
- else
132
- str2 << str[i]
137
+ i += 1
133
138
  end
134
- i += 1
139
+ str = str2
135
140
  end
136
- str = str2
137
- end
138
- markdown = Redcarpet::Markdown.new(RougeHTML,
141
+ markdown = Redcarpet::Markdown.new(RougeHTML,
139
142
  autolink: true)
140
- chtml = markdown.render(str)
143
+ chtml = markdown.render(str)
141
144
 
142
- parse(chtml)
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
- node = Nokogiri::HTML.fragment(html) do |config|
185
- config.strict.noblanks
186
- 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
187
206
 
188
- nodes = node.children.select { |c| c.class == Nokogiri::XML::Element }
207
+ nodes = node.children.select { |c| c.class == Nokogiri::XML::Element }
189
208
 
190
- nodes.each_with_index do |n,i|
191
- @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))
192
213
 
193
- if GPI::CLU.check_option('d') # debug
194
- f = File.join(debug_dir, "#{i}.txt")
195
- File.open(f, "w") { |f| f.write(@nodes.last.html) }
196
- 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
197
218
 
219
+ end
198
220
  end
199
221
  end
200
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
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.5
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: 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