Giter Site home page Giter Site logo

duckwork / unk Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 1.15 MB

a very small static site generator (mirror of https://git.sr.ht/~acdw/unk)

Home Page: https://tilde.town/~acdw/unk/

License: Do What The F*ck You Want To Public License

Awk 48.79% Shell 51.21%
posix-sh ssg minimal awk

unk's Introduction

UNK

a very small static site generator

UNK is an experiment in minimalism. It is a templating static site generator with an included markup language that all fits within 1000 bytes. There are three main scripts:

  • UNK (253 bytes), a POSIX-sh script that applies the template to each page and publishes them to the output dir,
  • LHT (241 bytes), an awk script that serves as a (very) basic markup language, and
  • TM (502 bytes), the default template script for UNK.

You are, of course, free to make the template file as large and involved as you like, but it's pretty good already:

  • it has a plain default CSS (based on this article), or will use S/s.css if it exists
  • it automatically adds a list of posts to the index page, or a link to other pages
  • it cleans up the first line of the input file and makes it a <title>, and a <h1> in the generated HTML

INSTALLING & RUNNING

OFFICIAL REPO // GITHUB MIRROR

To install UNK, simply clone this repo and put it where you want it. The default TM needs LHT to be in the same directory as it, so keep that in mind.

To run UNK, just cd into your cloned repo and run ./unk. It's just a POSIX shell script.

DETAILS

unk

UNK takes a set of files in a directory, applies a template to them, and output them into another directory as HTML files ready for a server. To keep a very small size, UNK delegates most file processing to TM, the main template. It delegates by using an idea found in shab: each input file is read as a heredoc, which enables shell interpolation. So the template, as opposed to the engine, can do all the heavy-lifting of index generation and navigation and such.

Content goes into the following (hard-coded) directories:

  • I/, for written (Input) content (the pages of the site),
  • S/, for Static content (css, images, etc.), &
  • O/, for the (Output) website, ready for rsyncing to a server.

If there is no TM in the directory where UNK is run, one will be created that will simply cat the file being processed.

The following variable is made available to TM:

  • F: the File name passed to TM
  • N: the fileName (with directories removed) of the file being processed

as well as these functions:

  • X, for eXpand: the shab stand-in. It is much simpler than shab, and will fail if the template (or if it nests templates, one of the nested ones) has a ZZ on a line by itself, due to its heredoc nature.
  • T, for Title: it'll return the first line of the current file.
  • B, for Body: it'll return all lines *but* the first of the current file.

and these aliases (though they're more an artefact of saving space in the script, but they can be used in templates):

  • c: cat
  • q: test
  • e: echo

As mentioned above, templates can be nested. Simply call another template from TM with the X function.

lht

LHT stands for Less HyperText, because that's what you're writing when you're writing it (though not much less than HTML). Basically, blank lines are interpreted as <p> tag breaks, unless the previous source paragraph started with < and ended with >. It also has support for three inline spans:

  • *em* as em
  • __strong__ as strong
  • `code` as code

Everything else is just HTML. This means that a valid .lh file is almost a valid .md file, except where it nests HTML and Markdown (so it's not really, but you can run it through Markdown in a pinch and get the basic idea across. This file, for example, is both index.lh and README.md (they're just symlinked to each other), so it's got some weirdness to keep things compatible between Markdown and LHT. But if you're just writing for LHT, it can be much simpler.).

LHT was inspired, in part, by Writing HTML in HTML by John Ankarstrom, as well as some other articles I can't think of right now. I liked the idea, but some tags in HTML are just annoying to write over and over, and take me out of the flow of writing prose. So I fixed those few tags. The inline tags are definitely subject to change.

Why?

I was bored and decided I'd try to write a static site generator that could fit in a toot (500 characters). I wrote a few of them, making them smaller and smaller each time. By the end, I was left with a tiny script that delegated almost all the work to the template file. That script became UNK in this repo.

I was feeling pretty high on my horse after writing the tiny SSG, so I thought, maybe I could try for a tootable Markdown converter next โ€” boy, was I wrong about that. Markdown is way too complicated to fit in 500 bytes. So I just wrote the Really Important Parts: <p> and some inlines.

LEGAL

Copyright ยฉ 2019 Case Duckworth <[email protected]>.

This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the LICENSE file for more details.

Why this license?

I was going to go with a stricter license like the GPL, but realized that

  1. this software isn't so important or time-consuming that I need others to credit me or redistribute the project under the same terms, and
  2. the GPL is way too long for a project like this. It's over 35 times bigger than the entirety of this project, not counting the content or this README. It would weigh down the entire undertaking. The WTFPL, by contrast, is a trim 443 characters, which is right in keeping with the smallness of this project.

CONTRIBUTING

To contribute to this project, head over to its GitHub mirror and send me a pull request or issue. One of these days, I'm sure I'll figure out sr.ht's mailing lists, Meme of Aragorn saying, 'But it is not this day'

unk's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tekknolagi

unk's Issues

Project website HTML broken

I haven't looked at any of your code, so I'm not sure if that's an issue in your code or just the project website, but I noticed the website was loading quite slow. Looking at the source code, there are no html, body and head tags. Also it has a repetitive <h1> tag.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.