Skip to content

Commit

Permalink
Added Disqus plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed May 8, 2024
1 parent 7e5f082 commit 0ea40a4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 5 deletions.
3 changes: 2 additions & 1 deletion example/.staticlrc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
2 changes: 1 addition & 1 deletion example/blog/math-example.post
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;;;;;
title: Math Example
tags: plugin,math
tags: plugin, math
created-at: 2024-05-09 10:00
format: md
;;;;;
Expand Down
59 changes: 59 additions & 0 deletions src/plugins/disqus.lisp
Original file line number Diff line number Diff line change
@@ -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* "
<div id=\"disqus_thread\"></div>
<script type=\"text/javascript\">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = '~A';
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
dsq.setAttribute('data-timestamp', +new Date());
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href=\"http://disqus.com/?ref_noscript\">comments powered by Disqus.</a></noscript>
<a href=\"http://disqus.com\" class=\"dsq-brlink\">comments powered by <span class=\"logo-disqus\">Disqus</span></a>
")


(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)))))
3 changes: 0 additions & 3 deletions src/plugins/mathjax.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ MathJax = {
")

"
"


(defclass mathjax (plugin)
((force :initarg :force
Expand Down
2 changes: 2 additions & 0 deletions src/user-package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ea40a4

Please sign in to comment.