pbsimply 3.7.0 → 3.9.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: 5d2819cbfc7057533e6c680ba3ee1b8dc30117eb532e7061a778437b2a5f3433
4
- data.tar.gz: fe9e02ca45a41d2a7649ea4b47be2230f52bf516b8b03722a4c6448be75d99b1
3
+ metadata.gz: 975c294c043cdc42f1a27b4ca670452598895f14bf8f4d4af5861e8c042827c2
4
+ data.tar.gz: fea3998951bb0c26638d11bbc53bd74644ae3b768b8676a8636888b02c89357f
5
5
  SHA512:
6
- metadata.gz: 20eefe2e45fb693831c91fda93007f64782d7ebcc37fc8a964709f506771a0e7b60b03612b16fdc5edd1f59c0e6ac0c51065c51447074bca1c3ca36727a4642b
7
- data.tar.gz: 673a659f5af31b89441e048e1896e3773d385404a9dcc9055fcc93ec85f95d2945e7daef92c6d0fd86ed23c39e73767949a5f66da732a450e97a613e08c24557
6
+ metadata.gz: 23b6806940f2c7498d99df6ded9f50c6cd4c35a97f768e75ef5411330307accdfc696026202540e2f7a6ad1f097e1b1cd014ddf8deb6234f1c727bb7c3333628
7
+ data.tar.gz: a09f739635c30597857f7401fa6df02266dc26476a41f4afff13d0692a41bec6836224ea475ef9bcee0470934780458c75730ea03e134864738357d6d5a5cf0d
@@ -13,8 +13,8 @@ class PBSimply
13
13
  @now = pbs.now
14
14
  @accs_processing = pbs.accs_processing
15
15
  @outfile = pbs.outfile
16
- frontmatter, @pos = read_frontmatter(pbs.dir, filename)
17
- @frontmatter = pbs.frontmatter.merge frontmatter
16
+ fmt, @pos = read_frontmatter(pbs.dir, filename)
17
+ @frontmatter = pbs.frontmatter.merge fmt
18
18
  @modified = true
19
19
  @proc_doc_path = nil
20
20
  end
@@ -42,7 +42,7 @@ class PBSimply
42
42
  end
43
43
 
44
44
  def draft?
45
- frontmatter["draft"]
45
+ frontmatter["draft"] || frontmatter["pbsimply_exclude"]
46
46
  end
47
47
 
48
48
  def to_a
@@ -1,6 +1,8 @@
1
1
  #!/bin/env ruby
2
2
  require 'erb'
3
3
  require 'yaml'
4
+ require 'time'
5
+ require 'date'
4
6
 
5
7
  module PBSimply::Frontmatter
6
8
  # Read Frontmatter from the document.
@@ -132,6 +134,11 @@ module PBSimply::Frontmatter
132
134
  end
133
135
 
134
136
  raise PBSimply::DocumentError.new("This document has no frontmatter") unless frontmatter
137
+
138
+ if (frontmatter["draft"] || frontmatter["pbsimply_exclude"])
139
+ return frontmatter, pos
140
+ end
141
+
135
142
  raise PBSimply::DocumentError.new("This document has no title.") unless frontmatter["title"]
136
143
 
137
144
  outpath = case
@@ -161,6 +168,7 @@ module PBSimply::Frontmatter
161
168
  this_url.sub!(%r!/\.([^/]+.html)$!, '/\1')
162
169
  this_url_external.sub!(%r!/\.([^/]+.html)$!, '/\1')
163
170
  frontmatter["page_url"] = this_url
171
+ frontmatter["page_url_external"] = this_url_external
164
172
  # URL in site with URI encode.
165
173
  frontmatter["page_url_encoded"] = ERB::Util.url_encode(this_url)
166
174
  frontmatter["page_url_encoded_external"] = ERB::Util.url_encode(this_url_external)
@@ -170,8 +178,7 @@ module PBSimply::Frontmatter
170
178
  frontmatter["title_encoded"] = ERB::Util.url_encode(frontmatter["title"])
171
179
  frontmatter["title_html_escaped"] = ERB::Util.html_escape(frontmatter["title"])
172
180
  fts = frontmatter["timestamp"]
173
- fts = fts.to_datetime if Time === fts
174
- if DateTime === fts
181
+ if Time === fts || DateTime === fts
175
182
  frontmatter["timestamp_xmlschema"] = fts.xmlschema
176
183
  frontmatter["timestamp_jplocal"] = fts.strftime('%Y年%m月%d日 %H時%M分%S秒')
177
184
  frontmatter["timestamp_rubytimestr"] = fts.strftime('%a %b %d %H:%M:%S %Z %Y')
@@ -0,0 +1,83 @@
1
+ require 'json'
2
+
3
+ class PBSimply
4
+ class Utils
5
+ def self.normalize_source_path path
6
+ root = File.expand_path Dir.pwd
7
+ path = File.expand_path path
8
+ unless root == path[0, root.length]
9
+ raise InvalidPathError.new("source path not match to document root.")
10
+ end
11
+ path[root.length..].sub(%r:^/:, "")
12
+ end
13
+ end
14
+
15
+ class JsonlLogger
16
+ def initialize enabled
17
+ @logfile = nil
18
+ if enabled
19
+ unless File.exist? ".pbsimply_var"
20
+ Dir.mkdir(".pbsimply_var")
21
+ end
22
+ @logfile = File.open(File.join(".pbsimply_var", "log.jsonl"), "a")
23
+ @logfile.flock(File::LOCK_EX)
24
+ @logfile.seek(0, IO::SEEK_END)
25
+ end
26
+ end
27
+
28
+ def generate frontmatter
29
+ return unless @logfile
30
+ @logfile.puts JSON.generate({
31
+ "action" => "generate",
32
+ "filepath" => frontmatter["source_path"],
33
+ "timestamp" => Time.now.to_i,
34
+ "title" => frontmatter["title"],
35
+ "url" => frontmatter["page_url"],
36
+ "size" => frontmatter["_size"],
37
+ "format" => frontmatter["_docformat"]
38
+ })
39
+ end
40
+
41
+ def delete fp
42
+ return unless @logfile
43
+ @logfile.puts JSON.generate({
44
+ "action" => "delete",
45
+ "filepath" => Utils.normalize_source_path(fp),
46
+ "timestamp" => Time.now.to_i
47
+ })
48
+ end
49
+ end
50
+
51
+ class TitleMapDB
52
+ def initialize enabled
53
+ @db = nil
54
+ if enabled
55
+ require 'dbm'
56
+ unless File.exist? ".pbsimply_var"
57
+ Dir.mkdir(".pbsimply_var")
58
+ end
59
+ @db = DBM.new(File.join(".pbsimply_var", "titlemap"))
60
+ @key = "title"
61
+ @key = "title_encoded" if enabled == "url_encoded"
62
+ @key = "title_html_escaped" if enabled == "html_escaped"
63
+ end
64
+ end
65
+
66
+ def []=(path, frontmatter)
67
+ return unless @db
68
+ now = Time.now.to_i
69
+ val = @db[path]
70
+ val = val ? JSON.load(val) : {}
71
+ if val[frontmatter[@key]]
72
+ val[frontmatter[@key]]["last_update"] = now
73
+ else
74
+ val[frontmatter[@key]] = {
75
+ "since" => now,
76
+ "last_update" => now
77
+ }
78
+ end
79
+
80
+ @db[path] = val
81
+ end
82
+ end
83
+ end
data/lib/pbsimply.rb CHANGED
@@ -21,6 +21,7 @@ require 'pbsimply/config-checker'
21
21
  require 'pbsimply/document'
22
22
  require 'pbsimply/eruby'
23
23
  require 'pbsimply/template-engine'
