Skip to content

Commit 2ca4859

Browse files
author
Adam Simpson
committed
chore: fix indents
1 parent b8e61c2 commit 2ca4859

File tree

1 file changed

+107
-107
lines changed

1 file changed

+107
-107
lines changed

cycle.lisp

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"CSS for the site.")
99

1010
(opts:define-opts
11-
(:name :help
12-
:description "`generate` is the only available command at the moment."
13-
:short #\h
14-
:long "help"))
11+
(:name :help
12+
:description "`generate` is the only available command at the moment."
13+
:short #\h
14+
:long "help"))
1515

1616
(defun concat (&rest strings)
1717
"Wrapper around the more cumbersome concatenate form."
@@ -39,7 +39,7 @@
3939
(defun parse-post (post)
4040
"Create list that contains the data from each JSON file combined with the body of every post."
4141
(let* ((json (uiop:read-file-string (car (cdr post))))
42-
(list-json (json:decode-json-from-string json)))
42+
(list-json (json:decode-json-from-string json)))
4343
`(,@list-json (:content . ,(post-for-slug (cdr (assoc :slug list-json)))))))
4444

4545
(defun full-path-as-string (dir)
@@ -69,8 +69,8 @@
6969
(defun write-file (contents file)
7070
"Write CONTENTS to FILE."
7171
(with-open-file (stream file
72-
:direction :output
73-
:if-exists :supersede)
72+
:direction :output
73+
:if-exists :supersede)
7474
(write-sequence contents stream)))
7575

7676
(defun post-for-slug (slug)
@@ -85,49 +85,49 @@
8585
(defun gen-posts ()
8686
"Generate posts from post data, templates, and css file(s)."
8787
(if (uiop:file-exists-p "templates/post.mustache")
88-
(let ((template (uiop:read-file-string "templates/post.mustache"))
89-
post
90-
rendered)
91-
(dolist (pair posts)
92-
(setf post `((:content . ,(cdr (assoc :content pair)))
93-
(:pub_date . ,(cdr (assoc :published pair)))
94-
(:mod_date . ,(cdr (assoc :modified pair)))
95-
(:modifiedDate . ,(parse-date (cdr (assoc :modified pair))))
96-
(:formattedDate . ,(parse-date (cdr (assoc :published pair))))
97-
(:link . ,(cdr (assoc :link pair)))
98-
(:description . ,(cdr (assoc :excerpt pair)))
99-
(:slug . ,(concat "/writing/"
100-
(cdr (assoc :slug pair))))
101-
(:css . ,css)
102-
(:title . ,(cdr (assoc :title pair)))))
103-
104-
(setf rendered (mustache:render* template post))
105-
(write-file rendered (concat
106-
"site/writing/"
107-
(cdr (assoc :slug pair))
108-
".html"))))
109-
(print "No post.mustache template found. Create it in templates/.")))
88+
(let ((template (uiop:read-file-string "templates/post.mustache"))
89+
post
90+
rendered)
91+
(dolist (pair posts)
92+
(setf post `((:content . ,(cdr (assoc :content pair)))
93+
(:pub_date . ,(cdr (assoc :published pair)))
94+
(:mod_date . ,(cdr (assoc :modified pair)))
95+
(:modifiedDate . ,(parse-date (cdr (assoc :modified pair))))
96+
(:formattedDate . ,(parse-date (cdr (assoc :published pair))))
97+
(:link . ,(cdr (assoc :link pair)))
98+
(:description . ,(cdr (assoc :excerpt pair)))
99+
(:slug . ,(concat "/writing/"
100+
(cdr (assoc :slug pair))))
101+
(:css . ,css)
102+
(:title . ,(cdr (assoc :title pair)))))
103+
104+
(setf rendered (mustache:render* template post))
105+
(write-file rendered (concat
106+
"site/writing/"
107+
(cdr (assoc :slug pair))
108+
".html"))))
109+
(print "No post.mustache template found. Create it in templates/.")))
110110

111111
(defun gen-archive ()
112112
"Create archive type pages."
113113
(if (and (uiop:file-exists-p "pages/archive.mustache")
114114
(uiop:file-exists-p "pages/archive.json"))
115115
(let* ((template (uiop:read-file-string "pages/archive.mustache"))
116-
(data (json:decode-json-from-string (uiop:read-file-string "pages/archive.json")))
117-
(css `(:css . ,css))
118-
(limit (cdr (assoc :paginate data)))
119-
(path (concat "site" (cdr (assoc :path data))))
120-
page
121-
times
122-
pagination)
116+
(data (json:decode-json-from-string (uiop:read-file-string "pages/archive.json")))
117+
(css `(:css . ,css))
118+
(limit (cdr (assoc :paginate data)))
119+
(path (concat "site" (cdr (assoc :path data))))
120+
page
121+
times
122+
pagination)
123123
(ensure-directories-exist path)
124124
(if (> limit 0)
125125
(progn
126126
(setf times (+ (floor (length posts) limit) 1))
127127
(dotimes (i times)
128128
(setf page (concat path
129-
(write-to-string (+ 1 i))
130-
".html"))
129+
(write-to-string (+ 1 i))
130+
".html"))
131131
(setf pagination (gen-pagination-for-archive (+ i 1) times))
132132
(when (= i (- times 1))
133133
(write-file (mustache:render* template
@@ -146,11 +146,11 @@
146146
(* i limit)
147147
(+ (* i limit) limit)))))
148148
page))))
149-
(write-file (mustache:render* template
150-
`(,css
151-
(:posts . ,posts)))
152-
(concat path ".html"))))
153-
(print "The files for generating an archive are missing. Create a archive.mustache file and a archive.json file in pages/.")))
149+
(write-file (mustache:render* template
150+
`(,css
151+
(:posts . ,posts)))
152+
(concat path ".html"))))
153+
(print "The files for generating an archive are missing. Create a archive.mustache file and a archive.json file in pages/.")))
154154

155155
(defun gen-pagination-for-archive (index limit)
156156
"Given INDEX and LIMIT this will return an alist of values for pagination."
@@ -178,38 +178,38 @@
178178
(defun gen-index()
179179
(if (uiop:file-exists-p "templates/index.mustache")
180180
(let* ((template (uiop:read-file-string "templates/index.mustache"))
181-
(posts (subseq posts 0 10))
182-
(rendered (mustache:render* template `((:posts . ,posts) (:css . ,css)))))
181+
(posts (subseq posts 0 10))
182+
(rendered (mustache:render* template `((:posts . ,posts) (:css . ,css)))))
183183
(write-file rendered "site/index.html"))
184-
(print "No index.mustache file found. Create a mustache file named index.mustache in templates/.")))
184+
(print "No index.mustache file found. Create a mustache file named index.mustache in templates/.")))
185185

186186
(defun gen-pages ()
187187
"Generate any markdown files in the pages/ dir using matching JSON files as context."
188188
(if (uiop:file-exists-p "templates/page.mustache")
189-
(let ((pages (uiop:directory-files "pages/" "*.md"))
190-
(css `(:css . ,css))
191-
(template (uiop:read-file-string "templates/page.mustache"))
192-
data
193-
content)
194-
(dolist (page pages)
195-
(setf data (json:decode-json-from-string (uiop:read-file-string
196-
(concat "pages/"
197-
(file-basename page)
198-
".json"))))
199-
(setf content (with-output-to-string (p)
200-
(3bmd:parse-string-and-print-to-stream (uiop:read-file-string page) p)))
201-
(ensure-directories-exist (concat "site/" (cdr (assoc :permalink data))))
202-
(write-file (mustache:render* template `((:slug . ,(cdr (assoc :permalink data)))
203-
,css
204-
,@data
205-
(:content . ,content)))
206-
(concat "site/" (cdr (assoc :permalink data)) ".html"))))
207-
(print "No page.mustache file found. Please create one in templates/.")))
189+
(let ((pages (uiop:directory-files "pages/" "*.md"))
190+
(css `(:css . ,css))
191+
(template (uiop:read-file-string "templates/page.mustache"))
192+
data
193+
content)
194+
(dolist (page pages)
195+
(setf data (json:decode-json-from-string (uiop:read-file-string
196+
(concat "pages/"
197+
(file-basename page)
198+
".json"))))
199+
(setf content (with-output-to-string (p)
200+
(3bmd:parse-string-and-print-to-stream (uiop:read-file-string page) p)))
201+
(ensure-directories-exist (concat "site/" (cdr (assoc :permalink data))))
202+
(write-file (mustache:render* template `((:slug . ,(cdr (assoc :permalink data)))
203+
,css
204+
,@data
205+
(:content . ,content)))
206+
(concat "site/" (cdr (assoc :permalink data)) ".html"))))
207+
(print "No page.mustache file found. Please create one in templates/.")))
208208

209209
(defun return-leading-zero-as-string (number)
210210
(if (< number 10)
211211
(concat "0" (write-to-string number))
212-
(write-to-string number)))
212+
(write-to-string number)))
213213

214214
(defun now-as-rfc-822 ()
215215
(date-as-rfc-822 (local-time:format-timestring nil (local-time:now))))
@@ -257,12 +257,12 @@
257257

258258
(defun gen-rss ()
259259
(if (uiop:file-exists-p "templates/rss.mustache")
260-
(let* ((posts (subseq posts 0 20))
261-
(now (now-as-rfc-822))
262-
(template (uiop:read-file-string "templates/rss.mustache"))
263-
(proper-posts (mapcar 'format-data-for-rss posts)))
264-
(write-file (mustache:render* template `((:now . ,now) (:posts . ,proper-posts))) "site/rss.xml"))
265-
(print "No rss template found. Please create one in templates/.")))
260+
(let* ((posts (subseq posts 0 20))
261+
(now (now-as-rfc-822))
262+
(template (uiop:read-file-string "templates/rss.mustache"))
263+
(proper-posts (mapcar 'format-data-for-rss posts)))
264+
(write-file (mustache:render* template `((:now . ,now) (:posts . ,proper-posts))) "site/rss.xml"))
265+
(print "No rss template found. Please create one in templates/.")))
266266

267267
(defun format-data-for-sitemap (post)
268268
`((:slug . ,(cdr (assoc :slug post))) (:date . ,(cdr (assoc :published post)))))
@@ -277,14 +277,14 @@
277277

278278
(defun gen-sitemap ()
279279
(if (uiop:file-exists-p "templates/sitemap.mustache")
280-
(let ((proper-posts (mapcar 'format-data-for-sitemap posts))
281-
(pages (get-page-slugs))
282-
(template (uiop:read-file-string "templates/sitemap.mustache")))
283-
(write-file (mustache:render*
284-
template
285-
`((:posts . ,proper-posts) (:pages . ,pages)))
286-
"site/sitemap.xml"))
287-
(print "No sitemap.mustache template found. Please create one in templates/.")))
280+
(let ((proper-posts (mapcar 'format-data-for-sitemap posts))
281+
(pages (get-page-slugs))
282+
(template (uiop:read-file-string "templates/sitemap.mustache")))
283+
(write-file (mustache:render*
284+
template
285+
`((:posts . ,proper-posts) (:pages . ,pages)))
286+
"site/sitemap.xml"))
287+
(print "No sitemap.mustache template found. Please create one in templates/.")))
288288

289289
(defun get-id()
290290
"Get all JSON files representing all posts and return the next ID to use."
@@ -319,31 +319,31 @@
319319
"The pipeline to build the site."
320320

321321
(if (equal (car (cdr (opts:argv))) "generate")
322-
(generate-post (car (last (opts:argv))))
323-
(progn
324-
(ensure-directories-exist "site/writing/")
325-
(when (uiop:subdirectories "./templates")
326-
(setf mustache:*load-path* `(,(namestring (car (uiop:subdirectories "./templates"))))))
327-
(when (uiop:file-exists-p "site.css")
328-
(setf css (uiop:read-file-string "site.css")))
329-
(setf mustache:*default-pathname-type* "mustache")
330-
(setf 3bmd-code-blocks:*code-blocks* t)
331-
(setf posts (reverse (sort (gen-data)
332-
'sort-by-ids
333-
:key 'car)))
334-
335-
(multiple-value-bind (options free-args)
336-
(opts:get-opts)
337-
(when options
338-
(opts:describe)))
339-
340-
(if (and css posts)
322+
(generate-post (car (last (opts:argv))))
341323
(progn
342-
(copy-public)
343-
(gen-archive)
344-
(gen-index)
345-
(gen-pages)
346-
(gen-posts)
347-
(gen-rss)
348-
(gen-sitemap))
349-
(print "No posts found. Create a md file in posts/. Also create a site.css file in the root.")))))
324+
(ensure-directories-exist "site/writing/")
325+
(when (uiop:subdirectories "./templates")
326+
(setf mustache:*load-path* `(,(namestring (car (uiop:subdirectories "./templates"))))))
327+
(when (uiop:file-exists-p "site.css")
328+
(setf css (uiop:read-file-string "site.css")))
329+
(setf mustache:*default-pathname-type* "mustache")
330+
(setf 3bmd-code-blocks:*code-blocks* t)
331+
(setf posts (reverse (sort (gen-data)
332+
'sort-by-ids
333+
:key 'car)))
334+
335+
(multiple-value-bind (options free-args)
336+
(opts:get-opts)
337+
(when options
338+
(opts:describe)))
339+
340+
(if (and css posts)
341+
(progn
342+
(copy-public)
343+
(gen-archive)
344+
(gen-index)
345+
(gen-pages)
346+
(gen-posts)
347+
(gen-rss)
348+
(gen-sitemap))
349+
(print "No posts found. Create a md file in posts/. Also create a site.css file in the root.")))))

0 commit comments

Comments
 (0)