]> git.llucax.com Git - software/blitiri.git/blobdiff - blitiri.cgi
Use text/css as Content-type when rendering the style sheet
[software/blitiri.git] / blitiri.cgi
index a72ccdd19968cfabe83fda06f74acb2049d0dfc5..b95d5ca03dd23bd52a2792fa3b139a05835d99d4 100755 (executable)
@@ -50,14 +50,20 @@ import urllib
 import cgi
 from docutils.core import publish_parts
 
 import cgi
 from docutils.core import publish_parts
 
+# Before importing the config, add our cwd to the Python path
+sys.path.append(os.getcwd())
+
 # Load the config file, if there is one
 # Load the config file, if there is one
-if os.path.isfile("config.py"):
-       try:
-               from config import *
-       except:
-               pass
+try:
+       from config import *
+except:
+       pass
 
 
 
 
+# Pimp *_path config variables to support relative paths
+data_path = os.path.realpath(data_path)
+templates_path = os.path.realpath(templates_path)
+
 # Default template
 
 default_main_header = """
 # Default template
 
 default_main_header = """
@@ -86,6 +92,7 @@ default_main_footer = """
   %(showyear)s: %(monthlinks)s<br/>
   years: %(yearlinks)s<br/>
   subscribe: <a href="%(url)s/atom">atom</a><br/>
   %(showyear)s: %(monthlinks)s<br/>
   years: %(yearlinks)s<br/>
   subscribe: <a href="%(url)s/atom">atom</a><br/>
+  views: <a href="%(url)s/">blog</a> <a href="%(url)s/list">list</a><br/>
 </div>
 
 </body>
 </div>
 
 </body>
@@ -124,16 +131,17 @@ default_css = """
 body {
        font-family: sans-serif;
        font-size: small;
 body {
        font-family: sans-serif;
        font-size: small;
+       width: 52em;
 }
 
 div.content {
 }
 
 div.content {
-       width: 50%;
+       width: 96%;
 }
 
 h1 {
        font-size: large;
        border-bottom: 2px solid #99F;
 }
 
 h1 {
        font-size: large;
        border-bottom: 2px solid #99F;
-       width: 60%;
+       width: 100%;
        margin-bottom: 1em;
 }
 
        margin-bottom: 1em;
 }
 
@@ -176,7 +184,7 @@ hr {
        height: 2px;
        border: 0;
        background-color: #99F;
        height: 2px;
        border: 0;
        background-color: #99F;
-       width: 60%;
+       width: 100%;
 }
 
 div.footer {
 }
 
 div.footer {
@@ -358,6 +366,10 @@ class Article (object):
                        return -1
                return 1
 
                        return -1
                return 1
 
+       def title_cmp(self, other):
+               return cmp(self.title, other.title)
+
+
        def load(self):
                try:
                        raw = open(data_path + '/' + self.path).readlines()
        def load(self):
                try:
                        raw = open(data_path + '/' + self.path).readlines()
@@ -504,6 +516,20 @@ def render_html(articles, db, actyear = None):
                print template.get_article_footer(a)
        print template.get_main_footer()
 
                print template.get_article_footer(a)
        print template.get_main_footer()
 
+def render_artlist(articles, db, actyear = None):
+       template = Templates(templates_path, db, actyear)
+       print 'Content-type: text/html; charset=utf-8\n'
+       print template.get_main_header()
+       print '<h2>Articles</h2>'
+       for a in articles:
+               print '<li><a href="%(url)s/uuid/%(uuid)s">%(title)s</a></li>' \
+                       % {     'url': blog_url,
+                               'uuid': a.uuid,
+                               'title': a.title,
+                               'author': a.author,
+                       }
+       print template.get_main_footer()
+
 def render_atom(articles):
        if len(articles) > 0:
                updated = articles[0].updated.isoformat()
 def render_atom(articles):
        if len(articles) > 0:
                updated = articles[0].updated.isoformat()
@@ -556,7 +582,7 @@ def render_atom(articles):
 
 
 def render_style():
 
 
 def render_style():
-       print 'Content-type: text/plain\n'
+       print 'Content-type: text/css\r\n\r\n',
        print default_css
 
 def handle_cgi():
        print default_css
 
 def handle_cgi():
@@ -571,6 +597,7 @@ def handle_cgi():
        atom = False
        style = False
        post = False
        atom = False
        style = False
        post = False
+       artlist = False
 
        if os.environ.has_key('PATH_INFO'):
                path_info = os.environ['PATH_INFO']
 
        if os.environ.has_key('PATH_INFO'):
                path_info = os.environ['PATH_INFO']
@@ -578,7 +605,9 @@ def handle_cgi():
                atom = path_info == '/atom'
                tag = path_info.startswith('/tag/')
                post = path_info.startswith('/post/')
                atom = path_info == '/atom'
                tag = path_info.startswith('/tag/')
                post = path_info.startswith('/post/')
-               if not style and not atom and not post and not tag:
+               artlist = path_info.startswith('/list')
+               if not style and not atom and not post and not tag \
+                               and not artlist:
                        date = path_info.split('/')[1:]
                        try:
                                if len(date) > 1 and date[0]:
                        date = path_info.split('/')[1:]
                        try:
                                if len(date) > 1 and date[0]:
@@ -606,7 +635,11 @@ def handle_cgi():
        elif style:
                render_style()
        elif post:
        elif style:
                render_style()
        elif post:
-               render_html( [db.get_article(uuid)], year )
+               render_html( [db.get_article(uuid)], db, year )
+       elif artlist:
+               articles = db.get_articles()
+               articles.sort(cmp = Article.title_cmp)
+               render_artlist(articles, db)
        else:
                articles = db.get_articles(year, month, day, tags)
                articles.sort(reverse = True)
        else:
                articles = db.get_articles(year, month, day, tags)
                articles.sort(reverse = True)
@@ -627,7 +660,8 @@ def handle_cmd():
        art_path = os.path.realpath(sys.argv[2])
 
        if os.path.commonprefix([data_path, art_path]) != data_path:
        art_path = os.path.realpath(sys.argv[2])
 
        if os.path.commonprefix([data_path, art_path]) != data_path:
-               print "Error: article must be inside data dir"
+               print "Error: article (%s) must be inside data_path (%s)" % \
+                               (art_path, data_path)
                return 1
        art_path = art_path[len(data_path):]
 
                return 1
        art_path = art_path[len(data_path):]