-
Notifications
You must be signed in to change notification settings - Fork 2
/
the_guy.rb
46 lines (35 loc) · 1.07 KB
/
the_guy.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
require 'FileUtils'
require_relative 'sanitizer'
require_relative 'markdowner'
def doit
#create a copy of the folder
from_path = "prd_original"
to_path = "prd_markdown"
copy_entire_folder(from_path, to_path)
#for each file that is a html
Dir.glob(to_path + '/**/*.html') do |html_filename|
puts(html_filename)
html = File.read(html_filename)
#sanitize it
sanitized_html = PaizoSanitizer.clean(html)
#markdown it
markdown = Markdowner.doit(sanitized_html)
#change broken links
markdown = markdown.gsub(/\.html/, "")
#change image links
markdown = markdown.gsub(/\/pathfinderRPG\/prd\//, "")
#create a file with the same name.md
markdown_filename = html_filename.gsub('.html', '.md')
#write to file
File.open(markdown_filename, 'w') {|f| f.write(markdown) }
#delete the file.html
File.delete(html_filename)
end
end
def copy_entire_folder from_path, to_path
from_path = from_path + "/*"
FileUtils.rm_rf(to_path)
FileUtils.mkdir_p(to_path)
FileUtils.cp_r(Dir.glob(from_path), to_path)
end
doit()