Skip to main content

An extensible static site generator.

Project description

Pyndakaas

An extensible static site generator written in Python.

Features

  • Extensible Handler System: Register custom file handlers for different content types
  • Flexible Renderer System: Support for multiple rendering engines (Markdown, etc.)
  • Template Support: Jinja2-based templating with metadata support
  • File Metadata: JSON frontmatter parsing for rich content metadata
  • Glob Matching: Template functions for filtering and selecting files

Installation

pip install pyndakaas

For development:

git clone https://github.com/rubenvannieuwpoort/pyndakaas
cd pyndakaas
pip install -e .

Quick Start

pyndakaas is meant to be used by calling process_dir with an input directory, output directory, and optionally a templates directory (if not provided, 'templates' is used). It uses Jinja templates. It is easiest to show how it works by example.

build.py:

import markdown
from pyndakaas import Handler, handler, process_dir

from pathlib import Path


@handler()
class Markdown(Handler):
    @staticmethod
    def should_handle(source_path: Path) -> bool:
        return source_path.suffix == '.md'

    def template(self) -> str:
        return 'post'

    def body(self) -> str:
        return markdown.markdown(self.source)


# Using default 'templates' directory
process_dir(Path('src'), Path('build'))

src/posts/example.md:

{
	"title": "This is the title of my first post"
}

# Hello, blog

I wanted to write a blog and `pyndakaas` makes it super easy!

src/index.html:

{
	"title": "Welcome to my blog!",
	"template": "index"
}

templates/post.jinja:

<html lang="en">
<head>
	<title>{{front_matter.title}}</title>
</head>
<body>
{{body}}
</body>
</html>

templates/index.jinja:

<html lang="en">
<head>
	<title>My blog</title>
</head>
<body>
	<p>
		My posts:
		{% for post in root.glob('posts/*.md') %}
		<ul>
			<li><a href="{{post.output_path}}">{{ post.front_matter.title }}</a></li>
		</ul>
		{% endfor %}
	</p>
</body>
</html>

File Format

Source files use JSON frontmatter followed by content:

{
    "title": "My Post",
    "author": "John Doe",
    "template": "custom-layout"
}

# My Content

This is the actual content that will be processed.

The template field in frontmatter will override the handler's default template specified in the template method of the handler.

Handlers

Handlers define how different file types are processed:

  • should_handle(): Static method to identify files this handler should process
  • suffix(): Method returning output file extension (defaults to '.html')
  • body(): Method returning processed content
  • template(): Method returning template name to use (or None to don't use a template and instead output the processed content)

Templates

Templates are Jinja2 files in the templates/ directory. They receive:

  • front_matter: Parsed JSON frontmatter from the source file
  • body: Processed content from the handler's body() method
  • folder: Globber instance for filtering files relative to current file
  • root: Globber instance for filtering files relative to the root of the input directory

License

MIT License - see LICENSE file for details.

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

pyndakaas-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

pyndakaas-0.2.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pyndakaas-0.2.0.tar.gz.

File metadata

  • Download URL: pyndakaas-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyndakaas-0.2.0.tar.gz
Algorithm Hash digest
SHA256 48fb9f6e1715ad8b5351d23dbc2f7fa6804c085f00941ce4fc7572ba6219a0a6
MD5 11be6e227339b620ad8d43a4bfb8bdb6
BLAKE2b-256 b46d67b01c578d72ec15e44a88e9f7bcfe68c1cbf508b2e7e6a85b89ac9646a4

See more details on using hashes here.

File details

Details for the file pyndakaas-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyndakaas-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyndakaas-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71d5e053a37052006c6fdf875bb90026088758fc92cdef682da6f6ec05f918f9
MD5 799f2b6682dcc5d35cf54f5fb4f85358
BLAKE2b-256 84a0e12f79712c3a8bf8ab72f147155585072e51da135e9d8637eb37bf651897

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