Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
clo
cl-site
Commits
5c3d2896
Commit
5c3d2896
authored
Apr 23, 2017
by
Cheshire Yang
Browse files
Finish basic template rendering
parent
6c7378be
Changes
2
Hide whitespace changes
Inline
Side-by-side
layout/templates/primary.html
View file @
5c3d2896
<!doctype html>
<html>
<head>
<title>
{{title}}
</title>
</head>
<body>
<header>
Site
header
</header>
<header>
Site
Title
</header>
Test post please ignore
{{page-content}}
</body>
</html>
main.lisp
View file @
5c3d2896
...
...
@@ -3,7 +3,7 @@
;; Locations for various files
(
defparameter
*PAGES-DIR*
"content/"
)
(
defparameter
*LAYOUT-DIR*
"layout/"
)
(
defparameter
*LAYOUT-DIR*
"layout/
templates/
"
)
(
defparameter
*OUTPUT-DIR*
"output/"
)
(
defparameter
*PRIVATE-KEYS*
'
(
:slug
:content
))
...
...
@@ -13,19 +13,34 @@
(
:slug
.
"test-page"
)
(
:content
.
"testpage.html"
))))
(
defun
render-page
(
page
)
(
let
((
input-path
(
pathname
(
concatenate
'string
*PAGES-DIR*
(
cdr
(
assoc
:content
page
)))))
(
output-path
(
pathname
(
concatenate
'string
*OUTPUT-DIR*
(
cdr
(
assoc
:content
page
)))))
(
page-context
(
remove-if
(
lambda
(
p
)
(
find
p
*PRIVATE-KEYS*
))
page
:key
'car
)))
;; Default template to use unless another is explicitly specified.
(
defparameter
*DEFAULT-PAGE-TEMPLATE*
"primary.html"
)
(
defun
make-path
(
prefix
page
)
(
pathname
(
concatenate
'string
prefix
(
cdr
(
assoc
:content
page
)))))
(
defun
file-to-string
(
filepath
)
(
with-open-file
(
stream
filepath
)
(
let
((
data
(
make-string
(
file-length
stream
))))
(
read-sequence
data
stream
)
data
)))
(
defun
render-page
(
page
template-path
)
(
let*
((
page-path
(
make-path
*PAGES-DIR*
page
))
(
output-path
(
make-path
*OUTPUT-DIR*
page
))
(
page-content
(
file-to-string
page-path
))
(
page-context
(
remove-if
(
lambda
(
p
)
(
find
p
*PRIVATE-KEYS*
))
(
push
(
cons
:page-content
page-content
)
page
)
:key
'car
)))
(
with-open-file
(
output-stream
output-path
:direction
:output
:if-exists
:supersede
)
(
mustache:render
input
-path
page-context
output-stream
))))
(
mustache:render
template
-path
page-context
output-stream
))))
(
defun
make-site
()
(
let
((
template-path
(
pathname
(
concatenate
'string
*LAYOUT-DIR*
*DEFAULT-PAGE-TEMPLATE*
))))
(
loop
for
page
in
*PAGES*
do
(
render-page
page
)))
do
(
render-page
page
template-path
)
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment