Skip to content

Commit c2ab6c4

Browse files
committed
TOC: Reorganize into groups
1 parent b83ee48 commit c2ab6c4

File tree

2 files changed

+51
-43
lines changed

2 files changed

+51
-43
lines changed

scripts/createWebBook.py

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -403,49 +403,52 @@ def returnChapterByCommonName( commonName ):
403403
#----------------------------------------------------- make TOC content
404404

405405
soup = Soup()
406-
a = Tag(soup, None, "a")
407-
408-
for c in chapterDicts:
409-
ul = Tag(soup, None, "ul")
410-
li = Tag(soup, None, "li")
411-
a = Tag(soup, None, "a");
412-
a['href'] = c['path'] + ".html"
413-
a.string = c['title']
414-
li.append(a)
415-
ul.append(li)
416-
417-
#print c['title']
418-
#print c['path']
419-
if (len(c['sections'])):
420-
ulInner = Tag(soup, None, "ul")
421-
li.append(ulInner);
422-
for tag in c['sections']:
423-
liInner = Tag(soup, None, "li")
424-
ulInner.append(liInner)
425-
a = Tag(soup, None, "a")
426-
a['href'] = "chapters/" + c['path'] + ".html#" + tag[1]
427-
a['target'] = "_top"
428-
a.string = tag[0]
429-
liInner.append(a);
430-
#print "\t" + tag
431-
432-
soup.append(ul);
406+
407+
wrapperDiv = Tag(soup, None, "div");
408+
wrapperDiv['class'] = "toc-wrapper"
409+
410+
411+
# Build the output like...
412+
# div[toc-wrapper]
413+
# h3 Group name
414+
# ul
415+
# li Chapter name
416+
# li Chapter name
417+
418+
# Run through the chapter groups
419+
for group in chapterGroups:
420+
421+
h3 = Tag(soup, None, "h3")
422+
h3.append(group['groupName'])
423+
wrapperDiv.append(h3)
424+
425+
ul = Tag(soup, None, "ul");
426+
427+
# Run through the chapters of the group
428+
for chap in group['chapters']:
429+
c = returnChapterByCommonName(chap)
430+
if (c != None):
431+
432+
a = Tag(soup, None, "a");
433+
a['href'] = c['href']
434+
a.string = c['title']
435+
436+
li = Tag(soup, None, "li");
437+
li.append(a)
438+
ul.append(li)
439+
440+
else:
441+
print chap
442+
443+
wrapperDiv.append(ul)
444+
445+
soup.append(wrapperDiv)
433446

434447
htmlOut = soup.prettify("utf-8")
435448
tocPath = os.path.join(webBookPath, "toc.html")
436449
with open(tocPath, "wb") as file:
437450
file.write(htmlOut)
438451

439-
# <ul>
440-
# <li>Coffee</li>
441-
# <li>Tea
442-
# <ul>
443-
# <li>Black tea</li>
444-
# <li>Green tea</li>
445-
# </ul>
446-
# </li>
447-
# <li>Milk</li>
448-
# </ul>
449452

450453
#----------------------------------------------------- run pandoc for TOC
451454

@@ -462,9 +465,3 @@ def returnChapterByCommonName( commonName ):
462465

463466
print "Removing", sourceTocPath, "..."
464467
os.remove(sourceTocPath)
465-
466-
467-
468-
469-
470-

static/style/style.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,17 @@ a:active {
370370
.toc {
371371
width: 980px;
372372
margin-left: 0px;
373+
374+
.toc-wrapper {
375+
column-count: 2;
376+
-webkit-column-count: 2;
377+
-moz-column-count: 2;
378+
379+
h3 {
380+
margin-top: 0;
381+
}
382+
}
383+
373384
}
374385

375386
#help {

0 commit comments

Comments
 (0)