• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    Python
  • Created over 12 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Blog based on Tornado, MongoDB, and Motor. To be used with MarsEdit.

Motor-Blog

Blog platform based on Tornado, MongoDB, and Motor. To be used with MarsEdit.

Prequisites

Features

  • 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.

  • Customization: Appearance is completely customizable.

Installation

  • 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

Deployment

Development Deployment

Start MongoDB

mkdir data
mongod --dbpath data --logpath data/mongod.log --fork --setParameter textSearchEnabled=true

Copy motor_blog.conf.example to motor_blog.conf, edit it as desired. Start the application:

python server.py --debug --config=motor_blog.conf --ensure-indexes

Visit http://localhost:8888/blog

Production Deployment

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/. If you have an Nginx version with WebSocket support (1.3.13 or later) then draft posts will autoreload when you update them from MarsEdit.

Run python server.py --ensure-indexes at once when first installing Motor-Blog on a production MongoDB server. (If you see an error when using the search box, "Can't canonicalize query: IndexNotFound text index required for $text query", it means you haven't done this step. In any case, running Motor-Blog without indexes built will risk performance problems.)

MarsEdit setup

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".

When you're editing a post, do "View -> Excerpt" to edit the post's meta-description. This text appears in Google results as a snippet, or when sharing a link to the post on Facebook. Motor-Blog refuses the post if the meta-description field is over 155 characters. 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.

Finally, you'll want to customize how MarsEdit inserts images. This customization serves two purposes: first, we'll remove the width and height from img tags so Motor-Blog's responsive layout can fit them to the visitor's screen. Second, we'll set images' title text is set to the same value as their alt-text, since browsers display image titles as tooltips. Open the MarsEdit Media Manager and select an image. In the Media Manager's lower-right corner is a "Style" chooser, with the option "Customize...":

Alt text

Choose this and create a new image style with "opening markup" like this:

<img
    style="display:block; margin-left:auto; margin-right:auto;"
    src="#fileurl#"
    alt="#alttext#"
    title="#alttext#" />

Blogging

Motor-Blog renders Markdown with Python-Markdown. Plain inline code is surrounded by single backticks (``). Code blocks can be fenced in a number of styles, such as GitHub's:

```python
print "foo"
```

The list of languages is whatever Pygments supports. The following are of interest to Python coders like me: py, py3, pytb and py3tb for tracebacks, and pycon for console sessions.

Using a feature in the latest Python-Markdown, you can highlight specific lines in a code block:

```python hl_lines="2"
# Line 1.
# Line 2. This will have a yellow background
```

Customization

  • 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. Tornado templates or Jade templates are both supported.
  • Follow the example theme for inspiration.
  • The setting() function is available to all templates, and gives access to values in motor_blog.conf.

A Tour of the Code

  • 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

More Repositories

1

proporti.onl

Compare number of women, men, and nonbinary people among my friends and followers.
Python
238
star
2

toro

Synchronization primitives for Tornado coroutines
Python
193
star
3

coroutines-demo

Live-coding a Python 3 async framework
Python
67
star
4

GreenletProfiler

Abandoned, please use Yappi.
C
51
star
5

chirp

A minimal Twitter clone to demonstrate Tornado and MongoDB
JavaScript
48
star
6

python-paxos-jepsen

Paxos in Python, tested with Jepsen
Python
31
star
7

cluster-profile

Demo scripts for setting up and profiling a sharded MongoDB cluster.
Python
16
star
8

geo-paging-example

Example of using MongoDB's new $minDistance option for paging through geo results.
JavaScript
13
star
9

emptysquare-lektor

Python
13
star
10

consistency-isolation-pycon-2023

Files related to A. Jesse Jiryu Davis's PyCon 2023 talk.
Python
12
star
11

tornado-test

Conveniences for unittesting Tornado-based asynchronous code
Python
10
star
12

asyncio-chat-example

Python 3.4 asyncio chat example
JavaScript
9
star
13

things2rtm

Import tasks from Cultured Code's Things to Remember The Milk
Python
8
star
14

bson-numpy

Fast conversion between NumPy arrays and MongoDB's native data format, BSON.
Python
8
star
15

yieldpoints

Simple extensions to Tornado's gen module.
Python
8
star
16

why-should-async-get-all-the-love

Source files for A. Jesse Jiryu Davis's PyCon 2022 talk
Python
7
star
17

zero-to-app

Zero to App in 30 Minutes, with Python and MongoDB
JavaScript
5
star
18

trickle

IOStream wrapper for use with Tornado coroutines
Python
5
star
19

osbridge-2015

Script for implementing Python async coroutines, live!
Python
4
star
20

pymongo-mockup-tests

Test PyMongo with MockupDB - for eventual merge into mongo-python-driver repo.
Python
4
star
21

emptysquare.net

A minimalist static photography gallery, pulling sets from a Flickr collection.
Python
3
star
22

motor-tools

Tools for developing and testing Motor, an asynchronous Python driver for Tornado and MongoDB
Python
3
star
23

list-of-tlaplus-operators

TeX
2
star
24

rescue_bson

Python
2
star
25

motor.github.com

GitHub Pages site for Motor, an asynchronous driver for MongoDB and Tornado
2
star
26

yelp-better-bookmarks

Nicer Yelp personal bookmarks browsing with Google maps
JavaScript
2
star
27

json_validate

A wrapper function that validates that some JSON object matches a spec, something like a validating XML parser. This is particularly useful if you expose a JSON API to third-party developers and want to return a useful error if they provide malformed input.
Python
2
star
28

SyncSend

Simple means of sending very large files to someone else if you're both online at the same time
JavaScript
2
star
29

eventuallycorrect

Code and supplements for my PyCon 2015 "Eventually Correct" talk on async testing.
Python
2
star
30

ShardViz

Watch a MongoDB sharded cluster rebalancing its data distribution
Shell
1
star
31

Emptysquare-Slideshow

Generate a static HTML + jQuery slideshow from a Flickr set. Inspired by New York Times' elegant dark slideshow layouts.
Python
1
star
32

svnlog

Script to view Subversion commit comments and diffs, same as git does by default.
1
star
33

emptysquare-hugo

A. Jesse Jiryu Davis's personal blog and site.
CSS
1
star
34

eventcalendar3

Event Calendar 3 WordPress plugin - ajdavis's fork
PHP
1
star
35

uninterpolate

Update Python' code to replace the old % formatting with format()
1
star
36

emptysquare-wordpress-theme

WordPress theme for emptysquare.net
1
star
37

lambda-endsessions-python

Python
1
star
38

three-eleven-mongolite-demo

Analyze NYC Noise Complaints with R, MongoDB, and Mongolite
R
1
star
39

term2image

Read the output of a terminal command like "man" or "ls" and write a PNG.
Python
1
star
40

2021-jesse-samy-tlaplus

Source for Interactive TLA+ talk at 2021 TLA+ Conference
TLA
1
star
41

what-to-expect-when-youre-expiring

Demonstrations of what can go wrong with Python's __del__.
Python
1
star
42

ajdavis-queue-theory-exercises

Python
1
star