Skip to main content

A modular static site generator in Python

Project description

Markupdown

Markupdown is a collection of functions that help you build static sites with markdown.

Many static site generators are complex, rigid, and rely on plugins for extensibility. Markupdown is the opposite: it's dumb but programmable. It's kind of like a build system for static sites. A typical flow looks like this:

  • Stage your site directory with markdown, CSS, Javascript, images, and so forth (using cp)
  • Transform your files to add metadata to the frontmatter (using functions like title, link, blurb, and so on)
  • Render the markdown with Liquid templates (using render)

You can call Markdown's functions any way you like, but I recommend creating a little build.py file in your project root:

#!/usr/bin/env python3
from markupdown import *

# Copy files to the site directory
cp("assets/**/*.*", "site")
cp("content/**/*.md", "site")

# Update markdown frontmatter
title("site/**/*.md")
link("site/**/*.md")
blurb("site/**/*.md")
siblings("site/**/index.md")
children("site/**/index.md")
changelog("content/**/*.md", "site")
sitemap("site/**/*.md", site_url="http://example.com")

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

# Minify site HTML, CSS, and JS
minify("site/**/*.html")
minify("site/**/*.css")
minify("site/**/*.js")

Functions

Markupdown ships with the following functions:

  • blurb: Updates the blurb field in markdown frontmatter to include a brief summary
  • changelog: Updates the created_at, updated_at, and change_log fields in markdown frontmatter
  • children: Generates children frontmatter for child directories with index.md files
  • clean: Deletes the site directory
  • cp: Copies files to the site directory
  • feed: Generates RSS and Atom feeds
  • init: Initializes a directory with an example site
  • link: Updates the link field in markdown frontmatter with the relative URL path
  • minify: Minifies HTML, CSS, and JS
  • references: Parses markdown for hrefs and generates references and backreferences frontmatter for markdown files
  • render: Renders markdown using Liquid templates
  • serve: Starts a local HTTP server with live reload to view the site
  • siblings: Generates siblings frontmatter that contains paths for sibling markdown files
  • sitemap: Generates an XML sitemap
  • title: Updates the title field frontmatter with the value of the first # h1 or filename
  • transform: Applies a transformation function to the frontmatter in markdown files

See DOCUMENTATION.md for more information.

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:

.
├── assets
│   ├── css
│   │   └── style.css
│   ├── images
│   └── js
├── content
│   ├── 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 your new site.

You can clean your site directory with:

python -m markupdown clean

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.4.tar.gz (69.4 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.4-py3-none-any.whl (77.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for markupdown-0.2.4.tar.gz
Algorithm Hash digest
SHA256 670b3644af1c02ed9cd56c763d79623941e3e019245a25e95891d21c19649663
MD5 8de5130ed945c7b219ed832909c4b494
BLAKE2b-256 13bc1679d039a09e236fffd895f9d473ba95686d752ca0c12813b5a4d54a269c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for markupdown-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2e942c6b1c67b34994e9c34cc25136bddcc5f59e34ddad64d62b2c42a2907378
MD5 b5ab0ca8efe5f6ce54082acebd03e322
BLAKE2b-256 cf7c2301a22ab9de14f6fca639947fb106edf51712dcfde7604e418fa7369e13

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