diff --git a/example/.staticlrc b/example/.staticlrc index 6b1a1a5..9a0f093 100644 --- a/example/.staticlrc +++ b/example/.staticlrc @@ -26,7 +26,8 @@ (atom :target-path #P"blog/atom.xml") (tags-index :target-path "tags/")) (mathjax) - (sitemap)) + (sitemap) + (disqus "staticl-example")) :theme "readable" ;; :theme "hyde" ) diff --git a/example/blog/math-example.post b/example/blog/math-example.post index 2ee07b1..9ddaea9 100644 --- a/example/blog/math-example.post +++ b/example/blog/math-example.post @@ -1,6 +1,6 @@ ;;;;; title: Math Example -tags: plugin,math +tags: plugin, math created-at: 2024-05-09 10:00 format: md ;;;;; diff --git a/src/plugins/disqus.lisp b/src/plugins/disqus.lisp new file mode 100644 index 0000000..5506b47 --- /dev/null +++ b/src/plugins/disqus.lisp @@ -0,0 +1,59 @@ +(uiop:define-package #:staticl/plugins/disqus + (:use #:cl) + (:import-from #:staticl/plugin + #:plugin) + (:import-from #:staticl/site + #:site) + (:import-from #:staticl/injections + #:add-injection + #:content-with-injections-mixin) + (:import-from #:staticl/content + #:has-tag-p) + (:import-from #:serapeum + #:fmt + #:->)) +(in-package #:staticl/plugins/disqus) + + +(defparameter *code-to-inject* " +
+ + +comments powered by Disqus +") + + +(defclass disqus (plugin) + ((shortname :initarg :shortname + :initform (error "Shortname should be given.") + :type string + :reader disqus-shortname))) + + +(-> disqus (string) + (values disqus &optional)) + +(defun disqus (shortname) + "Enables Disqus on the page if it's content has tag equal to the TAG-NAME or if FORCE argument was given." + (make-instance 'disqus + :shortname shortname)) + + +(defmethod staticl/pipeline:process-items ((site site) (node disqus) content-items) + (loop for item in content-items + when (typep item 'staticl/content/post:post) + do (add-injection item "after_content" + (fmt *code-to-inject* + (disqus-shortname node))))) diff --git a/src/plugins/mathjax.lisp b/src/plugins/mathjax.lisp index eacbc4d..0709d32 100644 --- a/src/plugins/mathjax.lisp +++ b/src/plugins/mathjax.lisp @@ -38,9 +38,6 @@ MathJax = { ") -" -" - (defclass mathjax (plugin) ((force :initarg :force diff --git a/src/user-package.lisp b/src/user-package.lisp index 6e394dd..865d2ee 100644 --- a/src/user-package.lisp +++ b/src/user-package.lisp @@ -15,6 +15,8 @@ #:sitemap) (:import-from #:staticl/plugins/mathjax #:mathjax) + (:import-from #:staticl/plugins/disqus + #:disqus) (:import-from #:staticl/site #:site) (:import-from #:staticl/content-pipeline