Skip to main content

Static site generator

Project description

Pages is a command line static site generator.

Piglet templates are used by default, but Jinja2, Chameleon, Genshi or Kajiki can all be used supported, and content can be read from reStructuredText, markdown or JSON data files.

Quick start

To get up and running with the default configuration of Piglet + reStructuredText:

pip install pages

pages --template layout.html --output build/ src/

For markdown, or to use another templating system, install the relevant extras hook, eg:

pip install pages[markdown,jinja2]

Examples

Select individual files to render:

pages --template layout.html -p1 --output=build/ src/index.md src/page1.md

Select a different template for a file:

pages --template layout.html -p1 --output=build/ src/ src/stats.json:report.html

Read the list of files to render from stdin:

find src/ -type f -name \*md | pages --template layout.html -p1 --output=build/

Select a different templating system:

pages --render-with jinja2 --template layout.html --output=build/ src/

Load additional data into the template context:

# Inline JSON
pages --template layout.html --context '{"foo": "bar"}' src/

# a JSON file
pages --template layout.html --context data.json  src/

# JSON loaded from a remote API
pages --template layout.html --context <(curl -s 'wttr.in/?format=j1') src/

# A python module
pages --template layout.html --context myproject.somemodule:avariable src/

# A python script
pages --template layout.html --context somevars.py src/

Path stripping

If you supply a directory to pages, it will render all the files inside that directory, stripping off the directory name. For example given a file at src/index.rst, this:

pages -t layout.html -o build/ src/

will produce this:

build/index.html

It will not strip the prefix of individually named files, so this:

pages -t layout.html -o build/ src/index.rst

will produce this:

build/src/index.html

Use -p <n>/--strip <n> to tell pages to remove one or more levels of path prefix. -p 1 will strip off one level of prefix, higher values will strip off more. -p 0 will leave the path unmodified.

Note that -p/--strip is only used for sources listed by full path names.

Rendering markdown

Markdown sources are processed using Python-Markdown with the “extra” and “meta” extensions loaded.

The template will be called with the following context variables:

{
    "html": ...,  # Content rendered as HTML
    "meta": ...,  # Parsed metadata
}

Rendering reStructuredText

reStructuredText sources make the following context variables available to the template:

{
  "title": ...              # Document title
  "meta": ...               # Key-value pairs from top level field lists
  "html": ...               # Rendered html body (incl. the title heading)
  "html_without_title": ... # As above, but without the title heading
  "parts": ...              # Parts dict as returned by the docutils writer
}

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

pages-0.3.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

pages-0.3-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file pages-0.3.tar.gz.

File metadata

  • Download URL: pages-0.3.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.13

File hashes

Hashes for pages-0.3.tar.gz
Algorithm Hash digest
SHA256 7c7c452c8a6dd67f3645beb54f94891ae053921ca8d4fb6b57b957375a1de1c9
MD5 53d7bf83701a64e0964d831b2380b316
BLAKE2b-256 fcf2c66db080b87ec42ebdcfedfaa4a2402bd68c99a5dbf660039493c0083dc6

See more details on using hashes here.

File details

Details for the file pages-0.3-py3-none-any.whl.

File metadata

  • Download URL: pages-0.3-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.13

File hashes

Hashes for pages-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 df7ddd10f55765c28dd4a5112d847a8863f8a0e58da86642577388793c9c6bbb
MD5 23f5cda784a75ae4eb083caf1c3100f0
BLAKE2b-256 4ab9f285e5bc7aa51276dac5e18e5f3fdfb832368cc5980f1d3cd1ff784d46bb

See more details on using hashes here.

Supported by

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