Themes in PieCrust
I just pushed a lot of changes to the dev branch of PieCrust, including the new support for themes. The point of themes is to make it easy to change your website’s appearance by further separating content and look.
Here’s an early look at how themes work, so that anybody can play with it and provide feedback. Not everything is in place yet, so now’s the best time to affect the design.
The theme folder
When a website is using a theme, that theme will be placed in the _content/theme folder.
The theme itself is really just another PieCrust website: it has its own _content folder with pages and templates and everything you expect. The only differences are:
- The configuration file is named
_content/theme_config.ymlinstead of_content/config.yml. This is sochefis not confused as to what’s the root of the current website when you go into the theme folder. - A theme should have a
theme_info.ymlfile at the root of the theme. It’s a YAML file with, at minimum, anameanddescription.
The theme behaves as follows:
- Pages defined in the theme (in
_content/pages, like any other PieCrust website) are added to the base website, unless a page with the same URL has been defined there. It makes it possible for themes to define pages like an “About” page or some blog archives. They effectively complement the website on which the theme is applied. - The theme’s templates directories (
site/templates_dirssetting) are added before the default_content/templatesdirectory, but after any other custom directory defined by the website. It makes it possible for themes to override the default templates, and for users to override a template defined in a theme.
The themes command
A new themes command is available in chef. It looks a lot like the plugins command in the sense that is offers the same 3 sub-commands: info, find and install. Right now, however, there are no themes in the default repository, so chef themes find won’t return anything, which means there’s no theme to install.
You could setup a local repository by setting site/themes_sources to /path/to/my/themes, where that path contains one or more themes in sub-directories. You can then install one of your local themes by running chef themes install <name>, which basically just copies the theme inside _content/theme.
For faster development, however, I would recommend just sym-linking your theme’s root directory to _content/theme.
Quickstart
To summarize, here’s how you can write a theme for PieCrust at the moment:
- Create a PieCrust site as usual.
- Rename
_content/config.ymlto_content/theme_config.yml. - Add a
theme_info.ymlfile at the root. This is a YAML file, just likeconfig.yml.- Give it a
name. - Give it a
description.
- Give it a
- Write pages, templates, CSS stylesheets and so on.
- It’s a good idea to implement standard pages like
_index.html,_tag.htmland_category.html. - It’s also good to implement standard templates like
default.htmlandpost.html.
- It’s a good idea to implement standard pages like
When you’re happy, symlink – or copy – the theme’s directory to a website’s _content/theme directory. Play around by adding new pages and posts to that site.
As always, report issues on the BitBucket or Github issue trackers.