comments - cl-yag - Common Lisp Yet Another website Generator
HTML git clone git://bitreich.org/cl-yag/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/cl-yag/
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
DIR LICENSE
---
DIR commit e0a4614444c18e9840e4fa30d832da9fafedfa5e
DIR parent 91e116792c8d8cd9319a4269a6465834b4116cf2
HTML Author: Solene Rapenne <solene@dataswamp.org>
Date: Sat, 30 Apr 2016 18:21:48 +0200
comments
Diffstat:
M generator.lisp | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
---
DIR diff --git a/generator.lisp b/generator.lisp
@@ -1,8 +1,7 @@
(load "data/articles.lisp")
+;; common-lisp don't have a replace string function natively
(defun replace-all (string part replacement &key (test #'char=))
- "Returns a new string in which all the occurences of the part
-is replaced with replacement."
(with-output-to-string (out)
(loop with part-length = (length part)
for old-pos = 0 then (+ pos part-length)
@@ -14,14 +13,14 @@ is replaced with replacement."
:end (or pos (length string)))
when pos do (write-string replacement out)
while pos)))
-; load a file as a string
+;; load a file and return it as a string
(defun slurp-file(path)
(with-open-file (stream path)
(let ((data (make-string (file-length stream))))
(read-sequence data stream)
data)))
-; save a string in a file
+;; save a string in a file
(defun save-file(path data)
(with-open-file (stream (concatenate 'string "output/" path) :direction :output :if-exists :supersede)
(format stream data)))
@@ -39,6 +38,7 @@ is replaced with replacement."
output)))
;; generates the html of one only article
+;; this is called in a loop to produce the homepage
(defun create-article(article &optional &key (tiny t))
(prepare "template/article.tpl"
(template "%%Author%%" (if (member :author article) (getf article :author) (getf *config* :webmaster)))
@@ -48,21 +48,25 @@ is replaced with replacement."
(template "%%Text%%" (if (and tiny (member :tiny article))
(getf article :tiny) (slurp-file (format nil "data/~d.txt" (getf article :id)))))))
-;; Layout generation
+;; return a html string
+;; produce the code of a whole page with title+layout with the parameter as the content
(defun generate-layout(body)
(let ((output (slurp-file "template/layout.tpl")))
(template "%%Title%%" (getf *config* :title))
(template "%%Body%%" body)
output))
-
-; Homepage generation
+
+
+;; Homepage generation
+;; generate each article and concatenate the whole
(defun generate-mainpage()
(format nil "~{~d~}"
(loop for article in *articles* collect
(create-article article :tiny t))))
-; ENGINE START !
+;; ENGINE START !
+;; This is function called when running the tool
(defun generate-site()
; produce index.html
@@ -75,6 +79,7 @@ is replaced with replacement."
(create-article article :tiny nil)))
;;(generate-file-rss)
+ ;;not done yet
)