Well, after writing my last blog entry, I decided to take my own advice and created a template project folder for creating these kinds of static CMS websites using the build.py build script.
You can download the template zip here, or you can clone the GitHub repository here.
I decided to call it AYM CMS, with AYM standing for "Ain't Yo Momma's". Or maybe it stands for "All Your Mess". Or something else. Let's go Git on this one and just say it stands for whatever you want it to. It's short and quick to type, which seems most important...
What AYM CMS Gives You
Use the full power of Django templates to create your static websites. From template inheritance and the default Django template tags and filters, to adding your own custom tags/filters as well.
All images you place in the
images/directory will be thumbnailed for free. It also loads all the images into a list and a dictionary that are injected into the template context for rendering.{% for image in images %} <a href="{{ image.image }}"> <img src="{{ image.thumbnail }}" alt="{{ image.filename }}"> </a> {% endfor %} {% with images_dict.my_pic as image %} <img src="{{ image.thumbnail }}"> {% endwith %}
Just add files to
static/and they'll be added to yourdeploy/staticfolder as well, including preserving subfolders.Two custom template tags for making writing static content quicker and more potent:
markdownandsyntax.markdownrenders the enclosed text as Markdown markup. It is used as follows:{% load aym %} <p> I love templates. </p> {% markdown %} Render this **content all in Markdown**. >> Writing in Markdown is quicker than >> writing in HTML. 1. Or at least that is my opinion. 2. What about you? {% endmarkdown %}
syntaxuses Pygments to render the enclosed text with a code syntax highlighter. Usage is:{% load aym %} <p> blah blah blah </p> {% syntax objc %} [obj addObject:[NSNumber numberWithInt:53]]; return [obj autorelease]; {% endsyntax %}
Add additional pages to your site by adding them to
PAGES_TO_RENDERlist in thesettings.pyfile. This means you only render the templates you want, and won't have partial templates hanging around your website.You can add custom template rendering context in both the
settings.pyandbuild.pyfiles. This opens up the doorway to easy customization and time saving scripts that copy additional resources, inject data from other sources, or pretty much anything else your crafty mind can devise.
Let me know if there are any problems with AYM CMS. It is intended to be a generic build script for creating complex static websites, and I think that it is a very sufficient solution for that problem (perhaps even a good solution, if I wanted to stretch a bit).
I realize that fancy dynamic websites are all the rage these days, but I think most of us still have a handful of static websites we maintain (or put together as temporary sites as we develop something more complex), and that AYM CMS can serve that small but important niche admirably.
Let me know if you have any questions, complaints or comments.
I think this is a great solution. I'm currently learning django and have had that itch that was nagging at me. What if I don't need anything dynamic (db driven website), but want to create a static website but don't want to be repeating myself endlessly when using plain old html. This is a nice medium. I'll give it a try...thanks for your work.
Michael,
Glad that it seems useful. I extracted the code from a project I wrote over the weekend, and am already considering going back and redoing my other static sites using it. Luke Hatcher pointed out to me that using Typogrify (a Django app for typography) is a natural combination.
In the same vein, I was considering adding BluePrint to AYM CMS by default, but figured that everyone will likely put together their own project template with the components that matter to them.
This has some interesting utility in creating offline copies of sites as well. I had a crazy project a while back to scrape documentation and other stuff into a Django powered site that I then crawled (via a bit of python) out into static HTML files before putting it onto distributable media. I could have saved a lot of time just using this. (Where were you then, Will?!)
I could also see this being used similarly to Movable Type's static publishing. You can easily add a bit of interactivity by using a hosted comments solution like Disqus on top of your static sites.
(Disclaimer: Disqus is my hammer and everything looks like a nail right now)
Luke,
Sorry that this project came too late to save you. It came too late to save me as well, which is why I finally extracted it into some reusable. I can't count the number of times I've wished I had this tool, but I'm glad I finally spent the hour to package it.
As for your comment about Disqus, I think you're right that projects like Disqus begin to provide some interesting dynamic behavior to 'static' websites. You can do a lot with client side JavaScript.
Something I was thinking about today is that you could use AYM CMS to manage php projects as well, letting projects leverage php for dynamic behavior and Django (templates, filters, tags, etc) for preprocessing. Could be a potent combination.
Hey, this is fantastic! Thank you for releasing this to the community! This is going to help dramatically reduce the annoying and repetitive part of the static sites I do for work.
Thanks!
I like AYM CMS so I modified it so build is a manage command and made it a 'resuable' django app. Even less tested and no tags. I did this because I think most people will have the whole django and just use django-admin to create the project even if there is a lot of django baggage.
Mercurial: https://hachaboob@bitbucket.org/hachaboob/builder/
Michael,
Neat work. There are a lot of interesting possibilities from doing things your way, like using the admin to manage content and a database, and then to just take snapshots via the build command...
I think there are some nice advantages from doing it my way as well. The world will be a better (well, maybe) place with both options available.
Thank you very much for this solution. It was exactly what I needed. After having coded dynamic sites for a long time, it felt very awkward having to code each page separately. Besides, there was the need for automating many repetitive tasks.
One point to mention is that, I think the value of the STATIC_URL_FORMAT in settings.py should be
Reply to this entry