Blog platform based on Tornado, MongoDB, and Motor. To be used with MarsEdit.
- MongoDB
- Python 2.7
- Tornado
- Motor, my experimental asynchronous MongoDB driver for Tornado
- Greenlet
- Other packages in
requirements.txt
-
Frontend: Motor-Blog runs in Tornado. It is very fast.
-
Editing: Motor-Blog has no admin panel, but supports MarsEdit.
-
Comments: Motor-Blog does not support comments natively, I recommend a third-party Javascript comments API like Disqus.
-
Retina Ready: See image-handling below.
-
Customization: Appearance is completely customizable.
-
Install MongoDB and run it on the default port on the same machine as Motor-Blog
-
pip install -r requirements.txt
-
To migrate from a prior WordPress blog with migrate_from_wordpress.py you'll need Pandoc
Start MongoDB
mkdir data
mongod --dbpath data --logpath data/mongod.log --fork
Set your PYTHONPATH to include PyMongo and Motor:
export PYTHONPATH=/path/to/mongo-python-driver
Copy motor_blog.conf.example to motor_blog.conf, edit it as desired. Start the application:
python server.py --debug
Visit http://localhost:8888/blog
I run Motor-Blog on http://emptysquare.net/blog with Nginx at the front and four server.py
processes.
Those processes and MongoDB are managed by Supervisor.
I've provided example config files in this repository in etc/
.
In MarsEdit, do "File -> New Blog." Give it a name and the URL of your Motor-Blog's home page. MarsEdit auto-detects the rest. You'll need to enter the username and password you put in motor_blog.conf. In the "General" tab of your blog's settings, I suggest setting "Download the 1000 most recent posts on refresh," since Motor-Blog can handle it. Under "Editing," set Preview Text Filter to "Markdown", and Image Size "Defaults To Full Size". Under "Custom Fields," add a "description" field. This lets you set the meta-description field for each post, which search engines show as the excerpt:
When you're editing a post, do "View -> Slug Field" to set a custom slug as the final part of the post's URL. If you leave the slug empty, Motor-Blog slugifies the title.
Motor-Blog supports the same Markdown dialect as cMarkdown with its flags set to the defaults. Plain inline code is surrounded by backticks (``). Syntax-highlighted code is indented with four spaces, and the first line is like:
::: lang="py" highlight="4,5,6"
... to specify the language syntax and which lines to highlight in yellow. The list of languages
is whatever Pygments supports, including the following of
interest to Python coders like me: py
, py3
, pytb
and py3tb
for tracebacks, and pycon
for
console sessions.
Motor-Blog tries to show images beautifully on every device.
When you upload an image, Motor-Blog resizes the image to 600px wide and centers it.
If your theme has columns of some width other than 600px, override maxwidth
in motor_blog.conf
.
Motor-Blog strips the width
and height
attributes from
\<img\>
tags so images can be resized responsively on mobile screens.
To support visitors with Retina displays, upload your images at double resolution and named like
<filename>@2x.<extension>
, for example image@2x.jpg
.
Motor-Blog replaces such images with regular images but stores the retina image for later.
The default theme includes retina.js
, which replaces regular images with double-res
images on retina devices.
- Set your theme directory in
motor_blog.conf
. - The theme directory should contain a
templates
subdir with the same set of filenames as the example theme. - Follow the example theme for inspiration.
- The
setting()
function is available to all templates, and gives access to values inmotor_blog.conf
.
- server.py: Web application server
- motor_blog/: Package code
- web/
- handlers.py: RequestHandlers for the blog's website
- admin-templates/: Templates for login/out and viewing drafts
- theme/: Default theme for emptysquare.net, overridable with your theme
- api/: The XML-RPC API that MarsEdit uses
- models.py: schema definitions
- text/
- markup.py: convert from Markdown into HTML for display, including some custom syntax
- wordpress_to_markdown.py: convert from the WordPress's particular HTML to markdown, for migrate_from_wordpress.py
- abbrev.py: convert from HTML to truncated plain text for all-posts page
- tools/:
- migrate_from_wordpress.py: Tool for migrating from my old Wordpress blog to Motor-Blog. I wrote this tool when Motor didn't support GridFS, so it puts all media from Wordpress into single documents in the "media" collection, which brings us to...
- migrate_media_to_gridfs.py: Tool to migrate media from a single document per image in the "media" collection to GridFS.
- cache.py: Cache results from MongoDB, invalidate when events are emitted
- indexes.py: Index definitions for server.py --ensure_indexes
- options.py: Configuration parsing
- web/