- Date now computed from a format YYYYMMDD - id attribute on <article> - cl-yag… | |
git clone git://bitreich.org/cl-yag/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
LICENSE | |
--- | |
commit 013ada82f339f61de56f426824c1c3c1a88bf9b1 | |
parent 52bd9a828bdd422d4c4ec8fbd30ba8f5ef253e76 | |
Author: Solene Rapenne <[email protected]> | |
Date: Wed, 13 Dec 2017 20:35:33 +0100 | |
- Date now computed from a format YYYYMMDD | |
- id attribute on <article> | |
Diffstat: | |
M data/articles.lisp | 7 ++++--- | |
M generator.lisp | 55 +++++++++++++++++++++++++++--… | |
M templates/article.tpl | 2 +- | |
3 files changed, 53 insertions(+), 11 deletions(-) | |
--- | |
diff --git a/data/articles.lisp b/data/articles.lisp | |
@@ -10,6 +10,7 @@ | |
:description "Yet another website on the net" | |
:url "https://my.website/~~user/" ;; the trailing slash … | |
:rss-item-number 10 ;; limit total amount … | |
+ :date-format "%DayNumber %MonthName %Year" ;; format for date %Da… | |
:html t ;; 't' to enable expor… | |
:gopher t ;; 't' to enable expor… | |
:gopher-path "/user" ;; absolute path of yo… | |
@@ -41,15 +42,15 @@ | |
;; CSS | |
(post :title "CSS For cl-yag" | |
- :id "css" :date "02.12.2017" :tag "cl-yag" | |
+ :id "css" :date "20171202" :tag "cl-yag" | |
:author "lambda" :tiny "Read more") | |
;; README | |
(post :title "README" | |
- :id "README" :date "23.11.2017" :tag "cl-yag" | |
+ :id "README" :date "20171202" :tag "cl-yag" | |
:author "lambda" :tiny "Read cl-yag's README") | |
;; 1 | |
(post :title "My first post" | |
- :id "1" :date "29.04.2016" :tag "pony" | |
+ :id "1" :date "20160429" :tag "pony" | |
:tiny "This is the first message" :author "Solène") | |
diff --git a/generator.lisp b/generator.lisp | |
@@ -1,17 +1,21 @@ | |
(defparameter *articles* '()) | |
(defparameter *converters* '()) | |
+(defparameter *days* '("Monday" "Tuesday" "Wednesday" "Thursday" | |
+ "Friday" "Saturday" "Sunday")) | |
+(defparameter *months* '("January" "February" "March" "April" | |
+ "May" "June" "July" "August" "September" | |
+ "October" "November" "December")) | |
;; structure to store links | |
-(defstruct article title tag date id tiny author short) | |
+(defstruct article title tag date id tiny author) | |
(defstruct converter name command extension) | |
-(defun post(&optional &key title tag date id (tiny nil) (author nil) (short ni… | |
+(defun post(&optional &key title tag date id (tiny nil) (author nil)) | |
(push (make-article :title title | |
:tag tag | |
:date date | |
:tiny tiny | |
:author author | |
- :short short | |
:id id) | |
*articles*)) | |
@@ -26,6 +30,31 @@ | |
(setf *articles* (reverse *articles*)) | |
+;; return the day of the week | |
+(defun get-day-of-week(day month year) | |
+ (multiple-value-bind | |
+ (second minute hour date month year day-of-week dst-p tz) | |
+ (decode-universal-time (encode-universal-time 0 0 0 day month year)) | |
+ (declare (ignore second minute hour date month year dst-p tz)) | |
+ day-of-week)) | |
+ | |
+;; parse the date to | |
+(defun date-parse(date) | |
+ (if (= 8 (length date)) | |
+ (let* ((year (parse-integer date :start 0 :end 4)) | |
+ (monthnum (parse-integer date :start 4 :end 6)) | |
+ (daynum (parse-integer date :start 6 :end 8)) | |
+ (day (nth (get-day-of-week daynum monthnum year) *days*)) | |
+ (month (nth (- monthnum 1) *months*))) | |
+ (list | |
+ :dayname day | |
+ :daynumber daynum | |
+ :monthname month | |
+ :monthnumber monthnum | |
+ :year year)) | |
+ nil)) | |
+ | |
+ | |
;; common-lisp don't have a replace string function natively | |
(defun replace-all (string part replacement &key (test #'char=)) | |
(with-output-to-string (out) | |
@@ -82,6 +111,16 @@ | |
`(progn | |
(setf output (replace-all output ,before ,@after)))) | |
+;; format the date | |
+(defun date-format(format date) | |
+ (let ((output format)) | |
+ (template "%DayName" (getf date :dayname)) | |
+ (template "%DayNumber" (write-to-string (getf date :daynumber))) | |
+ (template "%MonthName" (getf date :monthname)) | |
+ (template "%MonthNumber" (write-to-string (getf date :monthnumber))) | |
+ (template "%Year" (write-to-string (getf date :year ))) | |
+ output)) | |
+ | |
;; simplify the declaration of a new page type | |
(defmacro prepare(template &body code) | |
`(progn | |
@@ -129,9 +168,11 @@ | |
(prepare "templates/article.tpl" | |
(template "%%Author%%" (let ((author (article-author article))) | |
(or author (getf *config* :webmaster)))) | |
- (template "%%Date%%" (article-date article)) | |
- (template "%%Title%%" (article-title article)) | |
- (template "%%Id%%" (article-id article)) | |
+ (template "%%Date%%" (date-format (getf *config* :date-format) | |
+ (date-parse (article-date artic… | |
+ (template "%%Raw-Date%%" (article-date article)) | |
+ (template "%%Title%%" (article-title article)) | |
+ (template "%%Id%%" (article-id article)) | |
(template "%%Tags%%" (get-tag-list-article article)) | |
(template "%%Text%%" (if no-text | |
"" | |
@@ -166,7 +207,7 @@ | |
(defun generate-rss-item() | |
(apply #'concatenate 'string | |
(loop for article in *articles* | |
- for i from 1 to (if (> (length *articles*) (getf *config* :rss-ite… | |
+ for i from 1 to (min (length *articles*) (getf *config* :rss-item-… | |
collect | |
(prepare "templates/rss-item.tpl" | |
(template "%%Title%%" (article-title article)) | |
diff --git a/templates/article.tpl b/templates/article.tpl | |
@@ -1,5 +1,5 @@ | |
-<article> | |
+<article id="%%Raw-Date%%"> | |
<header> | |
<h1><a href="article-%%Id%%.html">%%Title%%</a></h1> | |
<p>Written by <em>%%Author%%</em>, on %%Date%%.<br/>Tags: %%Tags%%</p> |