• This repository has been archived on 03/Dec/2019
  • Stars
    star
    333
  • Rank 126,599 (Top 3 %)
  • Language
    Python
  • License
    Other
  • Created about 13 years ago
  • Updated almost 8 years ago

Reviews

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

Repository Details

A super simple "static site generator" Django app. (Unmaintained: see README for alternatives.)

django-medusa

A super simple "static site generator" for Django sites. Read more about this project here.

Β© 2011-2014 Mike Tigas. Licensed under the MIT License.


Note: This project is largely unmaintained since 2014 and may be broken. If you want to use something similar that's gotten more love lately, look at the following which are still somewhat active, as of January 2016:


django-medusa allows rendering a Django-powered website into a static website a la Jekyll, Movable Type, or other static page generation CMSes or frameworks. It is designed to be as simple as possible and allow the easy(ish) conversion of existing dynamic Django-powered websites -- nearly any existing Django site installation (not relying on highly-dynamic content) can be converted into a static generator which mirror's that site's output.

Given a "renderer" that defines a set of URLs (see below), this uses Django's built-in TestClient to render out those views to either disk, Amazon S3, or to Google App Engine.

At the moment, this likely does not scale to extremely large websites due to the use of the internal TestClient. But django-medusa optionally uses the multiprocessing library to speed up the rendering process by rendering many views in parallel.

For those uninterested in the nitty-gritty, there are tutorials/examples in the docs dir:

Renderer classes

Renderers live in renderers.py in each INSTALLED_APP.

Simply subclassing the StaticSiteRenderer class and defining get_paths works:

from django_medusa.renderers import StaticSiteRenderer

class HomeRenderer(StaticSiteRenderer):
    def get_paths(self):
        return frozenset([
            "/",
            "/about/",
            "/sitemap.xml",
        ])

renderers = [HomeRenderer, ]

A more complex example:

from django_medusa.renderers import StaticSiteRenderer
from myproject.blog.models import BlogPost


class BlogPostsRenderer(StaticSiteRenderer):
    def get_paths(self):
        paths = ["/blog/", ]

        items = BlogPost.objects.filter(is_live=True).order_by('-pubdate')
        for item in items:
            paths.append(item.get_absolute_url())

        return paths

renderers = [BlogPostsRenderer, ]

Or even:

from django_medusa.renderers import StaticSiteRenderer
from myproject.blog.models import BlogPost
from django.core.urlresolvers import reverse


class BlogPostsRenderer(StaticSiteRenderer):
    def get_paths(self):
        # A "set" so we can throw items in blindly and be guaranteed that
        # we don't end up with dupes.
        paths = set(["/blog/", ])

        items = BlogPost.objects.filter(is_live=True).order_by('-pubdate')
        for item in items:
            # BlogPost detail view
            paths.add(item.get_absolute_url())

            # The generic date-based list views.
            paths.add(reverse('blog:archive_day', args=(
                item.pubdate.year, item.pubdate.month, item.pubdate.day
            )))
            paths.add(reverse('blog:archive_month', args=(
                item.pubdate.year, item.pubdate.month
            )))
            paths.add(reverse('blog:archive_year', args=(item.pubdate.year,)))

        # Cast back to a list since that's what we're expecting.
        return list(paths)

renderers = [BlogPostsRenderer, ]

Renderer backends

Disk-based static site renderer

Example settings:

INSTALLED_APPS = (
    # ...
    # ...
    'django_medusa',
)
# ...
MEDUSA_RENDERER_CLASS = "django_medusa.renderers.DiskStaticSiteRenderer"
MEDUSA_MULTITHREAD = True
MEDUSA_DEPLOY_DIR = os.path.abspath(os.path.join(
    REPO_DIR,
    'var',
    "html"
))

S3-based site renderer

Example settings:

INSTALLED_APPS = (
    # ...
    # ...
    'django_medusa',
)
# ...
MEDUSA_RENDERER_CLASS = "django_medusa.renderers.S3StaticSiteRenderer"
MEDUSA_MULTITHREAD = True
AWS_ACCESS_KEY = ""
AWS_SECRET_ACCESS_KEY = ""
MEDUSA_AWS_STORAGE_BUCKET_NAME = "" # (also accepts AWS_STORAGE_BUCKET_NAME)

Be aware that the S3 renderer will overwrite any existing files that match URL paths in your site.

The S3 backend will force "index.html" to be the Default Root Object for each directory, so that "/about/" would actually be uploaded as "/about/index.html", but properly loaded by the browser at the "/about/" URL.

BONUS: Additionally, the S3 renderer keeps the "Content-Type" HTTP header that the view returns: if "/foo/json/" returns a JSON file (application/json), the file will be uploaded to "/foo/json/index.html" but will be served as application/json in the browser -- and will be accessible from "/foo/json/".

App Engine-based site renderer

Example settings:

INSTALLED_APPS = (
    # ...
    # ...
    'django_medusa',
)
# ...
MEDUSA_RENDERER_CLASS = "django_medusa.renderers.GAEStaticSiteRenderer"
MEDUSA_MULTITHREAD = True
MEDUSA_DEPLOY_DIR = os.path.abspath(os.path.join(
    REPO_DIR,
    'var',
    "html"
))
GAE_APP_ID = ""

