|
1 | 1 | #!/usr/bin/env python |
2 | 2 | """ |
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 | +
|
4 | 12 | """ |
5 | 13 |
|
6 | 14 | import sys,os,re |
@@ -85,7 +93,16 @@ def rootlink(self): |
85 | 93 | return os.path.join(os.path.dirname(parentlink),self.link) |
86 | 94 |
|
87 | 95 | 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:"] |
89 | 106 | # Iterate over parents |
90 | 107 | p = self.parent |
91 | 108 | linkmd = [self.makename()] #reverse order (self to root) |
@@ -137,14 +154,16 @@ def __repr__(self): |
137 | 154 | .format(self=self,parent=self.parent.title if self.parent else None) |
138 | 155 |
|
139 | 156 | if __name__ == "__main__": |
140 | | - root = TutorialIndex("README.md",title="BioJava Tutorial") |
| 157 | + # Set root index |
| 158 | + root = TutorialIndex("README.md",title="Home") |
141 | 159 |
|
| 160 | + # Rewrite headers |
142 | 161 | root.parse() |
143 | 162 |
|
144 | 163 | # Output tree |
145 | 164 | def pr(node,indent=""): |
146 | | - print "{}{}\t{}".format(indent,node.link,node.rootlink()) |
| 165 | + print "{}{}".format(indent,node.link,node.rootlink()) |
147 | 166 | for n in node.children: |
148 | | - pr(n,indent+"\t") |
| 167 | + pr(n,indent+" ") |
149 | 168 |
|
150 | 169 | pr(root) |
0 commit comments