def parseTags(nope): notags = [] # from %tags, create a global one-to-many associative array (dictionary) of tags to pages for f in os.listdir(docsDir): if f.endswith(".md"): tagList = getTags(docsDir + "/" + f) # print "tags found:"+str(len(tagList)) # print f+":"+str(type(tagList)) if len(tagList) > 0: for tag in tagList: if tag in tagDict: tagDict[tag].append(f) # add this file's name to listvalue of this tagkey else: # initialise this tagkey with a new list containing this filename tagDict[tag] = [f] else: print "UNTAGGED: " + f notags.append(f) allTags = open("../temp/all_tags.md", "w") allTags.write("# All Tags\n\ntag | articles\n----|------\n") # tags as table untagged = open("../temp/untagged_articles.md", "w") untagged.write("# Untagged Articles\n\n") for page in notags: untagged.write("* [" + getTitle("../articles/" + page)[0] + "](" + cleanTitle(page)[:-2] + "html)\n") # create a page for every tag found in all the articles. # on that page, add a link to every article with that tag for tag in tagDict.keys(): # consider sorting tags before printing # sorted(tagDict, key=itemgetter(len(tagDict[tag])), reverse=True) # articlesPerTag.append((tag, len(tagDict[tag]))) # allTags.write("* ["+tag+"]("+cleanTitle(tag)+".html): "+str(len(tagDict[tag]))+" articles\n")#as bulleted list allTags.write( "[" + tag + "](tags/" + cleanTitle(tag) + ".html) | " + str(len(tagDict[tag])) + "\n" ) # tags as table tagPage = open("../temp/" + cleanTitle(tag) + ".md", "w") tagPage.write(tagPageTitlePrefix + tag + "'\n===\n\n") # write page title padding = " "[len(tag) :] print tag + ":" + padding + str(len(tagDict[tag])) + " articles" for page in tagDict[tag]: link = "../" + cleanTitle(page)[:-3] + ".html" title = getTitle(docsDir + "/" + page)[0] tagPage.write("* [" + title + "](" + link + ")\n") # print "\t\""+title+"\" at "+link tagPage.close() allTags.close()
for page in tagDict[tag]: link = "../" + cleanTitle(page)[:-3] + ".html" title = getTitle(docsDir + "/" + page)[0] tagPage.write("* [" + title + "](" + link + ")\n") # print "\t\""+title+"\" at "+link tagPage.close() allTags.close() # --------------------begin! for liveFile in os.listdir(docsDir): if liveFile.endswith(".md") or liveFile.endswith(".list"): thisFileChanged = False cleanedName = cleanTitle( liveFile ) # replace spaces with underscores in filenames; make the name lowercase as well exists = os.path.exists("../lastinput/" + cleanedName) # and os.path.isfile("../lastinput/"+cleanedName) if exists: dift = subprocess.call(["diff", "-q", docsDir + "/" + liveFile, "../lastinput/" + cleanedName]) if dift != 0: filesChanged = True thisFileChanged = True else: # if there's no copy of this file in ../lastinput, then it has changed by definition filesChanged = True thisFileChanged = True if thisFileChanged: # if working copy in ../mdfiles/ differs from last rendered version in ../lastinput/ # print ""+liveFile+" HAS CHANGED!" guaranteeFolder("../temp")