Merge branch 'master' of git://bitreich.org/cl-yag - cl-yag - Common Lisp Yet Another website Generator
 (HTM) 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 bff6ca9e3a4f11ebbd196c972f74612dfbff6b26
 (DIR) parent ec61ee60dcbbe37b43d7cb6fb7a87bdfc847d990
 (HTM) Author: lambda <lambda@fnord.one>
       Date:   Wed, 29 Nov 2017 11:11:29 +0100
       
       Merge branch 'master' of git://bitreich.org/cl-yag
       
       Diffstat:
         M Makefile                            |      10 +---------
         M README.md                           |       3 ++-
         M data/README.md                      |       3 ++-
         M data/articles.lisp                  |       4 ++--
         M generator.lisp                      |      97 ++++++++++++++++---------------
       
       5 files changed, 56 insertions(+), 61 deletions(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       @@ -5,18 +5,10 @@ HTMLDIR=       temp/data
        ARTICLES!=     ls data/*.md
        HTML=          $(ARTICLES:.md=.html)
        
       -.if "${LISP}" == "sbcl"
       -PARAM=--dynamic-space-size 90 --script
       -.elif "${LISP}" == "clisp"
       -PARAM=
       -.elif "${LISP}" == "ecl"
       -PARAM=-shell
       -.endif
       -
        all: clean dirs html
        
        html: $(HTML) css
       -        $(LISP) $(PARAM) generator.lisp
       +        $(LISP) --load generator.lisp
                rm -fr "temp"
        
        dirs:
 (DIR) diff --git a/README.md b/README.md
       @@ -3,7 +3,8 @@
        
        ## Introduction
        
       -cl-yag is a very lightweight, static-site generator that produces **gopher** sites as well as **html** websites.  
       +
       +cl-yag is a very lightweight, static site generator that produces **gopher** sites as well as **html** websites.  
        The name 'cl-yag' stands for 'Common Lisp - Yet Another website Generator'.  
        It runs without Quicklisp.
        
 (DIR) diff --git a/data/README.md b/data/README.md
       @@ -3,7 +3,8 @@
        
        ## Introduction
        
       -cl-yag is a very lightweight, static-site generator that produces **gopher** sites as well as **html** websites.  
       +
       +cl-yag is a very lightweight, static site generator that produces **gopher** sites as well as **html** websites.  
        The name 'cl-yag' stands for 'Common Lisp - Yet Another website Generator'.  
        It runs without Quicklisp.
        
 (DIR) diff --git a/data/articles.lisp b/data/articles.lisp
       @@ -34,10 +34,10 @@
        (defvar *articles*
          (list
           ;; README
       -   (list :id "README"    :date "23 November 2016"  :tag "cl-yag README"
       +   (list :id "README"    :date "23 November 2017"  :tag "cl-yag README"
                 :title "README" :author "lambda"     :short "cl-yag's README got reworked." :tiny "Read cl-yag's README")
           ;; 1
       -   (list :id "1"         :date "29 April 2016":tag "pony code"
       +   (list :id "1"         :date "29 April 2016" :tag "pony code"
                 :title "My first message" :short "This is my first message" :author "Solène" :tiny "Read more")
           ))
        
 (DIR) diff --git a/generator.lisp b/generator.lisp
       @@ -15,31 +15,32 @@
                                       while pos)))
        
        ;; common-lisp don't have a split string function natively
       -;; thanks https://gist.github.com/siguremon/1174988
       -(defun split-str-1 (string &optional (separator " ") (r nil))
       -  (let ((n (position separator string
       -                     :from-end t
       -                     :test #'(lambda (x y)
       -                               (find y x :test #'string=)))))
       -    (if n
       -        (split-str-1 (subseq string 0 n) separator (cons (subseq string (1+ n)) r))
       -      (cons string r))))
       -(defun split-str (string &optional (separator " "))
       -  (split-str-1 string separator))
       -
       -;; we have to remove the quotes
       -;; when using collect in a loop
       -(defun strip-quotes(input)
       -  (format nil "~{~d~%~}" input))
       +(defun split-str(text &optional (separator #\Space))
       +  "this function split a string with separator and return a list"
       +  (let ((text (concatenate 'string text (string separator))))
       +    (loop for char across text
       +          counting char into count
       +          when (char= char separator)
       +          collect
       +          ;; we look at the position of the left separator from right to left
       +          (let ((left-separator-position (position separator text :from-end t :end (- count 1))))
       +            (subseq text
       +                    ;; if we can't find a separator at the left of the current, then it's the start of
       +                    ;; the string
       +                    (if left-separator-position (+ 1 left-separator-position) 0)
       +                    (- count 1))))))
        
        ;; load a file as a string
        ;; we escape ~ to avoid failures with format
        (defun load-file(path)
          (if (probe-file path)
              (replace-all
       -       (strip-quotes
       -        (with-open-file (stream path)
       -                        (loop for line = (read-line stream nil) while line collect line)))
       +       (apply #'concatenate 'string
       +              (with-open-file (stream path)
       +                (loop for line = (read-line stream nil)
       +                   while line
       +                   collect
       +                   (format nil "~a~%" line))))
               "~" "~~")
            (progn
              (format t "ERROR : file ~a not found. Aborting~%" path)
       @@ -82,18 +83,18 @@
        
        ;; generates the html of the list of tags for an article
        (defun get-tag-list-article(&optional article)
       -  (strip-quotes
       -   (mapcar #'(lambda (item)
       -               (prepare "templates/one-tag.tpl" (template "%%Name%%" item)))
       -           (split-str (getf article :tag)))))
       +  (apply #'concatenate 'string
       +         (mapcar #'(lambda (item)
       +                     (prepare "templates/one-tag.tpl" (template "%%Name%%" item)))
       +                 (split-str (getf article :tag)))))
        
        ;; generates the html of the whole list of tags
        (defun get-tag-list()
       -  (strip-quotes
       -   (mapcar #'(lambda (item)
       -               (prepare "templates/one-tag.tpl"
       -                        (template "%%Name%%" (getf item :name))))
       -           (articles-by-tag))))
       +  (apply #'concatenate 'string
       +         (mapcar #'(lambda (item)
       +                     (prepare "templates/one-tag.tpl"
       +                              (template "%%Name%%" (getf item :name))))
       +                 (articles-by-tag))))
        
        
        ;; generates the html of one only article
       @@ -123,31 +124,31 @@
        
        ;; html generation of index homepage
        (defun generate-semi-mainpage(&key (tiny t) (no-text nil))
       -  (strip-quotes
       -   (loop for article in *articles* collect
       -         (create-article article :tiny tiny :no-text no-text))))
       +  (apply #'concatenate 'string
       +         (loop for article in *articles* collect
       +              (create-article article :tiny tiny :no-text no-text))))
        
        ;; html generation of a tag homepage
        (defun generate-tag-mainpage(articles-in-tag)
       -  (strip-quotes
       -   (loop for article in *articles* 
       -         when (member (getf article :id) articles-in-tag :test #'equal)
       -         collect (create-article article :tiny t))))
       +  (apply #'concatenate 'string
       +         (loop for article in *articles* 
       +            when (member (getf article :id) articles-in-tag :test #'equal)
       +            collect (create-article article :tiny t))))
        
        ;; xml generation of the items for the rss
        (defun generate-rss-item()
       -  (strip-quotes
       -   (loop for article in *articles*
       -         for i from 1 to (if (> (length *articles*) (getf *config* :rss-item-number)) (getf *config* :rss-item-number) (length *articles*))
       -         collect
       -         (prepare "templates/rss-item.tpl"
       -                  (template "%%Title%%" (getf article :title))
       -                  (template "%%Description%%" (load-file (format nil "temp/data/~d.html" (getf article :id))))
       -                  (template "%%Url%%"
       -                            (format nil "~darticle-~d.html"
       -                                    (getf *config* :url)
       -                                    (getf article :id)))))))
       -  
       +  (apply #'concatenate 'string
       +         (loop for article in *articles*
       +            for i from 1 to (if (> (length *articles*) (getf *config* :rss-item-number)) (getf *config* :rss-item-number) (length *articles*))
       +            collect
       +              (prepare "templates/rss-item.tpl"
       +                       (template "%%Title%%" (getf article :title))
       +                       (template "%%Description%%" (load-file (format nil "temp/data/~d.html" (getf article :id))))
       +                       (template "%%Url%%"
       +                                 (format nil "~darticle-~d.html"
       +                                         (getf *config* :url)
       +                                         (getf article :id)))))))
       +
        ;; Generate the rss xml data
        (defun generate-rss()
          (prepare "templates/rss.tpl"
       @@ -225,4 +226,4 @@
              (create-gopher-hole)))
        
        (generate-site)
       -
       +(quit)