Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

"category list" markup extension - add short article description (as …

…in origin cliki)
  • Loading branch information...
commit e666c10261f2943e0c1c1d5e4e05bddeaa35a023 1 parent a7e0b55
@archimag archimag authored
View
3  src/defmodule.lisp
@@ -4,7 +4,8 @@
(defpackage #:cliki2.markup
(:use #:cl #:iter #:esrap)
- (:export #:generate-html-from-markup))
+ (:export #:generate-html-from-markup
+ #:format-article-description))
(restas:define-module #:cliki2
(:use #:cl #:iter #:bknr.datastore #:bknr.indices #:cliki2.markup)
View
29 src/markup.lisp
@@ -120,15 +120,42 @@
(:lambda (list)
(cons :cliki2-category-list (cliki2:category-keyword (second list)))))
+(sanitize:define-sanitize-mode +simple+
+ :elements ("a")
+ :attributes (("a" . ("href")))
+ :protocols (("a" . (("href" . (:ftp :http :https :mailto :relative))))))
+
+(defun format-article-description (article)
+ (sanitize:with-clean-fragment (fragment
+ (with-output-to-string (s)
+ (let ((3bmd::*references* (make-hash-table)))
+ (3bmd::print-element (parse '3bmd-grammar::block
+ (cliki2::article-content-head article)
+ :junk-allowed t)
+ s)))
+ +simple+)
+ (with-output-to-string (out)
+ (iter (for item in-child-nodes fragment)
+ (for text = (html:serialize-html item :to-string))
+ (for len initially 0 then (+ len (length text)))
+ (let ((dot-pos (if (xtree:text-p item) (position #\. text))))
+ (cond
+ (dot-pos (write-string (subseq text 0 (1+ dot-pos)) out)
+ (finish))
+ (t (write-string text out))))))))
(defmethod 3bmd::print-tagged-element ((tag (eql :cliki2-category-list)) stream category)
(write-string (cliki2.view:category-content
(list :items
- (iter (for article in (cliki2::articles-with-category category))
+ (iter (for article in (sort (copy-list (cliki2::articles-with-category category))
+ #'string<
+ :key 'cliki2::article-title))
(collect
(list :title (cliki2::article-title article)
+ :head (format-article-description article)
:href (restas:genurl 'cliki2:view-article
:title (cliki2::article-title article)))))))
stream))
+
(define-rule 3bmd-grammar::code (or 3bmdcode code-block category-list))
View
8 src/model.lisp
@@ -128,6 +128,14 @@
(cons latest-revision content)))
content))))
+(defun article-content-head (article &aux (count 200))
+ (let* ((revision (article-latest-revision article))
+ (path (content-path article (revision-content-sha1 revision))))
+ (with-output-to-string (out)
+ (iter (for char in-file path using #'read-char)
+ (for i from 0 below count)
+ (write-char char out)))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; revision
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
View
2  templates/markup.tmpl
@@ -29,6 +29,8 @@
{foreach $item in $items}
<li>
<a href="{$item.href}">{$item.title}</a>
+ -
+ {$item.head |noAutoescape}
</li>
{/foreach}
</ul>
Please sign in to comment.
Something went wrong with that request. Please try again.