Commits

Anonymous committed b6be9f1

new version of zip export. handle html page renndering + markdown sources

  • Participants
  • Parent commits e98b1e5

Comments (0)

Files changed (3)

         pages = all_pages(local.db, request.site.id)
         zip_content = StringIO()
         zfile = zipfile.ZipFile(zip_content, "w", zipfile.ZIP_DEFLATED)
-        import time
+        import time, codecs
         for page in pages:
              zinfo = zipfile.ZipInfo()
-             zinfo.filename = smart_str(page.title.replace(" ", "_")) + ".html"
+             zinfo.filename = "markdown/%s" % smart_str(page.title.replace(" ", "_")) + ".txt"
              zinfo.compress_type = zipfile.ZIP_DEFLATED
              zinfo.date_time = time.localtime()[:6]
-             zfile.writestr(zinfo, smart_str(page.content))
+             zfile.writestr(zinfo, codecs.BOM_UTF8 + page.content.encode('utf-8'))
+             zinfo.filename = smart_str(page.title.replace(" ", "_")) + ".html"
+             zfile.writestr(zinfo, codecs.BOM_UTF8 + render_template("page/export.html", 
+                        page=page, request=request, pages=pages).encode( "utf-8" ))
+        zinfo = zipfile.ZipInfo()
+        zinfo.filename = "index.html"
+        zinfo.compress_type = zipfile.ZIP_DEFLATED
+        zinfo.date_time = time.localtime()[:6]
+        zfile.writestr(zinfo,  codecs.BOM_UTF8 + render_template("page/export_index.html",
+            pages=pages, request=request).encode( "utf-8" ))
+         
         zfile.close()
         response = BCResponse(zip_content.getvalue())
         response.headers['content-type'] = "application/x-zip-compressed"

templates/page/export.html

+<!DOCTYPE html>
+
+<html lang="en">
+
+<head>
+    <meta charset="utf-8" />
+    <title>{% if site and site.title %}{{ site.title }} - {% endif %}{{ page.title }}</title>
+</head>
+<body>
+     <header id="site_header">
+         <h1><a href="{% if site_url %}{{ site_url }}{% else %}/{% endif %}">{% if site.title %}{{ site.title }}{% else %} {{ site.cname }}{% endif %}</a></h1>
+         <h2>{% if site.subtitle %}{{ site.subtitle }}{% endif %}</h2>
+     </header>   
+      
+    <section id="page">
+        <article id="post">
+               {% if page.title or page.subtitle %}
+               <header>
+                   <h2 id="page_title">{{ page.title }}</h2>
+                   <ul class="page_infos">
+                       <li><time title="GMT" datetime="{{ page.updated|rfc3339 }}">{{ page.updated|formatdatetime }}</time></li>
+                   </ul>
+               </header>
+               {% endif %}
+               {{ page.content|markdown(site.allow_javascript) }}
+               <footer>
+                   <p><a href="markdown/{{ page.title|replace(" ", "_") }}.txt">Markdown source</a></p>
+               </footer>
+           </article>
+    </section>        
+    
+    <footer class="footer_wrapper">
+        <p><a href="index.html">Back to index</a></p>
+        <p class="powered">Powered by <a href="http://couchit.net">CouchIt</a>.</p>
+    </footer>
+     
+</body>
+</html>

templates/page/export_index.html

+<!DOCTYPE html>
+
+<html lang="en">
+
+<head>
+    <meta charset="utf-8" />
+    <title>{% if site and site.title %}{{ site.title }} - {% endif %}Pages</title>
+</head>
+<body>
+     <header id="site_header">
+         <h1><a href="{% if site_url %}{{ site_url }}{% else %}/{% endif %}">{% if site.title %}{{ site.title }}{% else %} {{ site.cname }}{% endif %}</a></h1>
+         <h2>{% if site.subtitle %}{{ site.subtitle }}{% endif %}</h2>
+     </header>   
+      
+    <section id="pages">
+        <article id="post">
+
+               <header>
+                   <h2>Pages</h2>
+                   
+               </header>
+               <ul class="pagelist">
+                      {% for p in pages %}
+                      <li><a href="{{ p.title|replace(" ", "_") }}.html">{{ p.title }}</a></li>
+                      {% endfor %}
+                 </ul>
+               <footer>
+                    <p><a href="markdown/">Markdown sources</a></p>
+               </footer>
+           </article>
+    </section>        
+  
+    <footer class="footer_wrapper">
+        
+        <p class="powered">Powered by <a href="http://couchit.net">CouchIt</a>.</p>
+    </footer>
+     
+</body>
+</html>