Skip to content
/ staticl Public

Flexible and customizable static site generator with a lot of plugins!

Notifications You must be signed in to change notification settings

40ants/staticl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

staticl - Flexible static site generator.

STATICL ASDF System Details

Installation

You can install this library from Quicklisp, but you want to receive updates quickly, then install it from Ultralisp.org:

(ql-dist:install-dist "http://dist.ultralisp.org/"
                      :prompt nil)
(ql:quickload :staticl)

Usage

StatiCL is a static site generator. StatiCL as a modular architecture and is suitable for any kind of a site be it a blog or a site with pages not included in the feeds. This project was created to overcome limitations of the Coleslaw.

Processing Pipeline

First of all, a STATICL:SITE object is created and filled with options from .staticlrc file.

Then staticl:stage function calls STATICL/CONTENT:READ-CONTENT generic-function which returns a list of staticl/content:content objects. On the next stage, initial list of content objects are passed to a generic-function staticl/content:preprocess called with a preprocessor returned by a generic-function STATICL/PLUGINS:SITE-PLUGINS as a first argument. Each preprocessor may return additional staticl/content:content objects such as index pages, RSS or ATOM feeds, sitemaps etc.

When all content was preprocessed, a generic-function staticl/content:write-content is called on each staticl/content:content object and a SITE object. Content objects are having a format slot, so internally staticl/content:write-content generic-function creates an object of corresponding format class or takes it from the cache and then calls staticl/content:write-content-to-stream using this format object.

API

STATICL

package staticl

Functions

