commit 893723795f3c620bb9e8cf183db776d0edb69a39
parent 80f0856b7d8892f253f6fdc3d6bea44df473d5a8
Author: Decay <decaydjk@tilde.town>
Date: Sat, 8 Feb 2020 06:30:49 +0000
Enable external configuration + improving template
Diffstat:
2 files changed, 69 insertions(+), 42 deletions(-)
diff --git a/src/miniblog.lisp b/src/miniblog.lisp
@@ -1,7 +1,8 @@
(in-package :miniblog)
(defvar *blog-timezone* *default-timezone*)
-(defvar *public-html* (make-pathname :directory '(:relative "public_html")))
+(defvar *public-html*)
+(defvar *root-uri*)
(defvar *generator*)
(defparameter +command-line-spec+
@@ -40,22 +41,19 @@
(make-pathname :name "index" :type "html")
path))
-(defun get-index-path ()
- (merge-pathnames *public-html* (user-homedir-pathname)))
-
(defun get-monthly-path (year month)
(merge-pathnames
(make-pathname :directory
(list :relative (write-to-string year)
(format nil "~2,'0d" month)))
- (get-index-path)))
+ *public-html*))
(defun regenerate-file (entry)
(let* ((year (nth 0 entry))
(month (nth 1 entry))
(content (nth 2 entry))
(path (if (eql year :index)
- (get-index-path)
+ *public-html*
(get-monthly-path year month)))
(description (if (eql year :index)
"index"
@@ -81,7 +79,6 @@
(let ((all (miniblog.content:gen-all entries
:generator *generator*
:tz *blog-timezone*)))
- (format t "~a~%" all)
(mapcar #'regenerate-file all)))
(defun add-new (regen)
@@ -151,8 +148,21 @@
(format t "~d \"~A\" ~A~%" (first entry) (nth 3 entry) (nth 5 entry)))))
(defun init-tz ()
- (reread-timezone-repository)
- (setf *blog-timezone* (find-timezone-by-location-name "US/Pacific")))
+ (reread-timezone-repository))
+
+(defun set-config-and-defaults ()
+ (setf *root-uri* (format nil "/~~~a/" (get-username)))
+ (setf *public-html*
+ (merge-pathnames
+ (make-pathname :directory '(:relative "public_html"))
+ (user-homedir-pathname)))
+ (with-open-file (config
+ (merge-pathnames
+ (make-pathname :name ".miniblogrc")
+ (user-homedir-pathname))
+ :direction :input :if-does-not-exist nil)
+ (if config
+ (load config))))
(defun get-db-filename ()
(namestring (merge-pathnames
@@ -161,6 +171,7 @@
(defun miniblog (&key add get edit delete list start n regen-all help)
(init-tz)
+ (set-config-and-defaults)
(make-generator)
(miniblog.db:init :sqlite3 :database-name (get-db-filename))
(cond (add (add-new regen-all))
diff --git a/src/template.lhtml b/src/template.lhtml
@@ -2,43 +2,58 @@
<html>
<head>
<title><%= (or (getf env :title) "Miniblog") %></title>
+ <style>
+ header#miniblog-header { width :100%; }
+ section#miniblog-left { float: left; width: 25%; }
+ section#miniblog-main { float: left; width: <%= (if (getf env :links) "50%" "75%") %>; }
+ nav#miniblog-nav { float: left; width: 25%; }
+ table.calendar td { width: 25%; }
+ </style>
</head>
<body>
- <header>
+ <header id="miniblog-header">
+ <% @if header %>
+ <% @endif %>
</header>
- <% @if posts %>
- <% (let ((short-date)) %>
- <% (loop for (id created-at updated-at title content username last-updated-by) in (getf env :posts) do %>
- <% (let ((curr-short-date (funcall (getf env :short-date-formatter) created-at))) %>
- <% (if (string/= short-date curr-short-date)
- (progn
- (setf short-date curr-short-date)
- (format t "<h1>~A</h1>~%" short-date)))) %>
- <h2><%= title %></h2>
- <article>
- <%= (funcall (getf env :content-formatter) content) %>
- </article>
- <p>
- <small>
- Posted by <%= username %> on
- <%= (funcall (getf env :long-date-formatter) created-at) %>
- <% (if (local-time:timestamp/= created-at updated-at)
- (format t "<br>~%Last updated by ~A on ~A~%"
- last-updated-by
- (funcall (getf env :long-date-formatter) updated-at))) %>
- </small>
- </p>
+ <section id="miniblog-left">
+ <% @if links %>
+ <% @endif %>
+ </section>
+ <section id="miniblog-main">
+ <% @if posts %>
+ <% (let ((short-date)) %>
+ <% (loop for (id created-at updated-at title content username last-updated-by) in (getf env :posts) do %>
+ <% (let ((curr-short-date (funcall (getf env :short-date-formatter) created-at))) %>
+ <% (if (string/= short-date curr-short-date)
+ (progn
+ (setf short-date curr-short-date)
+ (format t "<h1>~A</h1>~%" short-date)))) %>
+ <h2><%= title %></h2>
+ <article>
+ <%= (funcall (getf env :content-formatter) content) %>
+ </article>
+ <p>
+ <small>
+ Posted by <%= username %> on
+ <%= (funcall (getf env :long-date-formatter) created-at) %>
+ <% (if (local-time:timestamp/= created-at updated-at)
+ (format t "<br>~%Last updated by ~A on ~A~%"
+ last-updated-by
+ (funcall (getf env :long-date-formatter) updated-at))) %>
+ </small>
+ </p>
+ <% ) %>
<% ) %>
- <% ) %>
- <% @else %>
- No posts found.
- <% @endif %>
- <nav>
+ <% @else %>
+ No posts found.
+ <% @endif %>
+ </section>
+ <nav id="miniblog-nav">
<% @if archive-date-list %>
<%
(let ((arc (copy-list (getf env :archive-date-list))))
(loop while arc do
- (format t "<div class=\"cal-title\">~a</div>" (caar arc))
+ (format t "<table class=\"calendar\"><tr><th colspan=\"4\">~a</th></tr>~%" (caar arc))
(let ((month-entries '())
(month-names '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")))
(loop for cal-month downfrom 12 to 1 do
@@ -48,14 +63,15 @@
(pop arc))
(push nil month-entries)))
(loop for row from 0 to 2 do
- (format t "<div class=\"cal-row\">~%")
+ (format t "<tr>~%")
(loop for cal-month from (* row 4) to (+ (* row 4) 3) do
- (format t "<span class=\"cal-cell\">")
+ (format t "<td>")
(if (nth cal-month month-entries)
(format t "<a href=\"~a\">~a</a>" (nth cal-month month-entries) (nth cal-month month-names))
(format t "~A" (nth cal-month month-names)))
- (format t "</span>~%"))
- (format t "</div>~%"))))) %>
+ (format t "</td>~%"))
+ (format t "</tr>~%")))
+ (format t "</table>~%"))) %>
<% @endif %>
</nav>
</body>