@hyperupcall/ten
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

Ten

Ten will be / is a static site generator / content management system / web framework solution. I created it because:

  • I want my website code to last for decades
    • Frameworks like Hugo, Zola, etc. will eventually go the way of Jekyll
    • Migrating working code is a waste of time
  • It's easier to implement bespoke features

Plans

  • on watch mode:
    • it's VERY useful for debugging output
    • it felt slow and bad because i was using it with browser-sync to serve the generated contents
    • it should now be "re-added" (without browser-sync), and everything will make sense
  • Blog RSS feed and fix tags/categories in dev server
  • Be able to build only certain files/directory matching a glob
  • later: Linter to always ensure trailing slash for local URLs

Introduction

Summary

Ten is a static site generator. Conventionally, it recursively reads input files from content/. Then, it processes each file path and content. Finally, it writes the result path and content to build/.

Content Files

Content files are any files located in the content directory that aren't special.

Transformations are done to file paths in two cases:

  1. If a file ends with .md (or similar) files, it is converted into a .html file.
  • /mathematics.md -> /mathematics.html
  • /index.md -> /index.html
  1. If a file name (excluding file extensions) is the same as the directory name of it's parent directory, then that file is renamed to index.html.
  • /about/about.md -> /about/index.html

This makes it easier to edit files in IDEs (unlike Next.js's page.js).

Supported Formats

The following formats are supported:

HTML, XML

These are processed with the templating engine Handlebars.

Templates have access to the following variables:

  • Page (layouts & partials, pages)
  • Title (layouts & partials, pages)
  • Body (layouts & partials)

Markdown

Markdown files support the following features:

  • Syntax highlighting (via Shiki)
  • Emoji conversion
  • KaTeX

Special File Names

Special file modify behavior and are not processed. They include:

  • *.ten.js

Described further in JavaScript Customization

  • _*

These are ignored.

  • *_

These are ignored.

Website JavaScript Customization

This file potentially customizes the behavior of the whole website. To be recognized, its name must be /ten.config.js.

It can export:

  • defaults
  • transformUri()
  • decideLayout()
  • validateFrontmatter()
  • handlebearsHelpers
  • tenHelpers

Page JavaScript Customization

This file potentially customizes the behavior of a single page. To be recognized, its name must match /**/<adjacentFileName>.ten.js.

It can export:

  • Meta()
  • Head()
  • GenerateSlugMapping()
  • GenerateTemplateVariables()

Directory Structure

Nothing here is out of the ordinary.

build/

Where output files are written to.

content/

User-generated content. There are several variants:

layouts/

Handlebars templates that are applied to all pages and posts. Individual pages and posts can specify a particular template in the frontmatter using the layout property.

partials/

Handlebars partials that can be used in any HTML file.

static/

These assets are copied directly to the build directory without processing.

Older Ideas

Entrypoints. Entrypoints were created to make it easier to approximate tracking dependencies of a page. For example, if /math/theme.cls changed, then probably /math/slides.tex should be regenerated as well. This breaks down too often, as it's not uncommon for files under a particular directory to be unrelated. An alternative to entrypoints was tracking dependencies of a page by parsing the page with either regular expressions or a laguage parser library. This wasn't chosen since it would mean adding regular expressions or traverse functions for each markup language. And, detection would not be posssible with more dynamic markup languages.

Dependencies (14)

Dev Dependencies (1)

Package Sidebar

Install

npm i @hyperupcall/ten

Weekly Downloads

10

Version

0.4.0

License

MPL-2.0

Unpacked Size

70.1 kB

Total Files

18

Last publish

Collaborators

  • hyperupcall