Skip to main content

Granita is a simple static site generator for embedding Markdown in HTML templates.

Project description

Granita

A super-simple static site generator, with sensible opinionated defaults.

Installation

pip install granita

Quickstart

Run the following commands in your terminal, then open the file my_app/public/index.html in your browser.

granita init my_app
cd my_app
granita build

What this is

At a basic level, you write Markdown in the pages directory, and Granita combines them with HTML templates from the templates directory.

For example, take the following Markdown:

# Hello world!

> *I'm learning how to use [Granita](https://github.com/apple-phi/granita)*

This would be translated into HTML before being inserted inside the <content/> element in the template. By default, if a template is not specified, Granita will use the default.html file in the templates directory.

Files listed in the static directory will be copied as-is to the output public directory.

Frontmatter

To specify your own parameters, you can use a format called frontmatter. It looks like this:

---
title: "My app"
template: my_template.html
---
# Hello world!

> *I'm learning how to use [Granita](https://github.com/apple-phi/granita)*

title and template are treated specially by Granita. Here's what they do:

  • title specifies the title of the webpage, by creating a <title> element if it doesn't already exist in the template.
  • template specifies the HTML template to embed the Markdown in, with the path relative to the templates directory.

Additionally, the frontmatter keys are treated as CSS selectors for appending content to the template. So if you had the following frontmatter:

---
"#my_element": "some text"
---

Then the element with the id my_element will have the text some text appended inside it. And this will happen for all elements matched by the CSS selector. For example, if you duplicate the <content/> tag in the default template generated by granita init and rebuild, then you will see two copies of the page content.

Further configuration

If you are unsatisfied with the default paths and settings, you can create a granita.config.json file to override them. Here's what the default configuration looks like:

{
	"pages": "pages", // path to pages dir
	"static": "static", // path to static dir
	"public": "public", // path to output dir
	"templates": "templates", // path to template dir
	"default-template": "default.html", // fallback template path
	"content-selector": "content", // CSS selector to insert Markdown into
	"extra-data": {} // key : value pairs of CSS selector : HTML data
}

You don't have to provide customisation for all settings; the defaults will be used if left unspecified.

License

MIT License, which can be found here

© Copyright 2021, apple-phi.

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

granita-0.2.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

granita-0.2.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: granita-0.2.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for granita-0.2.1.tar.gz
Algorithm Hash digest
SHA256 04158ecd028744b8005bfa223a4d2cc053116eae495911cf6a3a3d13bc462207
MD5 9d8968d324af42b6e9b57b746cbeedca
BLAKE2b-256 a948fe72806ca7606048312715d8bd091cf353ef28234797e5e40ee5390c4a81

See more details on using hashes here.

File details

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

File metadata

  • Download URL: granita-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for granita-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3996c348eb0e6efca016cd4a1a2d1737ff750d569fc747ba7d9af2eed6b22518
MD5 8296431de1e699f86d6ed863ee5ebdf2
BLAKE2b-256 a0fcdff4bfa2c907727211542ce0a2690f93972ea1bfe09455669823fb7800c3

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