Add choice of html conveter

This commit is contained in:
solene rapenne 2017-12-15 00:49:21 +01:00
parent 76cfe4f9da
commit 4ef4f5a4e8
3 changed files with 56 additions and 24 deletions

View File

@ -1,9 +1,6 @@
LISP= sbcl LISP= sbcl
MD= multimarkdown -t html -o
HTMLDIR= temp/data HTMLDIR= temp/data
ARTICLES!= ls data/*.md
HTML= $(ARTICLES:.md=.html)
all: clean dirs html all: clean dirs html
@ -16,9 +13,6 @@ dirs:
mkdir -p "output/html/static" mkdir -p "output/html/static"
mkdir -p "output/gopher" mkdir -p "output/gopher"
.SUFFIXES: .md .html
.md.html:
$(MD) "$(HTMLDIR)/$(@F)" "$<"
clean: clean:
rm -fr output/html/* output/gopher/* "temp" rm -fr output/html/* output/gopher/* "temp"

View File

@ -11,6 +11,7 @@
:url "https://my.website/~~user/" ;; the trailing slash is mandatory! RSS links will fail without it. Notice the '~~' to produce a literal '~' :url "https://my.website/~~user/" ;; the trailing slash is mandatory! RSS links will fail without it. Notice the '~~' to produce a literal '~'
:rss-item-number 10 ;; limit total amount of items in RSS feed to 10 :rss-item-number 10 ;; limit total amount of items in RSS feed to 10
:date-format "%DayNumber %MonthName %Year" ;; format for date %DayNumber %DayName %MonthNumber %MonthName %Year :date-format "%DayNumber %MonthName %Year" ;; format for date %DayNumber %DayName %MonthNumber %MonthName %Year
:default-converter :markdown2
:html t ;; 't' to enable export to a html website / 'nil' to disable :html t ;; 't' to enable export to a html website / 'nil' to disable
:gopher t ;; 't' to enable export to a gopher website / 'nil' to disable :gopher t ;; 't' to enable export to a gopher website / 'nil' to disable
:gopher-path "/user" ;; absolute path of your gopher directory :gopher-path "/user" ;; absolute path of your gopher directory
@ -23,8 +24,13 @@
)) ))
(converter :name :markdown :extension ".md" :command "peg-markdown -o %IN") (converter :name :markdown :extension ".md" :command "peg-markdown -t html -o %OUT data/%IN")
(converter :name :markdown2 :extension ".md" :command "multimarkdown -o %IN") (converter :name :markdown2 :extension ".md" :command "multimarkdown -t html -o %OUT data/%IN")
(converter :name :org-mode :extension ".org"
:command (concatenate 'string
"emacs data/%IN --batch --eval '(with-temp-buffer (org-mode) "
"(insert-file \"%IN\") (org-html-export-as-html nil nil nil t)"
"(princ (buffer-string)))' --kill | tee %OUT"))
;; Define your articles and their display-order on the website below. ;; Define your articles and their display-order on the website below.
;; Display Order is 'lifo', i.e. the top entry in this list gets displayed as the topmost entry. ;; Display Order is 'lifo', i.e. the top entry in this list gets displayed as the topmost entry.
@ -40,6 +46,8 @@
;; :tiny can be omitted. If so, the article's full text gets displayed on the all-articles view. (most people don't want this.) ;; :tiny can be omitted. If so, the article's full text gets displayed on the all-articles view. (most people don't want this.)
(post :title "test"
:id "t" :date "20171214" :tag "f" :converter :org-mode)
;; CSS ;; CSS
(post :title "CSS For cl-yag" (post :title "CSS For cl-yag"
:id "css" :date "20171202" :tag "cl-yag" :id "css" :date "20171202" :tag "cl-yag"

View File

@ -9,11 +9,13 @@
"October" "November" "December")) "October" "November" "December"))
;; structure to store links ;; structure to store links
(defstruct article title tag date id tiny author rawdate) (defstruct article title tag date id tiny author rawdate converter)
(defstruct converter name command extension) (defstruct converter name command extension)
;;;; FUNCTIONS ;;;; FUNCTIONS
(require 'asdf)
;; return the day of the week ;; return the day of the week
(defun get-day-of-week(day month year) (defun get-day-of-week(day month year)
(multiple-value-bind (multiple-value-bind
@ -39,22 +41,26 @@
:year year)) :year year))
nil)) nil))
(defun post(&optional &key title tag date id (tiny nil) (author nil)) (defun post(&optional &key title tag date id (tiny nil) (author nil) (converter nil))
(push (make-article :title title (push (make-article :title title
:tag tag :tag tag
:date (date-parse date) :date (date-parse date)
:rawdate date :rawdate date
:tiny tiny :tiny tiny
:author author :author author
:id id) :id id
:converter converter)
*articles*)) *articles*))
;; we add a converter to the list of the one availables ;; we add a converter to the list of the one availables
(defun converter(&optional &key name command extension) (defun converter(&optional &key name command extension)
(push (make-converter :name name (setf *converters*
:command command (append
:extension extension) (list name
*converters*)) (make-converter :name name
:command command
:extension extension))
*converters*)))
;; load data from metadata and load config ;; load data from metadata and load config
(load "data/articles.lisp") (load "data/articles.lisp")
@ -117,6 +123,23 @@
`(progn `(progn
(setf output (replace-all output ,before ,@after)))) (setf output (replace-all output ,before ,@after))))
;; get the converter object of "article"
(defmacro with-converter(&body code)
`(progn
(let ((converter-name (if (article-converter article)
(article-converter article)
(getf *config* :default-converter))))
(let ((converter-object (getf *converters* converter-name)))
,@code))))
(defun use-converter-to-html(article)
(with-converter
(let ((output (converter-command converter-object)))
(ensure-directories-exist "temp/data/")
(template "%IN" (concatenate 'string (article-id article) (converter-extension converter-object)))
(template "%OUT" (concatenate 'string "temp/data/" (article-id article) ".html"))
(uiop:run-program output))))
;; format the date ;; format the date
(defun date-format(format date) (defun date-format(format date)
(let ((output format)) (let ((output format))
@ -240,21 +263,25 @@
;; We do all the website ;; We do all the website
(defun create-html-site() (defun create-html-site()
;; produce index.html
(generate "output/html/index.html" (generate-semi-mainpage))
;; produce index-titles.html where there are only articles titles
(generate "output/html/index-titles.html" (generate-semi-mainpage :no-text t))
;; produce each article file ;; produce each article file
(loop for article in *articles* (loop for article in *articles*
do do
;; use the article's converter to get html code of it
(use-converter-to-html article)
(generate (format nil "output/html/~d-~d.html" (generate (format nil "output/html/~d-~d.html"
(date-format "%Year-%MonthNumber-%DayNumber" (date-format "%Year-%MonthNumber-%DayNumber"
(article-date article)) (article-date article))
(article-id article)) (article-id article))
(create-article article :tiny nil) (create-article article :tiny nil)
:title (concatenate 'string (getf *config* :title) " : " (article-title article)))) :title (concatenate 'string (getf *config* :title) " : " (article-title article))))
;; produce index.html
(generate "output/html/index.html" (generate-semi-mainpage))
;; produce index-titles.html where there are only articles titles
(generate "output/html/index-titles.html" (generate-semi-mainpage :no-text t))
;; produce index file for each tag ;; produce index file for each tag
(loop for tag in (articles-by-tag) do (loop for tag in (articles-by-tag) do
@ -293,10 +320,12 @@
output)) output))
;; produce each article file (only a copy/paste in fact) ;; produce each article file (only a copy/paste in fact)
(dolist (article *articles*) (loop for article in *articles*
(let ((id (article-id article))) do
(save-file (format nil "output/gopher/article-~d.txt" id) (with-converter
(load-file (format nil "data/~d.md" id))))) (let ((id (article-id article)))
(save-file (format nil "output/gopher/article-~d.txt" id)
(load-file (format nil "data/~d~d" id (converter-extension converter-object)))))))
) )
@ -313,4 +342,5 @@
(generate-site) (generate-site)
(quit) (quit)