constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit 5ac1afdce224c63fbd291669c713a998ac4e6362
parent c4fe5b45325a59c445ee092f6be17982e0bcf3db
Author: Dan Callaghan <djc@djc.id.au>
Date:   Wed,  3 Dec 2008 17:43:34 +1000

removed useless permalink from reading log items

Diffstat:
Mitemtypes.py | 14++------------
Mtemplates/ReadingLogEntry.xml | 5++---
Mviewutils.py | 8++++++++
3 files changed, 12 insertions(+), 15 deletions(-)
diff --git a/itemtypes.py b/itemtypes.py
@@ -49,14 +49,6 @@ def cleanup_metadata(header_items):
         cleaned[k] = v
     return cleaned
 
-IDIFY_WHITESPACE_PATT = re.compile(r'(?u)\s+')
-IDIFY_ACCEPT_PATT = re.compile(r'(?u)\w|[-_]')
-def idify(s):
-    # http://www.w3.org/TR/REC-xml/#NT-Name
-    s = s.lower()
-    s = IDIFY_WHITESPACE_PATT.sub(u'-', s)
-    return u''.join(c for c in s if IDIFY_ACCEPT_PATT.match(c))
-
 
 class NoAccessError(StandardError): pass
 
@@ -153,10 +145,8 @@ class BlogEntrySet(object):
 
 class ReadingLogEntry(object):
 
-    def __init__(self, yaml_dict, uri_path):
-        self.uri_path = uri_path
+    def __init__(self, yaml_dict):
         self.title = yaml_dict['Title']
-        self.id = idify(self.title)
         self.author = yaml_dict['Author']
         self.publication_date = self.modified_date = self.date = yaml_dict['Date']
         self.url = yaml_dict.get('URL', None)
@@ -189,7 +179,7 @@ class ReadingLogEntrySet(object):
         raise NotExistError(path_info)
 
     def __iter__(self):
-        return (ReadingLogEntry(d, self.prefix + '/#ReadingLogEntry-' + idify(d['Title']))
+        return (ReadingLogEntry(d)
                 for d in yaml.load_all(open(self.filename, 'r')))
 
 
diff --git a/templates/ReadingLogEntry.xml b/templates/ReadingLogEntry.xml
@@ -6,7 +6,7 @@
 <xi:include href="_fragments.xml" />
 
 <?python
-from viewutils import markdown, mini_markdown, tag_list
+from viewutils import markdown, mini_markdown, tag_list, idify
 from recaptcha.client import captcha
 ?>
 
@@ -19,14 +19,13 @@ from recaptcha.client import captcha
      src="http://covers.librarything.com/devkey/${config.get('readinglog', 'librarything_devkey')}/small/isbn/${entry.isbn}" 
      alt="Cover image for ${entry.title}" /-->
 
-<h3 class="title" id="ReadingLogEntry-${item.id}">
+<h3 class="title" id="ReadingLogEntry-${idify(item.title)}">
     <a py:strip="not item.url" href="${item.url}">${mini_markdown(item.title)}</a>
     <span py:if="item.author" class="author">by ${item.author}</span>
 </h3>
 
 <div class="date">
     ${item.publication_date.strftime(str('%-1d %b %Y'))}
-    <a href="${item.uri_path}" rel="bookmark" class="permalink" title="permalink">#</a>
 </div>
 
 <div py:if="item.rating" class="rating">
diff --git a/viewutils.py b/viewutils.py
@@ -13,6 +13,14 @@ def mini_markdown(s, safe_mode=None):
     assert match, m
     return genshi.Markup(match.group(1))
 
+IDIFY_WHITESPACE_PATT = re.compile(r'(?u)\s+')
+IDIFY_ACCEPT_PATT = re.compile(r'(?u)\w|[-_]')
+def idify(s):
+    # http://www.w3.org/TR/REC-xml/#NT-Name
+    s = s.lower()
+    s = IDIFY_WHITESPACE_PATT.sub(u'-', s)
+    return u''.join(c for c in s if IDIFY_ACCEPT_PATT.match(c))
+
 def tag_list(script_name, tags):
     # XXX urllib.quote
     return genshi.Markup(u', ').join(