function staticl:stage &KEY (ROOT-DIR *DEFAULT-PATHNAME-DEFAULTS*) (STAGE-DIR (MERGE-PATHNAMES (MAKE-PATHNAME :DIRECTORY '(:RELATIVE "stage"))
             (UIOP/PATHNAME:ENSURE-DIRECTORY-PATHNAME ROOT-DIR)))

STATICL/CLEAN-URLS

package staticl/clean-urls

Generics

generic-function staticl/clean-urls:transform-filename site filename

Converts the pathname to the form that should be used to write content to the disk.

If the site has the clean-urls setting enabled, then the filename like some/page.html will be converted to some/page/index.html. If clean-urls is not enabled, the pathname will remain unchanged.

generic-function staticl/clean-urls:transform-url site url

Converts the URL to the form that should be used on the site.

If the site has the clean-urls setting enabled, then the URL like /some/page.html will be converted to /some/page/. If clean-urls is not enabled, the URL will remain unchanged.

STATICL/CONTENT

package staticl/content

Classes

CONTENT-FROM-FILE

class staticl/content:content-from-file (content-with-title-mixin content-with-tags-mixin content)

Readers

reader staticl/content:content-created-at (content-from-file) (:created-at)

reader staticl/content:content-excerpt-separator (content-from-file) (:excerpt)

reader staticl/content:content-file (content-from-file) (:file)

Absolute pathname to the file read from disk or NIL for content objects which have no source file, like RSS feeds.

reader staticl/content:content-format (content-from-file) (:format)

reader staticl/content:content-template (content-from-file) (:template)

reader staticl/content:content-text (content-from-file) (:text)

CONTENT-TYPE

class staticl/content:content-type ()

Readers

reader staticl/content:content-class (content-type) (:content-class)

reader staticl/content:content-file-type (content-type) (:type)

CONTENT-WITH-TAGS-MIXIN

class staticl/content:content-with-tags-mixin ()

Readers

reader staticl/content:content-tags (content-with-tags-mixin) (:tags)

CONTENT-WITH-TITLE-MIXIN

class staticl/content:content-with-title-mixin ()

Readers

reader staticl/content:content-title (content-with-title-mixin) (:title)

CONTENT

class staticl/content:content (print-items-mixin)

Readers

reader staticl/content:content-metadata (content) (= (make-hash-table :test 'equal))

A hash with additional fields specified in the file's header.

Generics

generic-function staticl/content:get-target-filename site content stage-dir

Should return an absolute pathname to a file where this content item should be rendered.

generic-function staticl/content:preprocess site plugin content-objects

Returns an additional list content objects such as RSS feeds or sitemaps.

generic-function staticl/content:read-content-from-disk site content-type &key exclude

Returns a list of content objects corresponding to a given content type.

EXCLUDE argument is a list of pathname prefixes to ignore. Pathnames should be given relative to the root dir of the site.

generic-function staticl/content:read-contents site &key exclude

Returns a list of content objects loaded from files.

EXCLUDE argument is a list of pathname prefixes to ignore. Pathnames should be given relative to the root dir of the site.

generic-function staticl/content:supported-content-types site

Returns a list of content-type objects.

generic-function staticl/content:write-content site content stage-dir

Writes CONTENT object to the STAGE-DIR.

generic-function staticl/content:write-content-to-stream site content stream

Writes CONTENT object to the STREAM using given FORMAT.

Functions

function staticl/content:set-metadata content key value &key override-slot

Changes metadata dictionary by adding a new item with key KEY.

Key should be a string and it is automatically downcased.

Note, this way, you can override content's object slots. To prevent accidential override, function will raise an error in case if a slot named KEY exists in the object CONTENT. To force override provide OVERRIDE-SLOT argument.

STATICL/CONTENT-PIPELINE

package staticl/content-pipeline

Classes

LOAD-CONTENT

class staticl/content-pipeline:load-content ()

Readers

reader staticl/content-pipeline:exclude-patterns (load-content) (:exclude)

Functions

function staticl/content-pipeline:load-content &KEY (EXCLUDE (LIST ".qlot"))

STATICL/CONTENT/HTML-CONTENT

package staticl/content/html-content

Generics

generic-function staticl/content/html-content:content-html content

Returns a content as HTML string.

generic-function staticl/content/html-content:content-html-excerpt content

Returns an excerpt of full content as HTML string.

generic-function staticl/content/html-content:has-more-content-p content

Returns T if there is more content than was returned by content-html-excerpt generic-function.

STATICL/CONTENT/PAGE

package staticl/content/page

Classes

PAGE-TYPE

class staticl/content/page:page-type (content-type)

PAGE

class staticl/content/page:page (content-from-file)

STATICL/CONTENT/POST

package staticl/content/post

Classes

POST-TYPE

class staticl/content/post:post-type (content-type)

POST

class staticl/content/post:post (content-from-file)

This is the class for a page which will not be included into the feed and indices.

Functions

function staticl/content/post:postp content-item

Returns T if given object is a content of post class.

STATICL/CONTENT/READER

package staticl/content/reader

Functions

function staticl/content/reader:read-content-file file &key (separator *default-metadata-separator*)

Returns a plist of metadata from FILE with :TEXT holding the content going after the SEPARATOR.

STATICL/CURRENT-ROOT

package staticl/current-root

Functions

function staticl/current-root:current-root

Macros

macro staticl/current-root:with-current-root (root) &body body

STATICL/FEEDS/ATOM

package staticl/feeds/atom

Classes

ATOM

class staticl/feeds/atom:atom (feed)

Functions

function staticl/feeds/atom:atom &KEY (TARGET-PATH #P"atom.xml")

STATICL/FEEDS/RSS

package staticl/feeds/rss

Classes

RSS

class staticl/feeds/rss:rss (feed)

Functions

function staticl/feeds/rss:rss &KEY (TARGET-PATH #P"rss.xml")

STATICL/FILTER

package staticl/filter

Classes

FILTER

class staticl/filter:filter ()

Readers

reader staticl/filter:filter-fn (filter) (:filter-fn)

reader staticl/filter:pipeline-items (filter) (:pipeline)

Macros

macro staticl/filter:filter (&key path invert) &rest pipeline

Filters input content objects and processes them using steps given as a body.

Arguments:

  • PATH: if given result will contain only items read from the given path.
  • INVERT: inverts effect of the filter.

STATICL/FORMAT

package staticl/format

Generics

generic-function staticl/format:to-html text format

STATICL/INDEX/BASE

package staticl/index/base

Classes

BASE-INDEX

class staticl/index/base:base-index ()

Readers

reader staticl/content:content-template (base-index) (:template)

reader staticl/index/base:index-target-path (base-index) (:target-path)

Relative pathname to a directory where all pages will be generated.

reader staticl/index/base:page-size (base-index) (:page-size)

INDEX-PAGE

class staticl/index/base:index-page (content)

Readers

reader staticl/content:content-template (index-page) (:template)

reader staticl/index/base:next-page (index-page) (:next-page)

reader staticl/index/base:page-items (index-page) (:items)

reader staticl/index/base:page-target-path (index-page) (:target-path)

Relative pathname to a file with page content.

reader staticl/index/base:page-title (index-page) (:title)

A title of the page.

reader staticl/index/base:prev-page (index-page) (:prev-page)

Accessors

accessor staticl/index/base:next-page (index-page) (:next-page)

accessor staticl/index/base:prev-page (index-page) (:prev-page)

STATICL/INDEX/PAGINATED

package staticl/index/paginated

Classes

PAGINATED-INDEX

class staticl/index/paginated:paginated-index (base-index)

Readers

reader staticl/index/paginated:page-filename-fn (paginated-index) (:page-filename-fn)

A callback to change page titles.

Accepts single argument - a page number and should return a pathname relative to the site's root. By default, it returns index.html for the first page and page-2.html, page-3.html for others.

If site has "clean urls" setting enabled, then additional transformation to the pathname will be applied automatically.

reader staticl/index/paginated:page-title-fn (paginated-index) (:page-title-fn)

A callback to change page titles.

Accepts single argument - a page number and should return a string.

For example, here is how you can translate page title into a russian:

(paginated-index :target-path #P"ru/"
                 :page-title-fn (lambda (num)
                                  (fmt "Страница ~A" num)))

Functions

function staticl/index/paginated:paginated-index &rest initargs &key target-path page-size template page-title-fn page-filename-fn

STATICL/LINKS/LINK

package staticl/links/link

Classes

LINK

class staticl/links/link:link ()

Readers

reader staticl/links/link:link-content (link) (:content)

Functions

function staticl/links/link:link content

Creates a link to the given content piece.

When such object is passed to the template, it is resolved to a page URL and title.

STATICL/LINKS/PREV-NEXT

package staticl/links/prev-next

Classes

PREV-NEXT-LINKS

class staticl/links/prev-next:prev-next-links ()

Functions

function staticl/links/prev-next:prev-next-links

Creates a links between pages.

STATICL/NAVIGATION

package staticl/navigation

Classes

ITEM

class staticl/navigation:item ()

Readers

reader staticl/navigation:menu-item-title (item) (:title)

reader staticl/navigation:menu-item-url (item) (:url)

MENU

class staticl/navigation:menu ()

Readers

reader staticl/navigation:menu-items (menu) (:items)

Functions

function staticl/navigation:item title url

function staticl/navigation:menu &rest items

STATICL/PIPELINE

package staticl/pipeline

Generics

generic-function staticl/pipeline:process-items site pipeline-node content-items

A method for this generic function should process CONTENT-ITEMS - a list of conten items produced by a previous pipeline nodes.

During the execution, method can call produce-item or remove-item functions to add a new content or to remove some content item.

Functions

function staticl/pipeline:execute-pipeline site

function staticl/pipeline:produce-item item

function staticl/pipeline:remove-item item

STATICL/PLUGIN

package staticl/plugin

Classes

PLUGIN

class staticl/plugin:plugin ()

Functions

function staticl/plugin:make-plugin name &rest initargs

STATICL/RSYNC

package staticl/rsync

Classes

RSYNC

class staticl/rsync:rsync ()

Readers

reader staticl/rsync:rsync-host (rsync) (:host)

Functions

function staticl/rsync:rsync host

STATICL/SITE

package staticl/site

Classes

SITE

class staticl/site:site ()

Readers

reader staticl/site:clean-urls-p (site) (:clean-urls)

Generate some-page/index.html instead of some-page.html to make URLs look like https://my-site.com/some-page/ instead of https://my-site.com/some-page.html

reader staticl/site:site-charset (site) (:charset)

Site's charset. By default it is UTF-8.

reader staticl/site:site-content-root (site) (:root)

A directory pathname where .staticlrc file can be found.

reader staticl/site:site-description (site) (:title)

Site's description.

reader staticl/site:site-navigation (site) (:navigation)

Site's navigation.

reader staticl/site:site-pipeline (site) (:pipeline)

A list of pipline nodes

reader staticl/site:site-theme (site) (:theme)

A theme object for the site.

reader staticl/site:site-title (site) (:title)

Site's title.

reader staticl/site:site-url (site) (:url)

Site's URL.

Functions

function staticl/site:make-site root

function staticl/site:site title &rest args

STATICL/TAG

package staticl/tag

Classes

TAG

class staticl/tag:tag ()

Readers

reader staticl/tag:tag-name (tag) (:name)

STATICL/THEME

package staticl/theme

Classes

THEME

class staticl/theme:theme (print-items-mixin)

Readers

reader staticl/theme:theme-path (theme) (:path)

Generics

generic-function staticl/theme:copy-static theme stage-dir

Copies static files such as CSS, JS, images into the STAGE-DIR.

Usually it is enough to define a method for list-static generic-function.

generic-function staticl/theme:list-static theme

Returns a list of static files such as CSS, JS, images.

Each list item should be a list of two items where first item is an absolute pathname and second is a pathname relative to the root of the site.

generic-function staticl/theme:render theme template-name vars stream

Renders fills template named TEMPLATE-NAME with given VARS and renders into a given STREAM.

  • NAME argument is a string.
  • VARS argument is a hash table with string keys.

generic-function staticl/theme:template-vars site object &key hash

Fills a hash-table given as HASH argument with variables for filling a template.

If hash is NIL, then a new hash-table should be allocated with EQUAL :TEST argument.

Returned hash-table will be used for rendering a template for an OBJECT.

STATICL/URL

package staticl/url

Generics

generic-function staticl/url:object-url site obj &key full &allow-other-keys

Returns a full object URL. A method should return an relative URL, but if case if FULL argument was given, the full url with schema and domain will be returned.

Note a call to this method should happen in a context of the with-base-url macro, because it is always return a path from the site's root even if FULL is not given (in this case return only the path without a domain).

You may wonder: "Why does we bother to return a path without a domain?" It is much easier to service such static site locally for debugging purpose, because you don't have to setup a web server and dns resolver.

Actually you will need to use FULL argument only in a rare case when you really need and absolute URL, for example in an RSS feed.

Macros

macro staticl/url:with-base-url (url) &body body

STATICL/UTILS

package staticl/utils

Functions

function staticl/utils:absolute-url-p url

function staticl/utils:assert-absolute-url url

function staticl/utils:normalize-plist plist &rest normalizers-plist &key &allow-other-keys

Returns a new list where each value is replaced with results of call of normalizing functions.

For example:

CL-USER> (normalize-plist '(:foo "Bar" :blah 123)
                          :foo (lambda (value)
                                 (alexandria:make-keyword (string-upcase value))))
(LIST :FOO :BAR :BLAH 123)

Macros

macro staticl/utils:do-files (filename root-path &key file-type) &body body

For each file under ROOT-PATH, run BODY. If FILE-TYPE is provided, only run BODY on files that match the given extension.


[generated by 40ANTS-DOC]

About

Flexible and customizable static site generator with a lot of plugins!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published