-
Notifications
You must be signed in to change notification settings - Fork 0
/
splitpages.rb
73 lines (61 loc) · 1.6 KB
/
splitpages.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
## This takes the directory /repos/habitat/www/source/docs
## And breaks long pages into shorter pages at H2
## -------------
## ONE:
## Creates directory for each page
## Moves long page into directory
## -------------
## TWO:
## Creates blank page
## Adds frontmatter to page
## Finds section matching regex on main page
## moves content to subpage, removing content from main page
## copies page title >TITLE< into frontmatter title field
## deletes Magellan line
## saves/closes page
## -------------
## THREE:
## fix links
require 'fileutils'
## Set the environment to your path
DIRECTORY = ENV.fetch('HABITATDOCS',
'/Users/kimberlygarmoe/repos/habitat/www/source/docs')
## Regex pattern
# PATTERN =(/^#{2}\s(\D+)(?=^#{2}\s)/)
H2=/^#{2}\s/
## Navigate to docsf directory
FileUtils.cd DIRECTORY
# puts(FileUtils.pwd)
## ONE:
## Creates directory for each
## Moves long page into directory
# puts(Dir.glob("*.html.md.erb"))
# Dir.glob("*.html.md.erb") do |f|
# # puts(f.sub(/\..*/, ''))
# name=(f.sub(/\..*/, ''))
# Dir.mkdir(name)
# puts(name)
# FileUtils.mv(f, name)
# end
## -------------
## TWO:
Dir.each_child(DIRECTORY) do |d|
if File.directory?(d)
FileUtils.cd(d)
Dir.glob("*.html.md.erb") do |f|
File.open(f).each_line do |l|
if l.match(/^[#]{2}\s(.+)$/)
str=l
puts(str)
newname=str.match(/>([\w|\s]+)</m)
puts(newname)
end
end
end
end
# puts(FileUtils.pwd)
# FileUtils.cd(DIRECTORY)
# puts(FileUtils.pwd)
# puts(Dir.each)
## regex to select H2 and content up to the following H2
end