Skip to main content

A modular static site generator in Python

Project description

Markupdown

Markupdown is a dead-simple static site generator. You write a build.py file that calls Markupdown commands and run it. Here's what a build.py file looks like:

#!/usr/bin/env python3

from markupdown import *

# Copy files to the site directory
cp("assets/css/*.css", "site/css")
cp("assets/js/*.js", "site/js")
cp("assets/images/*.[jpg|jpeg|png]", "site/images")
cp("*.ico", "site")
cp("pages/**/*.md", "site")

# Update markdown frontmatter
title("site/**/*.md")
siblings("site/**/index.md")
children("site/**/index.md")
changelog("site/**/*.md")
transform("site/**/*.md", lambda md, _: md.frontmatter().pop("source", None))

# Render pages
render("site/**/*.md", site={"title": "My Site"})

Commands like title and index just scan a directory to create, update, or delete markdown files. title, for example, adds a title field to each matching markdown file's frontmatter.

Commands

Markupdown ships with the following commands:

  • changelog: Updates the created_at, updated_at, and change_log fields in markdown frontmatter
  • cp: Copies files to the site directory
  • transform: Applies a transformation function to the frontmatter in markdown files
  • siblings: Generates siblings frontmatter for sibling markdown files
  • children: Generates children frontmatter for child directories with index.md files
  • init: Initializes a new site
  • ls: Lists files in the site directory
  • render: Renders the markdown using liquid templates
  • serve: Starts a local HTTP server to view the site
  • title: Updates the title field in the markdown frontmatter
  • feed: Generates an RSS and Atom feeds

I'll probably add more (e.g. sitemap, minify, social). It's a work in progress.

Installation

pip install markupdown

Markupdown is compatible with Python 3.10 to 3.12

Usage

After you install Markupdown, go to an empty directory and initialize it:

python -m markupdown init

This will create a scaffolding with files and directories like this:

.
├── css
│   └── style.css
├── img
│   └── image.png
├── pages
│   ├── index.md
│   └── posts
│       ├── index.md
│       ├── post1.md
│       └── post2.md
├── templates
│   ├── _footer_.liquid
│   ├── _head_.liquid
│   ├── _header_.liquid
│   ├── _pages_.liquid
│   └── default.liquid
├── .gitignore
└── build.py

Run ./build.py to generate your site. The output will be in the site directory.

Markupdown comes with a server you can start with:

python -m markupdown serve

Open http://localhost:8000. You should see a (rather ugly) stub site.

You can clean your site directory with:

python -m markupdown clean

Philosophy

Markupdown is designed to be pretty dumb. It's just a collection of functions that help you do three things:

  • Stage your site directory with markdown, css, js, images, and so forth (using cp)
  • Transform the files in site to add metadata or create new files (using title, index, nav, etc.)
  • Render the markdown using liquid templates (using render)

That's it. Stupid simple. Worse is better.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markupdown-0.2.1.tar.gz (68.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markupdown-0.2.1-py3-none-any.whl (76.3 kB view details)

Uploaded Python 3

File details

Details for the file markupdown-0.2.1.tar.gz.

File metadata

  • Download URL: markupdown-0.2.1.tar.gz
  • Upload date:
  • Size: 68.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.22.3 CPython/3.12.3 Linux/6.8.0-1020-azure

File hashes

Hashes for markupdown-0.2.1.tar.gz
Algorithm Hash digest
SHA256 52a97a637e5628b590210e84fe5066a6f6c16f2824644d238cf06d7e0e625180
MD5 3de08b87af8a84e3a7f1cd624e4510ea
BLAKE2b-256 c5ca4f255baf29d7a18a4fcb1ae2bc44481a8e09528cd53a85600eb5ece19dc0

See more details on using hashes here.

File details

Details for the file markupdown-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: markupdown-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 76.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.22.3 CPython/3.12.3 Linux/6.8.0-1020-azure

File hashes

Hashes for markupdown-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ccc61d23ff006f9af93f072ed123c87e2ac5fe19aac968dd98e714e49b15d6e
MD5 2df494183c3246ce38a0850e9d0c1c86
BLAKE2b-256 0b7d920b5108e68a3828af2fbf2e8db15715e95d3c55f02bb9b383d1fb950fa3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page