Skip to main content

nanogen

A very small static blog generator written in Python.

Latest PyPI version

Purpose

nanogen exists solely so I can have a blogging platform I call my own. If other people find this useful and want to use it, that’s wonderful but it’s not a goal for this project.

The platform is very intentionally bare bones and simple. The code is intentionally utilitarian and less-than-perfect.

If you have an idea for a way to improve this without significantly increasing nanogen’s complexity, please open an issue and let me know. If it’s something I might use, then it’ll get merged. If it isn’t, then I’m sorry.

If you’re looking for a more fully-featured static site generator, may I recommend something like Jekyll or Pelican ?

Installation

The best way to install nanogen is through pip:

$> pip install nanogen

If you don’t want to install it via pip, you can install it manually:

$> git clone https://github.com/epochblue/nanogen
$> cd nanogen
$> python setup.py install

Note : To avoid possible dependency version issues, I advise installing nanogen into a virtual environment, rather than globally.

How To Use

Initializing

Once nanogen is installed, navigate to the directory you’d like to use as your new blog. Our examples will use a blog directory in $HOME:

$> mkdir blog
$> cd blog

Once there, run nanogen’s init command to get started:

$> nanogen init

Running this command will generate the basic directories used by nanogen. When this command completes, the blog directory will look like this:

~/blog
|-- _posts
`-- _layout

These are all the only two folders required by nanogen, and cannot currently be changed by the user. Your individual posts will go in the _posts directory, and the templates will go in the _layouts directory.

At this time, nanogen does not come with a built-in theme, so it’s up to the user to create their own.

Creating Posts

One way to create new posts is by creating a new file in the _posts directory. The filename is important and must match the following rules:

  1. The file can’t start with an underscore (they are ignored)

  2. The file’s name must match the pattern yyyy-mm-dd-<post_title_slug>

  3. The file’s extension must be a valid Markdown extension (md, mdown, or markdown).

To illustrate:

# valid filename
2015-11-01-this-charming-man.md

# invalid filename
15-11-1-bigmouth-strikes-again.txt

If you don’t want to try to remember all that, you can use nanogen’s new command to do it for you. The only required argument to this command is the title of the post being generated:

$> nanogen new "Example Post Title"

Running this will create a properly-named and formatted file in the _posts directory.

Draft posts aren’t an “official” feature of nanogen, however they are possible. By default, when nanogen generates a site it will only look in the _posts folder for files to process. If you’d like to maintain drafts of your posts before you publish them, you can create a _drafts folder next to the _posts folder and nanogen will ignore it during site generation. Alternatively, you can prepend the filename of a drafe with an underscore, and nanogen will skip over it when searching for files to process.

Post Content Format

nanogen posts don’t use YAML front-matter, so the first line of your post will be used for the title of the post. The content of the posts will be processed as Markdown (the Github-flavored variety, complete with syntax-highlighted code blocks). A minimal example of a valid nanogen post is this:

## This will become the title (with hashes stripped out)

**This** will become the post's _content_.

Generating Your Site

Once you’re ready to generate your site, you can use the build command:

$> nanogen build

This command will walk your _posts directory, process any valid files it finds, and will write all the generated HTML files into a _site folder. Although you will want to preview this on your local development system (see the following section for how to do this), the _site folder can be uploaded to your web host as-is.

Note: before each build nanogen will run the clean command. clean will remove the _site directory and all of its contents, so it’s not a good idea to add anything to the _site directory that you intend to keep between builds.

Previewing Your Site

To see what your site will look like before you upload it to a live webserver for the world to see, nanogen provides a built-in server that allows you to preview your generated site:

$> nanogen preview

This command will start a server that listens on localhost port 8080. Simply open http://localhost:8080 in a web broswer to see how your site looks. If you’d like to use a different hostname or port, nanogen provides an option for each (-h|--host, and -p|--port, respectively). The following example will start a server that listens on local.dev port 8000 (http://local.dev:8000):

$> nanogen preview --host local.dev --port 8000

Cleaning

If your _site folder somehow gets corrupted, or you’d simply like to generate your site from scratch, you can use the clean command:

$> nanogen clean

There is no undo or confirmation when running this command.

nanogen Themes

Note: nanogen doesn’t provide any themes out of the box. If you’d like to develop your own theme for nanogen, this section should explain how.

nanogen uses Jinja2 for its templating. If you need information about Jinja’s syntax, please refer to their documentation.

Template Files

The templates that make up the theme for your nanogen blog need to be placed in the _layout directory. nanogen only expects a few files to exist, and those files are:

  1. index.html

  2. post.html

  3. rss.xml

index.html will be used as the sites homepage, post.html will be used to generate each individual post, and rss.xml will be be used to generate your blog’s RSS feed.

All of your blog’s posts will be passed to index.html and rss.xml via a Jinja2 context variable named posts. Individual posts will be passed to post.html via a context variable named post. Each post will have the following relevant attributes available to use in the template:

  • content - the HTML content of the post

  • title - the title of the post (will not be processed as Markdown)

  • pub_date - a Python datetime object representing the publish date of the post

  • permalink - the relative URL to the post

Please see the _layout directory in the included example for a basic theme you can use to as a jumping off point for your own theme.

Static Files

If you have any files that you’d like to include in the published site (JavaScript files, CSS files, images, etc), place them into a folder named static inside the _layout folder. This folder will automatically be copied into the _site folder during the build process. No processing will be performed on the files within the static directory.

License

nanogen is MIT licensed. Please see included LICENSE file for more information.

Author

Bill Israel - bill.israel@gmail.com

Release files for nanogen 0.9.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nanogen 0.9.9
File Size Uploaded
nanogen-0.9.9.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nanogen 0.9.9
File Interpreter ABI Platform
nanogen-0.9.9.macosx-10.11-x86_64.tar.gz Details

Total release size: 28.5 kB

Release files / nanogen-0.9.9.tar.gz

Download URL nanogen-0.9.9.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4ce0320a4f57249576f5feb1f18ea85212582779a7cd586771f76a4a81c74517
BLAKE2b-256 checksum
How to use checksums
d2ddf9b8089c7b3276e441b1c03ee35b872ce4741db5094d3d9e878f39ab617e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / nanogen-0.9.9.macosx-10.11-x86_64.tar.gz

Download URL nanogen-0.9.9.macosx-10.11-x86_64.tar.gz
Size 21.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9cd6380ecc6208236214af6638cc76f322a1bdec4be0c2f05396cb8b5f661297
BLAKE2b-256 checksum
How to use checksums
79cb69563942fcab4f0aa3d7fb2325ffb7bdebabc157c60f92871027caa3ab2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.1.2

1 release file

1.0.1

2 release files

1.0.0

2 release files

This release

0.9.9 This release

2 release files

0.9.3

1 release file

0.9.2

1 release file

0.9.0

1 release file

0.8.0

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page