-
Notifications
You must be signed in to change notification settings - Fork 0
/
pages.lisp
179 lines (163 loc) · 6.54 KB
/
pages.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
;;; file: pages.lisp
;;;
;;; Copyright (c) 2007 Cyrus Harmon ([email protected])
;;; All rights reserved.
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;;
;;; * Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;;
;;; * Redistributions in binary form must reproduce the above
;;; copyright notice, this list of conditions and the following
;;; disclaimer in the documentation and/or other materials
;;; provided with the distribution.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;;
(in-package :nuclblog)
(defun entry-link (blog entry)
(concatenate-url
(blog-display-entry-url blog)
"?id="
(url-encode (prin1-to-string (blog-entry-number entry)))))
(defun archives-url (blog &key category rss)
(if category
(concatenate 'string
(if rss
(blog-rss-url blog)
(blog-archives-url))
(if rss "?" "/")
category)
(if rss (blog-rss-url blog) (blog-archives-url blog))))
(defmacro box ((&key class id) head &rest body)
`(with-html-output (*standard-output*)
(:div :id ,id :class ,(concatenate 'string "nuclblog-box " class)
,(when head
`(:div :class "nuclblog-box-head"
,head))
(:div :class "nuclblog-box-body"
,@body))))
(defun recent-entries (blog)
(with-html
(box (:class "nuclblog-nav-box" :id "nuclblog-nav-box-recent-entries")
(:h2 "Recent entries")
(:ul :class "nuclblog-recent-entries"
(loop for i from 1 to 10
for j in (blog-entries blog)
do (htm
(:li
(:a :href (entry-link blog j)
(str (blog-entry-title j))))))))))
(defun categories (blog)
(with-html
(box (:class "nuclblog-nav-box" :id "nuclblog-nav-box-categories")
(:h2 "Categories")
(:ul
(loop for i in (blog-categories blog)
do (htm
(:li (:a :href (make-archives-url blog i)
(str i))
" "
(:a :href (make-archives-url blog i :rss t)
"(RSS)"))))))))
(defun buttons (blog)
(with-html
(box (:class "nuclblog-nav-box nav-button" :id "nuclblog-nav-box-buttons")
nil
(:ul :class "nuclblog-buttons"
(loop for button in (blog-buttons blog)
do
(destructuring-bind (&key href-url id img-url alt) button
(htm
(:li
(:a :href href-url :class "nuclblog-button"
(:img :id id
:src img-url
:alt (escape-string alt)))))))))))
(defun main-nav (blog)
(box (:class "nuclblog-nav-box" :id "nuclblog-nav-box-1")
(:h2 (str (blog-short-name blog)))
(:ul
(:li (:a :href (blog-url-root blog) "Blog"))
(:li (:a :href (blog-new-entry-url blog) "New entry"))
(:li (:a :href (blog-archives-url blog) "Archives"))
(:li (:a :href (archives-url blog :rss t) "Syndicate (RSS)"))
(:li (:a :href (blog-email-redirect-url blog) "Send Comments"))
(if (hunchentoot-auth:session-realm-user-authenticated-p (blog-realm blog))
(htm (:li (:a :href (blog-logout-url blog) "Logout")))
(htm (:li (:a :href (blog-login-url blog) "Login")))))))
(defgeneric nav-boxes (blog))
(defmethod nav-boxes ((blog blog))
(main-nav blog)
(recent-entries blog)
(categories blog))
(defun nav (blog)
(with-html-output (*standard-output*)
(:div :id "nuclblog-nav" :class "nuclblog-nav"
(nav-boxes blog)
(buttons blog))))
(defgeneric banner (blog)
(:method (blog)
(with-html-output (*standard-output*)
(:div :id "nuclblog-banner"
(let ((url (blog-logo-img-url blog)))
(when url
(htm (:div :id "nuclblog-bannerleft"
(:img :class "nuclblog-titlelogo" :src url :alt ""))
" ")))
(:div :id "nuclblog-bannertext"
(:h1 (str (blog-title blog)))
(:h2 (str (blog-subtitle blog))))
(:div :class "nuclblog-pad" " ")))))
(defgeneric footer (blog)
(:method (blog)))
(defun blog-page (blog title body-function)
(with-html-page
((:html :xmlns "http://www.w3.org/1999/xhtml")
(:head (:title (str title))
(:link :rel "alternate" :type "application/rss+xml"
:title "RSS feed" :href (blog-rss-url blog))
(loop for style in (blog-page-css blog)
do
(htm
(:link :rel "stylesheet"
:title (car style) :type "text/css" :href (cdr style)))))
(:body
(banner blog)
(:div :id "nuclblog-main"
(nav blog)
(:div :id "nuclblog-content"
(funcall body-function)))
(footer blog)))))
(defmacro with-blog-page (blog title &body body)
`(with-html-page
((:html :xmlns "http://www.w3.org/1999/xhtml")
(:head (:title (str ,title))
(:link :rel "alternate" :type "application/rss+xml"
:title "RSS feed" :href (blog-rss-url blog))
(loop for style in (blog-page-css ,blog)
do
(htm
(:link :rel "stylesheet"
:title (car style) :type "text/css" :href (cdr style)))))
(:body
(banner ,blog)
(:div :id "nuclblog-main"
(nav ,blog)
(:div :id "nuclblog-content"
(progn
,@body)))
(footer ,blog)))))