Commits

John Mulligan committed 1b71945

handle page deletes gracefully

  • Participants
  • Parent commits 5206fa5

Comments (0)

Files changed (1)

File muyhomepage2/app/build.py

 
 def build(config):
     website = site.Site()
-    website.pages = site.read_site_pages(config.page_cache())
+    allfiles = set(page.walkpages(config.root()))
+    website.pages = set()
+    cached = set()
+    for cpage in site.read_site_pages(config.page_cache()):
+        if cpage.filename not in allfiles:
+            continue
+        website.pages.add(cpage)
+        cached.add(cpage.filename)
+
     site.update_site_tags(website, config.tag_cache())
     rebuild = set()
-    cached = [p.filename for p in website.pages]
-    for pagefile in page.walkpages(config.root()):
+    for pagefile in allfiles:
         if pagefile not in cached:
             npage = page.parse(pagefile)
             rebuild.add(npage)
     for spage in website.pages:
         if spage.action in config.always_rebuild():
             rebuild.add(page.parse(spage.filename))
+    # remove any pages from the cache that are gone
     compile_pages(config, website, rebuild)
     site.write_site_pages(website, config.page_cache())
     site.write_site_tags(website, config.tag_cache())
 
 
 def compile_pages(config, website, rebuild):
-    for page in rebuild:
+    for page in sorted(rebuild, key=lambda p: p.filename):
         phandler = handle_action(
             config.handlers(),
             config.defaulthandler(),