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
8980a330
Commit
8980a330
authored
Apr 24, 2017
by
Cheshire Yang
Browse files
Refactor code organization
parent
17feca53
Changes
5
Hide whitespace changes
Inline
Side-by-side
cl-site.asd
View file @
8980a330
...
...
@@ -12,7 +12,11 @@
:licence
"TBD"
:description
"Static site generator for CLnet, written in CL"
:depends-on
(
:cl-mustache
)
:depends-on
(
:asdf
:cl-mustache
)
:components
((
:file
"main"
))
:serial
t
:components
((
:file
"globals"
)
(
:file
"helpers"
)
(
:file
"process"
)
(
:file
"main"
))
)
\ No newline at end of file
globals.lisp
0 → 100644
View file @
8980a330
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(
in-package
:cl-site
)
;; Location of template files
(
defparameter
*LAYOUT-DIR*
(
asdf:system-relative-pathname
:cl-site
"layout/templates/"
))
;; Where generated output should be written to
(
defparameter
*OUTPUT-DIR*
(
asdf:system-relative-pathname
:cl-site
"output/"
))
;; Default template to use unless another is explicitly specified.
;; (More template-related variables may go here in the future)
(
defparameter
*DEFAULT-PAGE-TEMPLATE*
"primary.html"
)
;; Location and list of styles
;; *STYLES* should be list of strings representing relative filenames.
;; @TO-DO: replace this with better css preprocessing.
(
defparameter
*STYLES-DIR*
(
asdf:system-relative-pathname
:cl-site
"content/css/"
))
(
defparameter
*STYLES*
(
list
"main.css"
))
;; Location & list of pages
;; Each page is an alist containing info to be sent to the template via the context.
;; The only REQUIRED field is :content which must be the filename of the page content
;; The :content field will NOT be sent to the template.
(
defparameter
*PAGES-DIR*
(
asdf:system-relative-pathname
:cl-site
"content/"
))
(
defparameter
*PRIVATE-KEYS*
'
(
:slug
:content
))
(
defparameter
*PAGES*
(
list
'
((
:title
.
"Test Page"
)
(
:slug
.
"test-page"
)
(
:content
.
"testpage.html"
))))
;; Initialize global context (will be appended to all individual page contexts)
;; Used to store things like stylesheets, etc...
(
defparameter
*GLOBAL-CONTEXT*
())
\ No newline at end of file
helpers.lisp
0 → 100644
View file @
8980a330
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(
in-package
:cl-site
)
; Makes pathname from prefix + page object
(
defun
make-path
(
prefix
page
)
(
let
((
path
(
cdr
(
assoc
:content
page
))))
(
if
(
pathnamep
prefix
)
(
merge-pathnames
path
prefix
)
(
pathname
(
concatenate
'string
prefix
path
)))))
; Slurps file from a string
(
defun
file-to-string
(
filepath
)
(
with-open-file
(
stream
filepath
)
(
let
((
data
(
make-string
(
file-length
stream
))))
(
read-sequence
data
stream
)
data
)))
main.lisp
View file @
8980a330
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(
in-package
:cl-site
)
(
require
:asdf
)
;; Locations for various files
(
defparameter
*PAGES-DIR*
(
asdf:system-relative-pathname
:cl-site
"content/"
))
(
defparameter
*LAYOUT-DIR*
(
asdf:system-relative-pathname
:cl-site
"layout/templates/"
))
(
defparameter
*OUTPUT-DIR*
(
asdf:system-relative-pathname
:cl-site
"output/"
))
(
defparameter
*PRIVATE-KEYS*
'
(
:slug
:content
))
(
defparameter
*PAGES*
(
list
'
((
:title
.
"Test Page"
)
(
:slug
.
"test-page"
)
(
:content
.
"testpage.html"
))))
;; Default template to use unless another is explicitly specified.
(
defparameter
*DEFAULT-PAGE-TEMPLATE*
"primary.html"
)
(
defun
make-path
(
prefix
page
)
(
let
((
path
(
cdr
(
assoc
:content
page
))))
(
if
(
pathnamep
prefix
)
(
merge-pathnames
path
prefix
)
(
pathname
(
concatenate
'string
prefix
path
)))))
(
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
template-path
page-context
output-stream
))))
(
defun
make-site
()
(
let
((
template-path
(
pathname
(
merge-pathnames
*LAYOUT-DIR*
*DEFAULT-PAGE-TEMPLATE*
))))
(
loop
for
page
in
*PAGES*
do
(
render-page
page
template-path
))))
(
process-pages
))
\ No newline at end of file
process.lisp
0 → 100644
View file @
8980a330
;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
(
in-package
:cl-site
)
;; Copies/renders stylesheets + adds to global context
(
defun
process-styles
()
)
;; Copies/renders static assets (imgs, etc)
(
defun
process-static
()
)
;; process-pages : Copies/renders pages - called last
(
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
template-path
page-context
output-stream
))))
(
defun
process-pages
()
(
let
((
template-path
(
pathname
(
merge-pathnames
*LAYOUT-DIR*
*DEFAULT-PAGE-TEMPLATE*
))))
(
progn
(
ensure-directories-exist
*OUTPUT-DIR*
)
(
loop
for
page
in
*PAGES*
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