-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix_bible.rb
49 lines (38 loc) · 1.39 KB
/
fix_bible.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require './bible_books'
BIBLE_SRC = './ESV'.freeze
BIBLE_DST = './wiki/ESV'.freeze
`rm -rf #{BIBLE_DST}`
def chapter_number(str)
str.scan(/-(\d+)/).flatten.first
end
Dir.glob("#{BIBLE_SRC}/*/*.md").each do |chapter|
book = File.dirname(chapter).gsub("#{BIBLE_SRC}/", '')
folder = book_folder(book)
filename = File.basename(chapter)
content = File.read(chapter)
number = chapter_number(chapter)
# fix the verses
content.gsub!(/(###### \d+) /) { |v| "\n\n#{v}\n\n" }
# fix headers
content.gsub!(/(\S[.,;'"\-])([A-Z](?:[^"].)+)$/m) { |_h| "#{Regexp.last_match(1)}\n\n##### #{Regexp.last_match(2)}" }
# chapter
if filename.match(/-\d+/)
# add links back to the book
content = "# [[ESV/#{folder}/#{book}|#{book} #{number}]]\n#{content}"
# book title
else
# find all the chapters
chapters =
Dir
.glob("#{BIBLE_SRC}/#{book}/*.md")
.filter { |c| c.match(/-\d+/) }
.sort_by { |c| chapter_number(c).to_i }
.map { |c| "- [[#{File.basename(c)}|Chapter #{chapter_number(c)}]]" }
.join("\n")
content = "# #{book}\n\n[[#{book}-1|Start Reading →]]\n\n#{chapters}\n\nlinks: [[The Bible]]"
end
`mkdir -p '#{BIBLE_DST}/#{folder}'`
File.write("#{BIBLE_DST}/#{folder}/#{filename}", content)
end
book_order = BOOKS.keys.map { |b| "- [[#{b}]]" }.join("\n")
File.write("#{BIBLE_DST}/The Bible.md", "# The Bible\n\n#{book_order}")