From bdc98f612bd66a35d9a4b3eeb46d26c362bc7dd9 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 22 Feb 2008 19:28:46 +0100 Subject: [PATCH] another checkpoint, off to party --- tekuti/filters.scm | 7 +++++++ tekuti/page.scm | 8 +++++++- tekuti/post.scm | 4 ++-- tekuti/template.scm | 2 +- tekuti/util.scm | 6 ++++++ wordpress-to-dir.py | 4 ++-- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tekuti/filters.scm b/tekuti/filters.scm index d46e95c..7fb7369 100644 --- a/tekuti/filters.scm +++ b/tekuti/filters.scm @@ -77,6 +77,8 @@ (cons (car in) (pclose p out)))))))) (define (wordpress->sxml text) + (catch 'parser-error +(lambda () (let ((sxml (cadr (with-input-from-string (string-append "
" text "
") xml->sxml)))) (pre-post-order @@ -87,3 +89,8 @@ (cons tag body)))) (*text* . ,(lambda (tag text) text)))))) + (lambda (key . args) + `(pre "parse error: " + ,(with-output-to-string (lambda () (write args))) + "\n" + ,text)))) diff --git a/tekuti/page.scm b/tekuti/page.scm index ff23f68..03a2636 100644 --- a/tekuti/page.scm +++ b/tekuti/page.scm @@ -181,7 +181,13 @@ (define page-new-comment not-implemented) (define page-delete-comment not-implemented) (define page-delete-post not-implemented) -(define page-index not-implemented) + +(define (page-index request index) + (rcons* request + 'title "my bloggidy blog" + 'body (map (lambda (post) + (show-post post #f)) + (take-max (assq-ref index 'posts) 10)))) (define (page-show-post request index year month day post) (let ((slug (make-post-key year month day post))) diff --git a/tekuti/post.scm b/tekuti/post.scm index 43e19c9..ec20c0a 100644 --- a/tekuti/post.scm +++ b/tekuti/post.scm @@ -150,8 +150,8 @@ (define (post-sxml-n-comments post) `(div (@ (class "feedback")) - (a (@ (href ,(string-append *public-url-base* "/archives/" - (assq-ref post 'encoded-name) + (a (@ (href ,(string-append *public-url-base* "archives/" + (url:decode (assq-ref post 'key)) "#comments"))) "(" ,(post-n-comments post) ")"))) diff --git a/tekuti/template.scm b/tekuti/template.scm index aea0694..092da87 100644 --- a/tekuti/template.scm +++ b/tekuti/template.scm @@ -58,6 +58,6 @@ (a (@ ,(href "")) "wingolog")) ,(make-navbar) (div (@ (id "content")) - ,@(rref request 'body '(p "what"))) + ,@(rref request 'body '((p "what")))) (div (@ (id "footer")) "powered by sxml"))))) diff --git a/tekuti/util.scm b/tekuti/util.scm index 6c9231e..6017055 100644 --- a/tekuti/util.scm +++ b/tekuti/util.scm @@ -29,6 +29,7 @@ #:use-module (srfi srfi-1) #:export (expanduser match-lines dbg unwind-protect dbg dsu-sort hash-push! list-has-length? list-head-match mapn + take-max list-intersperse with-backtrace define-memoized)) (define (expanduser path) @@ -66,6 +67,11 @@ (let ((handle (hash-create-handle! h key '()))) (set-cdr! handle (cons value (cdr handle))))) +(define (take-max list n) + (if (or (null? list) (zero? n)) + '() + (cons (car list) (take-max (cdr list) (1- n))))) + (define (list-has-length? list len) (cond ((zero? len) (null? list)) diff --git a/wordpress-to-dir.py b/wordpress-to-dir.py index 82669ee..7d60734 100644 --- a/wordpress-to-dir.py +++ b/wordpress-to-dir.py @@ -38,7 +38,7 @@ def post_comments(post): sql = ('select comment_ID, comment_author, comment_author_email,' ' comment_author_url, comment_author_IP,' ' comment_date, comment_date_gmt, comment_content, comment_approved' - ' from wp_comments where comment_post_ID=%s') + ' from wp_comments where comment_post_ID=%s where comment_approved!=\'spam\'') cur.execute(sql, (post['id'],)) keys = ('id', 'author', 'author_email', 'author_url', 'author_ip', 'date', 'date-gmt', 'content', 'approved') @@ -70,7 +70,7 @@ def write_comment(comment, dir): def make_post_key(post): d = post['date'] pre = '%d/%02d/%02d/%s' % (d.year, d.month, d.day, post['name']) - return urllib.quote(pre, '') + return urllib.quote(pre, '').tolower() def write_post(post, categories, comments): def make_metadata():