Software & Apps

mna/trofaf: Super simple live static blog generator in Go. Recognition of the trophy.

Trofaf is super-simple LIVE static blog engine.

Install with: go get github.com/PuerkitoBio/trofaf

It creates a static website from markdown files and front object, and only requires a simple 3-directory structure to proceed. It favors simplicity over features.

To get started, create 3 subdirectories (you can view the example/ subdirectory for… an example):

only the trophy will be taken care of *.md files in the posts directory, and about *.amber (Amber templates) or *.html (native Go templates) files in the templates directory. It will watch for changes, creation or deletion of files in these directories, and automatically recreate the website if necessary. This is LIVE part.

All files in the public directory are exposed to the web server. Posts in markdown format will be translated into static html files in the root of the public directory. The html file name is a URL-friendly slug generated from the original markdown file name. No extension, so the URL looks clean and, uh, modern?

An RSS feed is automatically generated from many new posts, and stored as a static XML file in the public directory.

There is no special template for an index page, the most recent post (based on the publication date found in the front item of the markdown files) is stored twice – once under its own html file, once under index.html file, so this is the page that is displayed when the root of the web server is requested.

When the site (again) is created, the public directory should be cleaned, because some posts may have been deleted. Subdirectories are left untouched (so css/ or js/ Directories can coexist peacefully), as well as hidden (dot) files, and some special files are also decorated from destruction (robots.txt, favicon.ico, etc., see gen.go).

It is currently using my fork in the amber package, to make a fmttime(t time.Time, fmt string) string functions available in templates. This function makes it possible to format the PubTime or ModTime fields in the same way that stdlib’s time.Format() works. This function is also made available in native Go templates (you can check the examples for usage).

The following options can be set on the command-line:

  • Port (-p): the port number for the web server, default to 9000.
  • GenOnly (-g): generate static site and exit.
  • NoGen (-G): disables viewing and live-generating on the site. This is equivalent to running a static public directory.
  • SiteName (-n): the name of the web site, passed to the template.
  • TagLine (-t): a tag line for the web site, passed to the template.
  • RecentPostsCount (-r) : the number of posts in the recent posts list, passed to the template and used for the RSS feed.
  • BaseURL (-b): the base URL of the web site, possibly the host name (ie http://www.mysite.com).

Like many static blog generators, trofaf is used YAML front object to get metadata for a post. This is a complicated way of saying that you should add blocks of text like this to the beginning of your posts:

---
Title: My title
Description: My short-ish description of the post.
Author: Me
Date: 2013-07-14
Lang: en
---

# Here is my post!

Etc.

Three dashes delimit the front object. It must be there, beginning and end. Between the dashes, the front part of the colon : is the key, and after that is the value. Simple as that. Title, Description, Author, Date and Lang identified. Valid date formats are 2006-01-02, 2006-01-02 15h (or 2006-01-02 8h), 2006-01-02 15:04 (or 2006-01-02 8:17) or the RCF3339 format (2013-08-06T17:48:01-05:00).

the BSD 3-Clause License.


https://opengraph.githubassets.com/d571c45a7863a881058c5134d300a66943f39aefb54115de15d2d725f91d7390/mna/trofaf

2024-12-17 22:43:10

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button