-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a single pipeline and render RSS feed.
- Loading branch information
1 parent
c4d10b7
commit 3b9f5b8
Showing
15 changed files
with
531 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
;;; -*- mode : lisp -*- | ||
(:title "Example Staticl Site" | ||
:plugins ((sitemap))) | ||
(site "Example Static Site" | ||
:description "Just an example of the static file generated by StatiCL." | ||
:url "https://example.com/" | ||
:pipeline (list (load-content) | ||
(filter (:path "ru/") | ||
(rss :target-path #P"ru/blog/rss.xml")) | ||
(filter (:path "ru/" :invert t) | ||
(rss :target-path #P"blog/rss.xml")) | ||
(sitemap) | ||
;; (rsync "my-site") | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(uiop:define-package #:staticl/content/html-content | ||
(:use #:cl) | ||
(:export #:content-html | ||
#:content-html-excerpt)) | ||
(in-package #:staticl/content/html-content) | ||
|
||
|
||
(defgeneric content-html (content) | ||
(:documentation "Returns a content as HTML string.")) | ||
|
||
(defgeneric content-html-excerpt (content) | ||
(:documentation "Returns an excerpt of full content as HTML string.")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(uiop:define-package #:staticl/current-root | ||
(:use #:cl) | ||
(:import-from #:serapeum | ||
#:directory-pathname | ||
#:->) | ||
(:import-from #:alexandria | ||
#:with-gensyms) | ||
(:export #:with-current-root | ||
#:current-root)) | ||
(in-package #:staticl/current-root) | ||
|
||
|
||
(declaim (type directory-pathname *current-root*)) | ||
|
||
(defvar *current-root*) | ||
|
||
|
||
(-> current-root () | ||
(values directory-pathname &optional)) | ||
|
||
(defun current-root () | ||
(unless (boundp '*current-root*) | ||
(error "Function CURRENT-ROOT should be called inside WITH-CURRENT-ROOT scope.")) | ||
(values *current-root*)) | ||
|
||
|
||
(-> call-with-current-root (directory-pathname function)) | ||
|
||
(defun call-with-current-root (root thunk) | ||
(let ((*current-root* (uiop:ensure-absolute-pathname | ||
(uiop:ensure-directory-pathname root)))) | ||
(funcall thunk))) | ||
|
||
|
||
(defmacro with-current-root ((root) &body body) | ||
(with-gensyms (thunk) | ||
`(flet ((,thunk () | ||
,@body)) | ||
(declare (dynamic-extent #',thunk)) | ||
(call-with-current-root ,root #',thunk)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(uiop:define-package #:staticl/filter | ||
(:use #:cl) | ||
(:import-from #:serapeum | ||
#:directory-pathname) | ||
(:import-from #:staticl/site | ||
#:site) | ||
(:export #:filter)) | ||
(in-package #:staticl/filter) | ||
|
||
|
||
(defclass filter () | ||
((path :initarg :path | ||
:type (or null directory-pathname) | ||
:reader filter-path) | ||
(invert :initarg :invert | ||
:type boolean | ||
:reader filter-invert) | ||
(pipeline :initarg :pipeline | ||
:type list | ||
:reader pipeline-items)) | ||
(:default-initargs | ||
:path nil | ||
:invert nil | ||
:pipeline nil)) | ||
|
||
|
||
(defmacro filter ((&key path invert) &rest pipeline) | ||
(alexandria:once-only (path) | ||
`(make-instance 'filter | ||
:path (when ,path | ||
(uiop:ensure-directory-pathname ,path)) | ||
:invert ,invert | ||
:pipeline (list ,@pipeline)))) | ||
|
||
|
||
(defmethod staticl/pipeline:process-items ((site site) (node filter) content-items) | ||
(let ((filtered content-items)) | ||
(loop for subnode in (pipeline-items node) | ||
do (staticl/pipeline:process-items site subnode filtered)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
(uiop:define-package #:staticl/pipeline | ||
(:use #:cl) | ||
(:import-from #:staticl/site | ||
#:site | ||
#:site-pipeline) | ||
(:import-from #:serapeum | ||
#:soft-list-of | ||
#:->) | ||
(:import-from #:staticl/content | ||
#:content) | ||
(:export #:execute-pipeline | ||
#:process-items | ||
#:produce-item | ||
#:remove-item)) | ||
(in-package #:staticl/pipeline) | ||
|
||
|
||
(defgeneric process-items (site pipeline-node content-items) | ||
(:documentation "A method for this generic function should process CONTENT-ITEMS - a list of conten items | ||
produced by a previous pipeline nodes. | ||
During the execution, method can call PRODUCE-ITEM or REMOVE-ITEM functions to add a new content | ||
or to remove some content item.")) | ||
|
||
(defvar *produce-item-func*) | ||
|
||
(defun produce-item (item) | ||
(funcall *produce-item-func* item)) | ||
|
||
|
||
(defvar *remove-item-func*) | ||
|
||
(defun remove-item (item) | ||
(funcall *remove-item-func* item)) | ||
|
||
|
||
(-> execute-pipeline (site) | ||
(values (soft-list-of content))) | ||
|
||
(defun execute-pipeline (site) | ||
(let ((known-items nil) | ||
(items-to-remove nil)) | ||
(flet ((produce-item-func (item) | ||
(push item known-items) | ||
(values)) | ||
(remove-item-func (item) | ||
;; Items to remove are pushed into an intermediate list | ||
;; just because there may be some siteeffects if we'll | ||
;; modify KNOWN-ITEMS list while iterating on it. | ||
(push item items-to-remove) | ||
(values))) | ||
(declare (dynamic-extent #'produce-item-func | ||
#'remove-item-func)) | ||
|
||
(let ((*produce-item-func* #'produce-item-func) | ||
(*remove-item-func* #'remove-item-func)) | ||
(loop for pipeline-node in (site-pipeline site) | ||
do (process-items site pipeline-node known-items) | ||
(when items-to-remove | ||
;; This is N*M complexity, but length of items-to-remove | ||
;; usually should be relatively small. | ||
;; It is possible to optimize this in future, for example | ||
;; by remembering an index of the items to remove instead | ||
;; of the item itself. | ||
(setf known-items | ||
(remove-if (lambda (item) | ||
(member item items-to-remove)) | ||
known-items)) | ||
(setf items-to-remove nil))) | ||
(values known-items))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.