Next / Previous / Contents / TCC Help System / NM Tech homepage

16. buildAllPages(): Build the output pages

homelist2
# - - -   b u i l d A l l P a g e s

def buildAllPages(dirPath, kwicIndex):
    '''Generate the index page and all subpages.

      [ (dirPath is a path relative to http://www.nmt.edu/) and
        (kwicIndex is a kwic.KwicIndex instance) ->
          if directory (dirPath) is writeable ->
            directory (dirPath)  :=  (file INDEX_NAME containing links
                to letter pages) + (one page for each letter (X), named
                LETTER_PAGE_NAME+(X)+HTML_SUFFIX, displaying the
                entries in kwicIndex that start with (X)
          else ->
            sys.stderr  +:=  error message(s) ]
    '''

Although we say there is a page for each letter, in practice, because Unicode is involved, we can't just spit out pages for A through Z. Also, if there don't happen to be any keywords that start with a particular letter, we don't want to build a page for that letter. Furthermore, the navigational links on each subpage need to know the title and URL of the preceding and following pages.

So our first step is to build a letterList containing the single Unicode characters in whatever order their code points sort them. See Section 17, “scanInitialLetters(): What initial letters occur in keywords?”.

homelist2
    #-- 1 --
    # [ letterList  :=  a list of the unique initial letters of keywords
    #       in kwicIndex, in ascending order by code point, upshifted ]
    letterList = scanInitialLetters(kwicIndex)

See Section 18, “buildIndexPage(): Build the top-level page”. The index page doesn't need the actual KWIC index, just the list of subpage letters.

homelist2
    #-- 2 --
    # [ directory (dirPath) is writeable ->
    #     directory (dirPath)  +:=  an INDEX_NAME file linking
    #         to the subpages in (letterList) ]
    buildIndexPage(dirPath, letterList)

See Section 23, “buildSubpage(): Build the subpage for one letter”.

homelist2
    #-- 3 --
    # [ directory (dirPath)  +:=  (subpages for each letter in
    #       letterList, each displaying the entries in kwicIndex
    #       for that letter) ]
    for k in range(len(letterList)):
        #-- 3 body --
        # [ directory (dirPath)  +:=  (a subpage for letterList[k],
        #       using letterList to find the next and previous
        #       pages, displaying entries in kwicIndex for
        #       letterList[k])
        buildSubpage(dirPath, letterList, k, kwicIndex)