Crates.io | slsg |
lib.rs | slsg |
version | 0.1.0 |
source | src |
created_at | 2024-04-13 20:13:29.2402 |
updated_at | 2024-04-13 20:13:29.2402 |
description | Scriptable Lua Site Generator |
homepage | |
repository | https://github.com/Dimev/slsg |
max_upload_size | |
id | 1207796 |
size | 1,124,263 |
Scriptable Lua Site Generator
lssg new [name]
to initialize a new project. This will create a directory with that name,
a site.toml
file, the content directory, style, static and lib directory
lssg init
initializes the current directory as a new site, if it's empty
site/
is for the site, lib/
is for lua scripts, styles/
is for sass stylesheets,
static/
is for statically accessible files
The completed website is output to public/
, or the folder specified by -o
or --output
lssg build
builds the site by looking at the first found site.toml
file in the current or any ancestor directories.
lssg cookbook [name]
shows a script that may be useful when making a site. Run without name to see the full list.
lssg runs the site/index.lua
file, which is expected to return a page
this page is then converted into a website
The final returned item of this script is expected to be a page
index.lua
, as well as all other scripts found in site/
or subdirectories get access to a global named script
.
This serves as the main way to interact with the file system
They also get access to the config
table, which is loaded from site.toml
script
:
colocated
: directory
for the colocated files, if this was an index.lua
file, otherwise an empty directoryname
: stem of the *.lua
file, or directory name if index.lua
static
: directory
for the static filesstyles
: return table of file
s, for the styledirectory
:
files
: table for all colocated filesdirectories
: table for all colocated directoriesscripts
: table for all colocated scripts (*.lua
, or ./index.lua
)file
:
site.file(text)
functionparseMd()
: parses the file as markdownparseJson()
: parses the file as json, into a tableparseYaml()
: parses the file as yaml, into a tableparseToml()
: parses the file as toml, into a tableparseTxt()
: loads the file as a stringparseBibtex()
: loads the file as bibtex, into a tablestem
: file stem if any, or nilname
: file name if any, or nilextention
: file extention if any, or nilmarkdown
:
front()
: the front matter as a table, or nil if none. --- is parsed as yaml, +++ is parsed as tomlraw
: the raw markdown texthtml(flow)
: the markdown as html, accepts a bool for whether to allow mdx flow, as in text between {} to be interpreted speciallyast(flow)
: the markdown as the ast (table), accepts a bool for whether to allow mdx flow, as in text between {} to be interpreted specially
See the cookbook page on markdown for more details on how to use thispage
:
page(name)
functionwithFile(path, file)
: adds a file at the given relative pathwithHtml(html)
: adds html to the page. If no html is used, no index.html file is generated for the directorywithPage(page)
: adds a subpage to the pagewarn
: Accepts a single string, warnings will be shown in the terminal and error pagesite.debug
: bool, true if the site is built from the serve
commandescapeHtml
: escapes the given html stringBesides including these page and file searching functions,
there's also a small library for rendering html
This is available under the h table, as well as with the fragment and rawHtml functions
h
contains all elements as functions, with the sub()
method allowing child nodes to be added, one per argument,
and attrs()
accepting a table of the attributes to set on the element
renderHtml()
will render the given nodes to a string of html
render()
will do the same, but exclude the initial "<!DOCTYPE html>"
TODO
Static content under the static/
folder is not included by default,
and has to be added manually via withFile
on page
all content under the styles
folder is interpreted as css, scss or sass, depending on the extention
all top-level at the root of the directory is available under the styles
all html passed in via withHtml is minified, as well as all stylesheets under style/
the minifyhtml
, minifycss
and minifyjs
functions can be used to minify html, css and javascript respectively
TODO
the site.toml
file can be used for configuring.
everything under the [config]
section is loaded into the config
global