Skip to content

Commit

Permalink
Merge pull request #8 from 40ants/add-more-template-filters
Browse files Browse the repository at this point in the history
Filters `remove-html-tags` and `first-line` were added to the templat…
  • Loading branch information
svetlyak40wt authored May 26, 2024
2 parents 43a6dfb + bb4379d commit 93984c5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"ASDF"
"REPL"
"HTTP"))
(0.2.0 2024-05-26
"* `Excerpt` field was added to the `content` objects such as posts and pages. It can be used in the description HTML tags.
* Filters `remove-html-tags` and `first-line` were added to the template engine base on Closure Templates.")
(0.1.1 2024-05-11
"* Fixed error in `serve` command when xdg-open ultility is not available.
* Installation using Roswell was updated in the docs.")
Expand Down
6 changes: 3 additions & 3 deletions qlfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
("quicklisp" .
(:class qlot/source/dist:source-dist
:initargs (:distribution "https://beta.quicklisp.org/dist/quicklisp.txt" :%version :latest)
:initargs (:distribution "http://beta.quicklisp.org/dist/quicklisp.txt" :%version :latest)
:version "2023-10-21"))
("ultralisp" .
(:class qlot/source/dist:source-dist
:initargs (:distribution "https://dist.ultralisp.org/" :%version :latest)
:version "20240504133502"))
:initargs (:distribution "http://dist.ultralisp.org/" :%version :latest)
:version "20240526155501"))
("slynk" .
(:class qlot/source/github:source-github
:initargs (:repos "svetlyak40wt/sly" :ref nil :branch "patches" :tag nil)
Expand Down
3 changes: 2 additions & 1 deletion src/content.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@
(content-format content)))



(defmethod content-html-excerpt ((content content-from-file))
(let* ((separator (content-excerpt-separator content))
(full-content (content-text content))
Expand All @@ -381,6 +380,8 @@
(content-title content)
(gethash "html" hash)
(content-html content)
(gethash "excerpt" hash)
(content-html-excerpt content)
(gethash "created-at" hash)
(content-created-at content)

Expand Down
2 changes: 1 addition & 1 deletion src/content/reader.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
appending (parse-initarg line))))


(-> read-content (pathname &key (:separator string))
(-> read-content-file (pathname &key (:separator string))
(values proper-list &optional))

(defun read-content-file (file &key (separator *default-metadata-separator*))
Expand Down
2 changes: 1 addition & 1 deletion src/index/paginated.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ can be overriden by PAGE-FILENAME-FN argument.
The same way page title may be overriden by providing a function as PAGE-TITLE-FN argument.
# Arguments:
**Arguments:**
**PAGE-FILENAME-FN**:
Expand Down
2 changes: 1 addition & 1 deletion src/index/tags.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ can be overriden by PAGE-FILENAME-FN argument.
The same way page title may be overriden by providing a function as PAGE-TITLE-FN argument.
# Arguments:
**Arguments:**
**PAGE-FILENAME-FN**:
Expand Down
2 changes: 1 addition & 1 deletion src/site.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
:type string
:reader site-title
:documentation "Site's title.")
(description :initarg :title
(description :initarg :description
:type string
:reader site-description
:documentation "Site's description.")
Expand Down
30 changes: 27 additions & 3 deletions src/themes/closure-template.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
(:import-from #:str
#:replace-all)
(:import-from #:local-time
#:format-timestring))
#:format-timestring)
(:import-from #:html2text
#:html2text))
(in-package #:staticl/themes/closure-template)


Expand Down Expand Up @@ -44,6 +46,8 @@
;; as "date" rule:
(define-print-syntax print-datetime "datetime" (:constant t))
(define-print-syntax print-date "date" (:constant t))
(define-print-syntax remove-html-tags "remove-html-tags" (:constant t))
(define-print-syntax first-line "first-line" (:constant t))

(flet ((format-date (params end value)
(declare (ignore params end))
Expand All @@ -54,13 +58,33 @@
(declare (ignore params end))
(when value
(format-timestring nil value
:format (datetime-format theme)))))
:format (datetime-format theme))))
(remove-html-tags (params end value)
(declare (ignore params end))
(when value
(html2text value
:tags-to-remove (list :img
:style
:script))))
(first-line (params end value)
(declare (ignore params end))
(when value
(first
(str:split #\Newline value
:omit-nulls t
:limit 2)))))
(register-print-handler :common-lisp-backend
'print-date
:function #'format-date)
(register-print-handler :common-lisp-backend
'print-datetime
:function #'format-datetime))))
:function #'format-datetime)
(register-print-handler :common-lisp-backend
'remove-html-tags
:function #'remove-html-tags)
(register-print-handler :common-lisp-backend
'first-line
:function #'first-line))))

(defmethod initialize-instance :after ((obj closure-template) &rest initargs &key path &allow-other-keys)
(declare (ignore initargs))
Expand Down

0 comments on commit 93984c5

Please sign in to comment.