• Stars
    star
    112
  • Rank 312,240 (Top 7 %)
  • Language
    JavaScript
  • Created about 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A super simple static site generator

Teeny: A simple static site generator

โš ๏ธ Disclaimer: This is a tool I built in a couple of hours to generate my personal blog yakkomajuri.github.io. It doesn't do much right now and probably won't ever.

๐Ÿƒ Quick start

npm i -g teeny-cli # yarn global add teeny-cli
teeny init && teeny develop

For an example of a project using Teeny, check out my personal blog's repo.

๐Ÿ“– Backstory

You can read about my motivation for building Teeny on this blog post titled "Why I built my own static site generator".

๐Ÿ’ป Supported commands

Initialize a Teeny project in the current directory

teeny init

Build the static HTML files and add them to public/

teeny build

Start a local Teeny server that listens for file changes

teeny develop

๐Ÿ“„ How it works

Teeny is a super simple static site generator built to suit my needs and my needs only.

All it does is generate pages based on HTML templates and Markdown content.

It does very little and is strongly opinionated (read: I was too lazy to build customization/conditional handlers), but has allowed me to build a blog I'm happy with extremely quickly.

Essentially, there are really only 2 concepts you need to think about: templates and pages.

Templates

Templates are plain HTML and should be added to a templates/ subdirectory.

They can contain an element with the id page-content, which is where Teeny adds the HTML generated by parsing the Markdown content.

Pages

Markdown is a first-class citizen in Teeny, so all of your website's pages are defined by a Markdown file.

The file need not have any actual content though, so if you want a page to be defined purely in HTML you just need to create a template that is referenced from a page file.

To specify what template a page should use, you can specify it in the frontmatter of the page, like so:

---
template: blog
---

In the above example, Teeny will look for a template called blog.html. If no template is specified, Teeny looks for a default.html file in templates/ and uses that.

๐Ÿ’ก Example usage

Here's an example of Teeny at work.

To start a Teeny project, run teeny init. This will create the following in your current directory:

.
โ”œโ”€โ”€ pages
โ”‚ย ย  โ””โ”€โ”€ index.md
โ”œโ”€โ”€ static
โ”‚ย ย  โ””โ”€โ”€ main.js
โ””โ”€โ”€ templates
    โ”œโ”€โ”€ default.html
    โ””โ”€โ”€ homepage.html

If you then run teeny build, you'll end up with this:

.
โ”œโ”€โ”€ pages
โ”‚ย ย  โ””โ”€โ”€ index.md
โ”œโ”€โ”€ public
โ”‚ย ย  โ”œโ”€โ”€ index.html
โ”‚ย ย  โ””โ”€โ”€ main.js
โ”œโ”€โ”€ static
โ”‚ย ย  โ””โ”€โ”€ main.js
โ””โ”€โ”€ templates
    โ”œโ”€โ”€ default.html
    โ””โ”€โ”€ homepage.html

index.md uses the homepage template, and together they generate index.html. As is standard with other SSGs, static files are served from public/.

You'll also notice main.js got moved to public/ too. Teeny will actually take all non-template and non-page files from pages/, templates/, and static/ and copy them to public/, following the same structure from the origin directory.

The reason for this is that I actually didn't want to have "magic" imports, where you have to import static assets from paths that do not correspond to the actual directory structure. As a result, I decided that static files would just live inside templates/ and pages/ as necessary.

Later I did surrender to the static/ directory approach though, as there may be assets both pages and templates want to use. Imports from static/ are "magic", meaning you need to think about the output of teeny build for them to work.

The last command that Teeny supports is teeny develop. This creates an HTTP server to server files from the public/ subdirectory.

It listens for changes to the files and updates the static files on the fly (naively, by just rebuilding everything each time it detects a change).

๐Ÿ”ฎ Potential future improvements

I want to keep Teeny as tiny as possible. I deliberately put all the code in one file as a reminder to myself that this is supposed to just be a simple tool for me to build simple static blogs quickly.

However, it could use a few "developer experience" upgrades, like an optimized approach to teeny develop instead of naively rebuilding everything, as well as some better customization options.

More Repositories

1

react-from-scratch

Building a Modern React App from Scratch in 2021
TypeScript
147
star
2

brython-snake

A web snake game built 100% with Python for the browser.
HTML
35
star
3

medium-to-blog

Turn your Medium posts into a Gatsby blog in 5 minutes with one command.
JavaScript
14
star
4

linkedin-adblocker

JavaScript
10
star
5

fibonacci-benchmark

Comparing execution speed of fibonacci() in C, Nim, Go, and Python
C
8
star
6

privacy-initiative

A (hopefully) community-maintained repo for all things privacy & online security
5
star
7

structlog

A lightweight structured logging tool for Node.js without any dependencies.
TypeScript
5
star
8

lang

Python
4
star
9

vaccines-eth

A website to display my vaccination records registered on Ethereum's mainnet
HTML
4
star
10

certfy.me

Source code for Certfy.me dApp.
CSS
3
star
11

yakkomajuri.github.io

HTML
2
star
12

smart-contract-series

All code displayed during the "Smart Contracts" series, published in Portuguese on Medium. | Todo o cรณdigo passado na sรฉrie "Smart Contracts", publicada no Medium.
HTML
2
star
13

favorite-syntax

1
star
14

certfy-me

My Final Project for the ConsenSys Ethereum Developer Bootcamp. Grade: 100%
CSS
1
star
15

solidity

Smart contracts
Solidity
1
star
16

exposed-git

All the code addressed in the tutorial "Learning the internals of Git by hacking websites".
PHP
1
star
17

coursework-website

A website to help students with their coursework.
HTML
1
star
18

leavemealone-extension

A browser extension to alert you if you're entering a malicious website
JavaScript
1
star
19

mlflow_custom_headers_plugin

Python
1
star