Overview
HastySite is a minimalist but powerful static site generator written in Nim which aims to be fast at processing content and highly configurable to suit your own needs.
Key Features
- Built-in rich markdown support via HastyScribe.
- Built-in mustache support for page templates.
- Limited support for standard CSS variables.
- Fully configurable content and asset processing pipeline, using the min programming language.
- Custom script definition, using the min programming language.
- Default stylesheet and fonts from HastyScribe.
- Default scripts and rules to get started quickly.
- All packed in a single executable file, with no dependencies, available for the most common desktop platforms.
Why HastySite?
HastySite is a static-site generator, similar to hundreds of others. Why bother with yet another one then?
Because HastySite:
- has been designed with minimalism in mind. It does not provide many features on its own, but it can be extended do do almost anything you’d want it to do.
- is only comprised by a single executable file, available pre-compiled for all major desktop platforms, and it can be compiled to run on even more via Nim.
- embeds a concatenative programming language in it, that can be used to customize almost every aspect of it.
- can be extended, from the way it processes files to creating custom commands to do literally what you want.
- provides a simple but functional fully-working site template out-of-the-box, which is also the same template used for its web site.
- provides out-of-the-box Markdown support. But not just any markdown, HastyScribe-compatible markdown, which extends the alredy-amazing and powerful Discount engine with more useful features such as snippets, macros, fields and transclusion.
- provides a robust logic-less templating engine based on mustache.
- provides support for SCSS-like partials and CSS variables, which don’t substitute a full fledged CSS preprocessor like LESS or SASS, but they do help.
Technology and Credits
HastySite has been built leveraging the following open source projects:
- The min programming language.
- The HastyScribe markdown compiler.
- The moustachu mustache template engine.
Special thanks also to the creators and maintainers of the following projects, that made HastySite possible:
- The Nim programming language, used to develop HastySite and all the above-mentioned projects.
- The Discount markdown compiler, used as the basis for HastyScribe.
Sites Using HastySite
HastySite powers the following web sites:
Getting Started
Download
You can download one of the following pre-built HastySite binaries:
Building from Source
Alternatively, you can build HastySite from source as follows:
- Download and install nim.
- Download and build Nifty, and put the nifty executable somewhere in your $PATH.
- Clone the HastySite repository.
- Navigate to the HastySite repository local folder.
- Run the following command to download HastySite’s dependencies.
nifty install
- Run the following command to compile HastySite:
nim c -d:release hastysite.nim
Tip
You should put the compiled HastySite executable somewhere in yout $PATH.
Running HastySite
To create a new site, run the following command in an empty directory:
hastysite init
This will create the following default directory structure:
- assets/ — Your site assets
- fonts/
- styles/
- contents/ — Your site contents.
- output/ — Your static web site.
- rules.min — Rules to process your contents and assets.
- scripts/ — Scripts to manage your site.
- settings.json — Your site configuration.
- temp/ — Temporary files and folders will be placed here.
- templates/ — Mustache templates.
Tip
Default folder paths can be configured in your settings.json file.
Then, create your first page by running the following command and specifying the page ID and Title:
hastysite page ID: home Title: Home Page ----- id: home title: "Home Page" content-type: page ----- Create page? [yes/no]: y
Finally, run the following command to generate your site contents (just an empty home page for now) and copy the default assets.
hastysite build Preprocessing... Processing rules... - Writing file: output/index.html - Copying: assets/fonts/SourceSansPro-Regular.woff -> output/fonts/SourceSansPro-Regular.woff - Copying: assets/fonts/SourceSansPro-It.woff -> output/fonts/SourceSansPro-It.woff - Copying: assets/fonts/fontawesome-webfont.woff -> output/fonts/fontawesome-webfont.woff - Copying: assets/fonts/SourceCodePro-Regular.woff -> output/fonts/SourceCodePro-Regular.woff - Copying: assets/fonts/SourceSansPro-Bold.woff -> output/fonts/SourceSansPro-Bold.woff - Copying: assets/fonts/SourceSansPro-BoldIt.woff -> output/fonts/SourceSansPro-BoldIt.woff - Writing file: output/styles/hastysite.css - Writing file: output/styles/site.css - Writing file: output/styles/luxbar.css - Writing file: output/styles/hastyscribe.css - Writing file: output/styles/fonts.css Postprocessing... All done.
That’s it! You can view the result by serving the output directory from any web server.
Usage
HastySite is a simple command-line program that supports some default commands and options, described in the following sections.
Syntax
hastysite command [ options ]
Default Commands
The following sections define the default commands provided by HastySite. All of them except for init can be modified, and you can also configure your own commands by creating your own min scripts and placing them in the scripts directory.
build
Builds the site by preprocessing contents and assets, processing rules defined in the rules.min file, and creating a temporary file containing the checksums of all newly-generated files. By doing so, the next time this command is executed, only the files that have actually been modified will be copied to the output directory.
The rules.min file processed by this command:
- Ignores contents and assets starting with . or _.
- Pre-processes CSS variables in all .css files.
- Processes text as HastyScribe-compatible Markdown in all .md content files.
- Associates contents to mustache templates based on the value of the content-type metadata property.
- Copies each asset file “as-is” to the output directory, respecting the source directory structure in the asset directory.
- Copies each content file to a directory within the output named after the source content ID, in an index.html file (to easily obtain “pretty URLs” ending with no extension).
Note
This command can be customized by modifying the scripts/build.min file within your site directory.
clean
Deletes all files and directories in the output and temp directories.
Note
This command can be customized by modifying the scripts/clean.min file within your site directory.
init
Initializes a new HastySite site directory, by creating the following directory structure:
- assets/ — Your site assets
- fonts/
- styles/
- contents/ — Your site contents.
- output/ — Your static web site.
- rules.min — Rules to process your contents and assets.
- scripts/ — Scripts to manage your site.
- settings.json — Your site configuration.
- temp/ — Temporary files and folders will be placed here.
- templates/ — Mustache templates.
Tip
Default folder paths can be configured in your settings.json file.
page
Generates an empty page content file containing initial metadata. This command asks the user for the following information:
- A valid ID composed only by letters, numbers, and dashes that has not yet been used for another page.
- The title of the page.
After information has been provided, a new content will be created in the contents directory containing the following metadata properties:
- id
- title
- content-type (set to page)
Note
This command can be customized by modifying the scripts/page.min file within your site directory.
post
Generates an empty post content file containing initial metadata. This command asks the user for the following information:
- A valid ID composed only by letters, numbers, and dashes that has not yet been used for another post.
- The title of the post.
After information has been provided, a new content will be created in the contents/posts directory containing the following metadata properties:
- id
- title
- content-type (set to post)
- timestamp (set to the Unix timestamp of the creation of the content)
- data (set to a date string corresponding to the creation of the content)
Note
This command can be customized by modifying the scripts/post.min file within your site directory.
Options
By default, HastySite provides the following options to display information about the program or alter its behavior.
-h, --help
Displays the description of all HastySite commands and options.
-l=level, --loglevel=level
Sets the log level to one the following values:
- debug
- info
- notice (default)
- warn
- error
- fatal
-v, --version
Displays the HastySite version string.
Customization
By default, HastySite provide all the scripts and rules necessary to build a simple blog with static pages and timestamped blog posts. While this may work for a simple blogging site, you may need additional features like support for tags, or maybe group articles by months, or project pages with custom metadata, and so on.
HastySite can be customized to your heart content essentially in the following ways:
- By modifying the rules.min file and tweak the build pipeline.
- By creating custom scripts to create generators for custom content types, or any other task you deem useful for your use case.
- By leveraging HastyScribe advanced features for content reuse, like snippets, fields, macros, and transclusions.
Default Build Pipeline
Before diving into customization techniques, you should be familiar with the way HastySite builds your site out-of-the-box. If you have a look at the scripts/build.min file, it looks like this:
;Builds a site by processing contents and assets.
'hastysite import
"Preprocessing..." notice
preprocess
"Processing rules..." notice
process-rules
"Postprocessing..." notice
postprocess
"All done." notice
Even if you are not familiar with the min programming language, this code looks straightforward enough. as part of the build process, three actions are performed:
- preprocess
- process-rules
- post-process
Preprocess
During this phase, the following operations are performed:
- Some maintenance of temporary files is performed, e.g. the temp directory is created and populated with a checksums.json file if needed, temporary contents from the previous build are deleted, and so on.
- All contents are loaded, and metadata in the content header is processed and saved in memory.
- All assets are loaded and bare-bones metadata is generated for them and saved in memory, as they have no header.
If you are wondering what this content header is, it’s a section at the start of a content file delimited by five dashes, and containing metadata properties, like this:
-----
id: getting-started
title: "Getting Started"
content-type: page
-----
Now, this looks like YAML, but it is actually Nim’s own configuration file format, which is a bit more limited, but it does the job. Just remember to wrap strings with spaces in double quotes and everything will be good.
Internally, after the preprocessing phase all contents and assets will have the following metadata:
- id
- An identifier for the content or asset, corresponding to the path to the file relative to the contents or assets folder, without extension.
- path
- The path to the file relative to the contents or assets folder, including extension.
- type
- Either content or asset.
- ext
- The file extension (including the leading .).
Process Rules
In this phase, the control of the build process is passed to the rules.min script. It is important to point out that in case of an empty rules.min file, nothing will be done and no output file will be generated.
Luckily, a default rules.min file is provided, which:
- Ignores contents and assets starting with . or _.
- Pre-processes CSS variables in all .css files.
- Processes text as HastyScribe-compatible Markdown in all .md content files.
- Associates contents to mustache templates based on the value of the content-type metadata property.
- Copies each asset file “as-is” to the output directory, respecting the source directory structure in the asset directory.
- Copies each content file to a directory within the output named after the source content ID, in an index.html file (to easily obtain “pretty URLs” ending with no extension).
Typically, you only need to modify this file to change how HastySite builds your site.
Postprocess
In this phase, the temp/checksums.json is updated with the latest checksums of the generated output files.
Modifying the rules.min File
The rules.min file is used to build your site. This file is nothing but a min script, and therefore you should have at least a basic understanding of the min programming language before diving in and modifying it.
In particular, you should get acquainted with the following min modules, whose symbols and sigils are typically used to create rules.min files:
Additionally, a dedicated hastysite module is also provided specifically for HastySite, which is described in the Reference section.
Creating Commands
Once you are comfortable with witing min scripts and maybe after you modified the rules.min file, you could try modifying or adding new HastySite commands. To do so, you must:
- Create a new .min file named after your command (e.g. project.min) and place it in the scripts folder of your site.
- On the first line, enter a min comment corresponding to the description of your command. This description will be used by HastySite help system.
- On the subsequent lines, write the logic of your command in min.
For more information and examples, have a look at the default scripts generated by the hastysite init command.
Leveraging HastyScribe Advanced Features
In some cases, you may not even need to edit .min files to customize the way your site pages are rendered. In particular, HastyScribe, the Markdown engine that powers HastySite, provide a lot of extra feature aimed at improving content reuse, such as:
- Transclusion, to basically load the contents of a Markdown file into another.
- Snippets, to reuse chunks of text in the same file (and transcluded files).
- Fields, to specify things like current date and time, but also custom properties defined at run time.
- Macros, to create chunks of reusable text with placeholders.
Reference
This section provides some reference information related to the default metadata of contents and assets, as well as the full documentation of the hastysite min Module.
Default Content and Asset Metadata
The following table lists all the default metadata properties available for contents and assets, and also after which build phase they become available.
Note
You can define your own custom metadata for contents in a header section delimited by five dashes, at the start of each content file.
Property | Content | Asset |
---|---|---|
id | ||
path | ||
ext | ||
type | ||
title | ^1 | |
content-type | ^1 | |
date | ^(1,2) | |
timestamp | ^(1,2) | |
contents | ^3 | ^3 |
- 1 This property is defined for all page and post contents created using the default page and post commands.
- 2 This property is defined for all post contents created using the default post command.
- 3 This property must be added to contents and assets before they can be written to the output folder. This can be done implicitly using symbols provided with the hastysite min module.
hastysite min Module
This min module can be imported in the rules.min file or in any script file and can be used to perform common operations such as ready and writing files, and interact with HastySite data at build time.
assets
∅ ⇒ (meta*)
Returns a quotation of metadata dictionaries (meta*) containing the metadata of each asset file.
clean-output
∅ ⇒ ∅
Deletes all the contents of the output directory.
clean-temp
∅ ⇒ ∅
Deletes all the contents of the temp directory.
contents
∅ ⇒ (meta*)
Returns a quotation of metadata dictionaries (meta*) containing the metadata of each content file.
input-fread
meta ⇒ string
Reads the contents of the file identified by the metadata dictionary meta (such as those returned by the contents and assets parameters).
Note that:
- The source directory is determined by the value of the type metadata property.
- The path within the source directory is determined by the value of the path metadata property.
markdown
string1 dict ⇒ string2
Converts the HastyScribe Markdown string string1 into the HTML fragment string2, using the properties of dict as custom fields (accessible therefore via HastyScribe’s {{$<field-name>}} syntax).
mustache
string1 dict ⇒ string2
Renders mustache template string1 into string2, using dictionary dict as context.
Note
string1 is the path to the mustache template file, relative to the templates directory and without .mustache.
output
∅ ⇒ string
Returns the full path to the output directory.
output-cp
meta ⇒ ∅
Copies a file from the source directory (contents or assets depending on its type) to the output directory.
Note that:
- The source directory is determined by the value of the type metadata property.
- The path within the source directory is determined by the value of the path metadata property.
- The destination path within the output directory is determined by the value of concatenation of the id and ext metadata properties.
- The contents of the file are retrieved from the contents metadata property (in case of contents) or the contents of the original file (in case of assets).
output-fwrite
meta ⇒ ∅
Writes the contents of the file identified by the metadata dictionary meta (such as those returned by the contents and assets parameters).
Note that:
- The destination path within the output directory is determined by the value of concatenation of the id and ext metadata properties.
- The contents of the file are retrieved from the contents metadata property (in case of contents) or the contents of the original file (in case of assets).
postprocess
∅ ⇒ ∅
Starts the postprocessing phase of the build.
preprocess
∅ ⇒ ∅
Starts the preprocessing phase of the build.
preprocess-css
string1 ⇒ string2
Pre-process CSS contents within string1, i.e.:
- Pseudo-SCSS partial imports. Partial CSS files must start with an underscore and be placed in the
css-partials
directory (set in your settings.json, or assets/styles if not specified). - CSS variable declarations
Returns the resulting CSS code string2.
For example, the following CSS code in two different files:
- _vars.css:
:root { --standard-gray: #cccccc; }
- style.css:
@import 'vars'; .note { background-color: var(--standard-gray); }
Will be converted into the following:
:root {
--standard-gray: #cccccc;
}
.note {
background-color: #cccccc;
}
Limitation
Only basic support for CSS variables is provided, e.g. no fallback values are supported.
process-rules
∅ ⇒ ∅
Starts the processing phase of the build, and interprets the rules.min file.
settings
∅ ⇒ dict
Returns a dictionary dict containing all the settings defined in the settings.json file.
Changelog
v1.3.9
- Updated HastyScribe 2.0.0.
- Now using nim-mustache for Mustache processing.
- Simplified installation.
v1.3.8
- Updated min to v0.39.1
- Updated HastyScribe to v1.12.5
- Compiled with Nim v2.0.0
v1.3.7
- Updated min to v0.35.1
- Updated HastyScribe to v1.12.4
- Compiled with Nim v1.4.6
v1.3.6
- Updated min to v0.35.0 (contains breaking changes to scripts and rules syntax)
- Compiled with Nim v1.4.4
v1.3.5
- Updated to min v0.21.1
- Updated to hastyscribe v1.12.2
- Fixed post/clean scripts
- Compiled with Nim v.1.4.0
v1.3.4
- Fixed Linux cross-compilation
- Updated to min v0.20.1
- Updated to hastyscribe v1.12.1
v1.3.3
- Fixed cross-compilation error.
v1.3.2
- Fixed processing of metadata fields.
- Upgraded to min v0.19.5.
- Tested on Nim v1.0.0
v1.3.1
- Upgraded min to v0.19.4; tested on Nim v0.20.2.
v1.3.0
- Implemented basic support for SCSS-like partial imports.
v1.2.2
- Upgraded to min v0.19.2
- Upgraded to HastyScribe v1.11.0
v1.2.1
- Upgraded to min v0.19.0.
v1.2.0
- Upgraded HastyScribe to v1.10.0.
- Upgraded min to v0.15.2.
- Improved stylesheet.
v1.1.0
- Upgraded HastyScribe to v1.8.0.
- Upgraded min to v0.15.0.
- Fixed compilation warnings with Nim 0.18.0.
- Now including Font Awesome 5.
v1.0.1
Just a bugfix release, containing minor fixes to the default CSS stylesheet, and upgrades to HastyScribe v1.7.1 and min v0.13.0.
v1.0.0
This is the first public release of HastySite. There are not many things changed compared to the previous release, except for the brand new HastySite web site available at https://hastysite.h3rald.com.
The contents of the site are also available in a standalone HTML document, here.
v0.1.0
The first internal release of HastySite is out and available on Github. This is intented to be only an internal pre-release, but as a matter of fact everything works as expected.
This first release has already been tested in production on the following web sites: