Skip to main content

A simple util for 'compiling' a folder, e.g. to a static website.

Project description

Some processors for FolderCompiler to compile a static website

This static website generator is meant to generate simple webpages as simple as possible by mainly applying a markdown generator and jinjer templates in an organized way. The general assumption is, that every output file only requires a single input file (+template). You just specify which Processor is applied for which files (e.g., the MarkdownProcessor for all files ending with ".md" in the input directory).

See also the base project folder_compiler.

Principles

  • The primary focus is to apply a template to content files (e.g. a navigation bar).
  • Keep it super simple (I update my webpage maybe every year and don't want it to take much knowledge that I immediately forget afterwards)
  • Keep it open (especially do not hide jinja)
  • Allow more complex behavior where possible without increasing the complexity of the generator (actually, this is included in the previous point).

Processors

A processor gets an input file (e.g., a markdown file) and compiles it to an arbitrary amount of output files.

It is very simple to create your own processor (e.g., for automatically compressing every jpg into _small, _medium, and _large). For the cases I need myself, a set of processors is already provided:

  • HtmlProcessor: Simply passes the content to a jinjer template (thus, file content must already be html readable)
  • MarkdownProcessor: Parses a markdown file including metadata and lets a jinjer template render it.
  • BibtexProcessor: Parses a bibtex file and lets a jinjer template create a nice bibliography.
  • FileCopyProcessor: Simply copies a file (Part of FolderCompiler)
  • DevNullProcessor: Ignores files (Part of FolderCompiler)

Example

See in the following example, how simple it is to configure

import jinja2 as jinja2

from folder_compiler import FolderCompiler
from folder_compiler.processors import FileCopyProcessor
from static_webpage_folder_compiler import MarkdownProcessor

# Create jinja2 environment as powerful template engine
# ./template holds the template files in this case
jinja = jinja2.Environment(
    loader=jinja2.FileSystemLoader('./templates'),
)

# jinja templates (see example folder)
md_template = jinja.get_template("markdown_default.html")

# Processors
processors = [
    MarkdownProcessor(md_template).add_include(".*.md"),  # apply to all *.md files
    FileCopyProcessor().add_exclude(".*/\..*")  # copy the rest (except hidden files)
]

# Compile the files in the folder ./content to ./output
FolderCompiler(input="./content", output="./output").compile(processors).remove_orphaned_files()

But if you want to do something complex like a blog, try something more advanced like Hyde.

Project details


Download files

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

Files for folder-compiler-static-website, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size folder_compiler_static_website-0.1.1-py3-none-any.whl (11.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page