shithub: werc

Download patch

ref: 222627c656507224e6e485df89e3a74cf5dcddd3
parent: 3a201bbda67956b0e1ddec0bb29e2289e6dee140
author: uriel <uriel@engel.se.cat-v.org>
date: Fri Jun 29 06:28:58 EDT 2007

Markdown caching system

--- a/bin/controller.rc
+++ b/bin/controller.rc
@@ -8,6 +8,8 @@
 cd ..
 
 # default config
+formater=markdown.pl
+formater=md_cache # markdown cacher
 site=$SERVER_NAME
 sitedir=sites/$site
 headers=inc/headers.tpl
@@ -83,8 +85,8 @@
 fn genbody {
     if ( test -f $body.md ) {
         if ( ! ~ $#inBlog 0 )
-            blogTitle $body.md | markdown.pl
-        markdown.pl < $body.md
+            blogTitle $body.md | $formater
+        $formater < $body.md
     }
     if not if ( test -f $body.tpl )
         template.awk $body.tpl | rc $rcargs
@@ -116,7 +118,7 @@
             blogTitle $f
             cat $f 
             echo 
-        } | markdown.pl 
+        } | $formater
     }
 }
 
--- /dev/null
+++ b/bin/md_cache
@@ -1,0 +1,17 @@
+#!/bin/rc
+. 9.rc
+
+cachedir=/tmp/md_cache
+mkdir -p $cachedir >[2]/dev/null
+
+tmpfile=$cachedir/mdtmp.$pid
+score=`{{tee $tmpfile || exit 1} | sha1sum}
+cachefile=$cachedir/$score
+
+if(test -f $cachefile)
+    cat $cachefile
+if not {
+    markdown.pl < $tmpfile | tee $cachefile.$pid
+    mv $cachefile.$pid $cachefile
+}
+rm $tmpfile >[2]/dev/null