Commits

faassen  committed 6e4ecc7

Use a relative URL for links where possible, so it's easy to test
the generated blog locally.

  • Participants
  • Parent commits 919fa68

Comments (0)

Files changed (1)

     main = []
 
     base_url = config.get('html', 'base_url')
-    def get_url(parts):
-        """Create a url from a document"""
-        return base_url + identifier(parts)
-
+    def get_relative_url(parts):
+        """Create a relative url from a document"""
+        return identifier(parts)
+    def get_absolute_url(parts):
+        """Create absolute url for a document"""
+        return base_url + get_relative_url(parts)
+    
     #Get timestamps from Mercurial
     for parts in data:
         timestamp = timestamp_tpl.substitute(
     #Sort by creation date
     data.sort(cmp=lambda x, y: y['created']-x['created'])
     #Create links
-    links = "\n".join([menu_link_tpl.substitute(link=get_url(parts), 
-                                                   title=parts['title']) 
-                          for parts in data])
+    links = "\n".join([
+            menu_link_tpl.substitute(
+                link=get_relative_url(parts), 
+                title=parts['title']) 
+            for parts in data])
 
     title = config.get('content', 'title')
 
                     main=blaag_html,
                     ).encode("utf-8"))
             #Append post to main page
-            shortcomments = comments_short_tpl.substitute(parts, 
-                                                          link=get_url(parts), 
-                                                          threadid=identifier(parts))
-            main.append(blaag_tpl.substitute(parts, 
-                                             comments=shortcomments, 
-                                             link=get_url(parts)))
+            shortcomments = comments_short_tpl.substitute(
+                parts, 
+                link=get_relative_url(parts), 
+                threadid=identifier(parts))
+            main.append(blaag_tpl.substitute(
+                    parts, 
+                    comments=shortcomments, 
+                    link=get_relative_url(parts)))
     #Write main page
     with open(os.path.join(html_path, "index.html"), "w") as target:
         target.write(page_tpl.substitute(
     #Write rss
 
     description = config.get('content', 'description')
-    base_url = config.get('html', 'base_url')
     
     for name in FEEDS:        
         rss = generate_rss(data, FEEDS[name], title, description, base_url,
-                           get_url)
+                           get_absolute_url)
         f = open(os.path.join(html_path, name), 'w')
         rss.write_xml(f)
         f.close()