Total Pageviews

Friday, 26 August 2016

基于python3的静态网站程序Bassclef CMS

Bassclef is a command-line CMS built on a foundation of stable and mature shell utilities. It generates static Web pages from markdown text files, and eschews the use of databases.
  • Content is written pandoc-flavoured markdown, an easy-to-read Web writing format;
  • Markdown sources are stored by the user in regular files, and are never databased (a migration nightmare for many users);
  • Pandoc's templating system is used to define the outer html structure;
  • A command-line front end (bcms) manages the processing;
  • The back end uses GNU makepandoc and ImageMagick convert (why re-invent the wheel?);
  • Facilities for constructing blogs and RSS feeds are provided;
  • CSS, font, and social media extras are provided to enable a quick start; and
  • A test server is provided to view the generated Web pages.
Bassclef was inspired by Tyler Cipriani's "Replacing Jekyll with Pandoc and a Makefile". It powers the author's blog.
I am pleased to receive bug reports via bassclef's Issues tracker.


This is Alpha software, and as such there is not currently an official release. A major rewrite is nearly complete, and I hope to make a Beta release soon.


Bassclef was written for unix-derived systems such as linux, Mac OS X and CygWin. The following prerequisites must be installed before proceeding:


To install Bassclef, you should download the source and install it (as root) using:
$ python3 install
The installation can be tested using:
$ bcms test

Quick Start

To initialize a new bassclef project, cd into an empty directory and execute:
$ bcms init --extras
This installs the build infrastructure in your current directory along with some extras (css, fonts, ...) to enable a quick start. A sample markdown file is given in the markdown/ directory.
To build the site, run:
$ bcms make
Output is written to www/. To view it with a test server, run
$ bcms serve
and point your browser to


The following discussion assumes that you are working from the command line and are currently in your bassclef project's root.


A project is initialized using:
$ bcms init
The following visible files and subdirectories are created:
config.ini css/ fonts/ images/ javascript/ markdown/
The root directory contains a hidden file .Makefile and the subdirectories each contain a file. These manage the build.
There are two flags that may be used with the init command.
  • --extras: Populates the directories with css, fonts, etc. Also creates and populates the directory templates.
  • --force: Forces the overwriting of existing files.


Site configuration is given in the config.ini, which is documented internally. All configuration items are made available to the bassclef templating system.
You should immediately set the site-url field in config.ini.


Bassclef uses pandoc-flavoured markdown. A variety of extensions to standard markdown are supported. Please see Pandoc's Markdown for the details.
Markdown files should end with a .md extension and be saved to the markdown/ directory. You may use whatever subdirectory structure you wish.


YAML metadata blocks may be placed at the top of markdown files. All metadata items are provided to the templating system. Here is an example metadata block adapted from one of my articles:
title: Echoes of Walkerton in Environment Canada cuts
subtitle: Health and safety of Canadians is at risk with latest slashing of Environment Canada budget.
author: Thomas J. Duck
date: 19 March 2014
image: /images/tiles/2014-03-19_thestar.png
caption: As seen in The Toronto Star.
The following metadata fields are recognized by bassclef. You may define these in config.ini or in YAML metadata blocks:
  • All variables in config.ini; and
  • title - the title for the page;
  • image - the relative URL to an image associated with the page.
The following metadata fields are reserved and set by bassclef. You should not set these manually, but may use them in your templates:
  • body - the html body injected into the template;
  • lang - the language for the html body tag;
  • web-root - the Web root for the site;
  • rel-url - relative link to a page;
  • permalink - the page's permalink;
  • rss-url - a link to the rss feed (composed pages only);
  • first-entry - flags the first entry in a composed page;
  • quoted-title - the document title with URL-escaped characters;
  • quoted-plus-title - the document title with URL-escaped characters and spaces coded as plus signs;
  • quoted-permalink - the URL-escaped permalink;
  • posted-in-html - a comma-separated list of links to composed ( files in which the current file is listed (you must list composed files in the posted-in field of your config.ini for this).


Images should be stored in the images/ directory.
The image associated with each page should be listed the in the metadata block. It will normally be inserted between the first and second elements of your content.
URLs for images in your documents should begin with /images/.

Composed pages

Composed pages are assembled from the contents of other pages. An example is a summary page for a series of blog posts.
Composed pages are defined by files and should be stored in the markdown directory. Composed pages contain regular markdown text and filename listings with one filename per line. Bassclef replaces the filenames with each file's contents. Here is an example adapted from my blog:
title: Latest Posts

Often it is undesirable to include the full text for each filename entry. See Processing Flags, below.

Processing Flags

Processing flags are used in markdown files to fine-tune how content is displayed. The following flags are supported:
<!-- image --> ~ Marks where the image defined in the metadata should be inserted.
<!-- vspace --> ~ Adds some vertical space.
<!-- break --> ~ Inserts a line break that clears to both margins.
<!-- cut --> ~ Marks where content should be cut when displayed in a composed page. "Read more..." links are automatically added.


To build your pages, run:
$ bcms make
This command is simply a wrapper for GNU make, and any processing flags that you would normally use with make can be used here. For example, to only build the html files use:
$ bcms make html
Other targets include imagescssfonts and javascript. Destination filenames can also be used as targets.
To force a build use:
$ bcms make -B
This will be needed if you make a change to a template or config.ini.
Html is written to www/.
Images are copied to www/images/originals/. Versions with reduced size (as set by imagegeometry in config.ini) are created using convert and stored in www/images/. The smaller versions are automatically linked to their full-size originals in the output html.
CSS files are copied to www/css/ and fonts are copied to www/fonts/.


Html templates are stored in templates/. You can -- and should -- edit these templates and create new ones.
The template language is pandoc's own, with one exception: An $include()$ function is provided by pandoc-tpp.
There is not currently any documentation for the pandoc template language, but it is pretty easily discerned by reading the sources. Pandoc template directives are enclosed by dollar signs. Everything else is html.
All configuration and metadata items are provided to the template.


To view your pages, use:
$ bcms serve
and point your browser to Type ^C to exit the test server.