Skip to content

Commit d83f318

Browse files
committed
Small tweeks to update_index.py
- better documentation - no footer on the main README - small formatting fixes
1 parent 7c47f75 commit d83f318

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

bin/update_index.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/usr/bin/env python
22
"""
3-
A script to update footer links for all tutorial pages
3+
This script generates the footers for all markdown files. Rerun the script
4+
after adding new books or chapters in order to update the footer sections on
5+
each page with links to the next and previous chapters.
6+
7+
The script works by recursively parsing "## Index" sections in files, starting
8+
with README.md. The footer is marked with an HTML comment, `automatically
9+
generated footer`. Any text after this comment is destroyed by the script, so
10+
all edits should be made above that point.
11+
412
"""
513

614
import sys,os,re
@@ -85,7 +93,16 @@ def rootlink(self):
8593
return os.path.join(os.path.dirname(parentlink),self.link)
8694

8795
def makefooter(self):
88-
lines = ["---","","Navigation:"]
96+
""" makefooter() -> str
97+
98+
Creates the footer text (everything below the "automatically generated
99+
footer" line)
100+
"""
101+
# Don't include footer on main page
102+
if self.parent is None:
103+
return ""
104+
105+
lines = ["","---","","Navigation:"]
89106
# Iterate over parents
90107
p = self.parent
91108
linkmd = [self.makename()] #reverse order (self to root)
@@ -137,14 +154,16 @@ def __repr__(self):
137154
.format(self=self,parent=self.parent.title if self.parent else None)
138155

139156
if __name__ == "__main__":
140-
root = TutorialIndex("README.md",title="BioJava Tutorial")
157+
# Set root index
158+
root = TutorialIndex("README.md",title="Home")
141159

160+
# Rewrite headers
142161
root.parse()
143162

144163
# Output tree
145164
def pr(node,indent=""):
146-
print "{}{}\t{}".format(indent,node.link,node.rootlink())
165+
print "{}{}".format(indent,node.link,node.rootlink())
147166
for n in node.children:
148-
pr(n,indent+"\t")
167+
pr(n,indent+" ")
149168

150169
pr(root)

0 commit comments

Comments
 (0)