24
+ require 'pbsimply/utils'
24
25
 
25
26
  class PBSimply
26
27
  include Prayer
@@ -62,6 +63,8 @@ class PBSimply
62
63
  class InvalidConfigError < PBSimplyError
63
64
  end
64
65
  end
66
+ class InvalidPathError < PBSimplyError
67
+ end
65
68
 
66
69
  # Use Oj as JSON library for frontmatter passing if possible.
67
70
  begin
@@ -165,6 +168,9 @@ class PBSimply
165
168
  @frontmatter = {}
166
169
  @accs_processing = false
167
170
 
171
+ @logger = JsonlLogger.new config["enable_jsonl_log"]
172
+ @titlemap_db = TitleMapDB.new config["enable_titlemap"]
173
+
168
174
  $debug = (ENV["DEBUG"] == "yes")
169
175
  end
170
176
 
@@ -227,13 +233,19 @@ class PBSimply
227
233
  draft_articles = []
228
234
  target_docs = []
229
235
  effective_docs = []
236
+ exclude_files = []
230
237
  $stderr.puts "in #{@dir}..."
231
238
 
239
+ # Check exclude file
240
+ if File.exist?(File.join(@dir, ".pbsimply-exclude"))
241
+ exclude_files = File.read(File.join(@dir, ".pbsimply-exclude")).each_line.map(&:chomp).reject(&:empty?)
242
+ end
243
+
232
244
  $stderr.puts "Checking Frontmatter..."
233
245
  Dir.foreach(@dir) do |filename|
234
246
  next if filename == "." || filename == ".." || filename == ".index.md"
235
247
  next unless File.file? File.join(@dir, filename)
236
- if filename =~ /^\./ || filename =~ /^draft-/
248
+ if filename =~ /^\./ || filename =~ /^draft-/ || exclude_files.include?(filename)
237
249
  draft_articles.push({
238
250
  article_filename: filename.sub(/^(?:\.|draft-)/, ""),
239
251
  filename: filename,
@@ -343,6 +355,7 @@ class PBSimply
343
355
  tfp = File.join(@config["outdir"], @dir, tfn)
344
356
  if File.file?(tfp)
345
357
  $stderr.puts "#{df} was turn to draft."
358
+ @logger.delete dah[:source_file_path]
346
359
  @hooks.delete.run({target_file_path: tfp, source_file_path: dah[:source_file_path]})
347
360
  File.delete tfp if @config["auto_delete"]
348
361
  end
@@ -361,6 +374,7 @@ class PBSimply
361
374
  unless File.exist? v["source_path"]
362
375
  $stderr.puts "#{k} is missing."
363
376
  missing_keys.push k
377
+ @logger.delete v["source_path"]
364
378
  @hooks.delete.run({target_file_path: v["dest_path"] ,source_file_path: v["source_path"]})
365
379
  File.delete v["dest_path"] if @config["auto_delete"]
366
380
  end
@@ -442,6 +456,7 @@ class PBSimply
442
456
 
443
457
  # Generated Document
444
458
  doc = process_document(dir, filename, frontmatter, orig_filepath, ext, procdoc) # at sub-class
459
+ @logger.generate frontmatter
445
460
 
446
461
  ##### Post eRuby
447
462
  if @config["post_eruby"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pbsimply
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Haruka
@@ -43,6 +43,7 @@ files:
43
43
  - lib/pbsimply/plugger.rb
44
44
  - lib/pbsimply/prayer.rb
45
45
  - lib/pbsimply/template-engine.rb
46
+ - lib/pbsimply/utils.rb
46
47
  - themes/contribute/README.md
47
48
  - themes/default.yaml
48
49
  - themes/pandoc/_pandoc_base/.accsindex.erb
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubygems_version: 3.6.9
114
+ rubygems_version: 4.0.16
114
115
  specification_version: 4
115
116
  summary: Flexible and programmable static site generator with pluggable Markdown engines
116
117
  test_files: []