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 try to find and use file called default.html in your 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 prepending 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 prepended 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
 "global-stylesheet": null, // a stylesheet to be applied to all templates
 "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.3.0.tar.gz (4.9 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.3.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for granita-0.3.0.tar.gz
Algorithm Hash digest
SHA256 00fd87ba374d2a2bd05e544419818bcad835ba55e61dc8239573de596846574c
MD5 b55915191d86811815a4eceb15aa21e5
BLAKE2b-256 b380e8b0efb259ca4fc11ddc0ed8611fcaf4bcdc78b62773c699bffa2ac01765

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for granita-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e53d272b6652a5e3b133412aa1991ea95fac1fbaf9931b3b8991f9f200c1e06
MD5 7e3816e4a6a975489dd86b60b5e029bf
BLAKE2b-256 91e42403d5073d2949481ec9fff649f055857967c4798f2881445bf439abf6c7

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