This generates a app.yaml file and a deploy directory in your MEDUSA_DEPLOY_DIR. The app.yaml file contains the URL mappings to upload the entire site as a static files.

App Engine generally follows filename extensions as the mimetype. If you have paths that don't have an extension and are not HTML files (i.e. "/foo/json/", "/feeds/blog/", etc.), the mimetype from the "Content-Type" HTTP header will be manually defined for this URL in the app.yaml path.

Usage

  1. Install django-medusa into your python path (TODO: setup.py) and add django_medusa to INSTALLED_APPS.
  2. Select a renderer backend (currently: disk or s3) in your settings.
  3. Create renderer classes in renderers.py under the apps you want to render.
  4. django-admin.py staticsitegen
  5. ???
  6. Profit!

Example

From the first example in the "Renderer classes" section, using the disk-based backend.

$ django-admin.py staticsitegen
Found renderers for 'myproject'...
Skipping app 'django.contrib.syndication'... (No 'renderers.py')
Skipping app 'django.contrib.sitemaps'... (No 'renderers.py')
Skipping app 'typogrify'... (No 'renderers.py')

Generating with up to 8 processes...
/project_dir/var/html/index.html
/project_dir/var/html/about/index.html
/project_dir/var/html/sitemap.xml

More Repositories

1

iOS-MapLayerDemo

Demo of using MKOverlayView in iOS 4.0+ to render custom tile server overlays. (Last updated in 2012, you probably want to look elsewhere for modern code examples.)
Objective-C
197
star
2

django-twofactor

Two factor auth using the TOTP draft spec. Compatible with the Google Authenticator or any other TOTP token. (Unmaintained, last updated in 2013.)
Python
63
star
3

iObfs

obfs4proxy for Onion Browser & other Tor iOS apps --- DEPRECATED AND SUPERSEDED BY @tladesignz/IPtProxy
Objective-C
39
star
4

heroku-django-demo-app

A demo Django-on-Heroku app.
Python
21
star
5

simurgh

A ADS-B "BEAST" TCP decoder server, in Go. Requires dump1090 or similar application with BEAST TCP output. β€’β€’β€’β€’β€’β€’ THIS REPO LIVES AT THE FOLLOWING URL NOW: https://0xacab.org/mtigas/simurgh β€’ or via tor: http://wmj5kiic7b6kjplpbvwadnht2nh2qnkbnqtcv3dyvpqtz7ssbssftxid.onion/mtigas/simurgh
Go
15
star
6

homebrew-tor

Homebrew formulae for Tor and related. (for "brew tap")
Ruby
12
star
7

iOS-BLE-Tire-Logger

THIS REPO LIVES AT THE FOLLOWING URL NOW: https://0xacab.org/mtigas/iOS-BLE-Tire-Logger β€’β€’β€’β€’β€’β€’ or via tor: http://wmj5kiic7b6kjplpbvwadnht2nh2qnkbnqtcv3dyvpqtz7ssbssftxid.onion/mtigas/iOS-BLE-Tire-Logger
Swift
7
star
8

homebrew-ssldump

SSLdump tool, with some patches to fix compatibility w/OpenSSL
Ruby
5
star
9

cs4970_capstone

Fall 2009 capstone project: A Django-based data app using massive amounts of Census & FBI data.
Python
5
star
10

homebrew-gpg21

LEGACY REPO, NO LONGER SUPPORTED. Use `gnupg21` in `homebrew-versions`.
5
star
11

minutiae

A (rather simple) Django-based blog.
Python
4
star
12

air-playground

I toyed with HTML-based Adobe AIR for a while and this is what I came up with.
JavaScript
3
star
13

radiowut

various fun tinkerings with the Rdio API
Python
3
star
14

hello-propubdata

A GitHub Pages demo for the ProPublica Data Institute
3
star
15

django-gpg-sign-middleware

Django middleware that automatically clearsigns HTML pages with PGP. β€’β€’β€’β€’β€’β€’ THIS REPO LIVES AT THE FOLLOWING URL NOW: https://0xacab.org/mtigas/django-gpg-sign-middleware β€’ or via tor: http://wmj5kiic7b6kjplpbvwadnht2nh2qnkbnqtcv3dyvpqtz7ssbssftxid.onion/mtigas/django-gpg-sign-middleware
Python
3
star
16

hello-django

A super-minimal Django "hello world" example repo.
Python
2
star
17

django-harderhash

A port of django-bcrypt that doesn't use bcrypt, but a slow loop of sha384. Don't use this.
Python
2
star
18

django-hellban

Inspired by drupal-misery and Jeff Atwood's "Suspension, Ban or Hellban" blog post
Python
1
star
19

arch-aur-tor-browser-dev

UNMAINTAINED (was repo mirror for the `tor-browser-dev` Arch Linux AUR pkg)
Shell
1
star
20

nyu2017-week2-collab

learning how to collaborate with some github pages fun
HTML
1
star
21

example_code

How-to's and code examples, usually tied in with my blog.
Python
1
star
22

2015.mozfest.club

CSS
1
star
23

geopy

DOES NOT LIVE HERE ANYMORE: Official github mirror is now at https://github.com/geopy/geopy
Python
1
star
24

hidserv-proxy

Forked from SecureDrop's bootstrap bits. Builds a hardened machine, bootstrapped to provide a tor hidden service proxy to a normal website.
Ruby
1
star