Skip to content

Commit

Permalink
Added a new-site command-line utility.
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlyak40wt committed Apr 30, 2024
1 parent 9710473 commit 2e4de7d
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 0 deletions.
20 changes: 20 additions & 0 deletions skeleton/.staticlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
;;; -*- mode : lisp -*-
(in-package #:staticl-user)

;; This way you can load all required plugins,
;; which are not included into the Staticl system:
(asdf:load-system "staticl/format/spinneret")

(site "{{title}}"
:description "{{description}}"
:url "{{url}}"
:navigation (menu (item "Blog" "/blog/")
(item "About" "/about/"))
:pipeline (list (load-content)
(prev-next-links)
(paginated-index :target-path "blog/")
(rss :target-path "blog/rss.xml")
(atom :target-path "blog/atom.xml")
(tags-index :target-path "tags/")
(sitemap))
:theme "readable")
14 changes: 14 additions & 0 deletions skeleton/about.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;;;;;
title: About this site
created-at: 2024-03-30
format: spinneret
;;;;;

(:h2 "Subtitle")

(:p "This is an example of a page written using Spinneret. It's main advantage is an ability to use Lisp for HTML generation.")
(:p "You can execute any code to get data for the page - access a database or some API. Note that these actions will be performed
during the build stage and site itself will remain static.")
(:p "Using Spinneret you can use any HTML markup. If you want to draw a red square, you just do it:")

(:div :style "width: 200px; height: 200px; background: red;")
12 changes: 12 additions & 0 deletions skeleton/blog/first.post
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;;;;;
title: The first post
tags: example, foo
created-at: 2024-04-15
format: md
;;;;;

This post contains some *Markdown* markup.

<!--more-->

Following part only visible on the post page, not in the indices.
12 changes: 12 additions & 0 deletions skeleton/blog/second.post
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;;;;;
title: The second post
tags: example, bar
created-at: 2024-04-30
format: md
;;;;;

Another post. StatiCL is more versatile than Coleslaw, because of it's modular architecture.

<!--more-->

Following part only visible on the post page, not in the indices.
12 changes: 12 additions & 0 deletions skeleton/index.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;;;;;
title: An index page.
created-at: 2024-03-30
format: md
;;;;;

This is a front page of example site. The site uses StatiCL generator written in Common Lisp.

Blog posts are available at [/blog/](/blog/). There is also an [/about/](/about/) page.

The blog has an rss feed, and all pages are gathered into a
single [sitemap.xml](/sitemap.xml) file.
20 changes: 20 additions & 0 deletions src/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:use #:cl)
(:import-from #:staticl/core
#:stage)
(:import-from #:staticl/skeleton)
(:import-from #:defmain
#:subcommand
#:defcommand
Expand Down Expand Up @@ -44,3 +45,22 @@
(when *verbose*
(format t "Site was written to: ~A~%"
(namestring output-dir)))))


(defcommand (main new-site) ((output-dir "An output directory to write site files to."
:default (namestring
(uiop:ensure-directory-pathname
*default-pathname-defaults*)))
(description "Site's description."
:default "A site description.")
title url)
"Creates a new site skeleton with a few posts."
(let ((output-dir (uiop:ensure-directory-pathname
output-dir)))
(staticl/skeleton:create-site output-dir
title
url
:description description)
(when *verbose*
(format t "Site's content was written to: ~A~%"
(namestring output-dir)))))
62 changes: 62 additions & 0 deletions src/skeleton.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(uiop:define-package #:staticl/skeleton
(:use #:cl)
(:import-from #:serapeum
#:->)
(:import-from #:mystic.template.file
#:file-mixin)
(:import-from #:mystic
#:make-option)
(:import-from #:mystic.util
#:read-template-file)
(:import-from #:mystic.template.file
#:file)
(:export
#:create-site))
(in-package #:staticl/skeleton)


(defclass staticl-site (file-mixin)
()
(:default-initargs
:options (list (make-option :title
"Title"
"The site's title."
:requiredp t)
(make-option :description
"Description"
"The site's description."
:requiredp t)
(make-option :url
"URL"
"The site's URL."
:requiredp t))))


(defun read-all-files (from-dir)
(loop with from-dir = (uiop:ensure-directory-pathname from-dir)
for filename in (directory (uiop:wilden from-dir))
for relative-path = (enough-namestring filename from-dir)
unless (uiop:directory-pathname-p filename)
collect
(make-instance 'file
:path relative-path
:content (alexandria:read-file-into-string filename))))


(-> create-site ((or pathname string) string string &key (:description string))
(values &optional))

(defun create-site (path title url &key (description ""))
"Creates a new site skeleton with a few posts."
(let ((files (read-all-files
(asdf:system-relative-pathname :staticl
(make-pathname
:directory '(:relative "skeleton"))))))
(mystic:render
(make-instance 'staticl-site
:files files)
(list :title title
:url url
:description description)
(uiop:merge-pathnames*
(uiop:ensure-directory-pathname path)))))
3 changes: 3 additions & 0 deletions staticl.asd
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
(asdf:register-system-packages "3bmd-ext-code-blocks" '("3BMD-CODE-BLOCKS"))
(asdf:register-system-packages "fuzzy-dates" '("ORG.SHIRAKUMO.FUZZY-DATES"))
(asdf:register-system-packages "feeder" '("ORG.SHIRAKUMO.FEEDER"))

(asdf:register-system-packages "mystic" '("MYSTIC.UTIL"))
(asdf:register-system-packages "mystic-file-mixin" '("MYSTIC.TEMPLATE.FILE"))

0 comments on commit 2e4de7d

Please sign in to comment.