I am a very big proponent of static site generators. I would not have bothered writing Nikola otherwise. But there is always that feeling that maybe there is some little thing which is hard to implement, like a contact form.
And let's face it, the easiest way to solve some of those things is by sticking a few lines of PHP in your HTML.
So, if you really want to, you can do it. I think Nikola (github master) is the first static site generator that supports php code. Here's how:
Add php to your page_compilers (because I will never put it there by default):
post_compilers = {
"rest": ('.txt', '.rst'),
"markdown": ('.md', '.mdown', '.markdown'),
"textile": ('.textile',),
"txt2tags": ('.t2t',),
"bbcode": ('.bb',),
"wiki": ('.wiki',),
"ipynb": ('.ipynb',),
"html": ('.html', '.htm'),
"php": ('.php'),
}
Add php posts or pages to your post_pages:
post_pages = (
("posts/*.txt", "posts", "post.tmpl", True),
("posts/*.php", "posts", "post.tmpl", True),
("stories/*.txt", "stories", "story.tmpl", False),
("stories/*.php", "stories", "story.tmpl", False),
)
Create a php post:
nikola new_post posts/foo.php
Put php in there:
<!-- .. date: 2013/04/16 09:57:09 .. title: php test .. slug: foo --> <?php Print "Hello, World!"; ?>
Build the site as usual, and you should end up with a page with PHP extension, that has that PHP in the "content" area, so it will follow your site's theme. Of course you can't do things like add HTTP headers and such, but hey, read the title.
Yes, version 5.4.4 of Nikola, my static site/blog generator is just published at the usual place, including the following improvements:
It's not because I wrote it (ok, yes, it's because I wrote it) but if you ever need a "clean" browser, without cookies etc for tests, you can do worse than using my Devicenzo like this:
rm -f ~/.config/ralsina/devicenzo.conf curl https://devicenzo.googlecode.com/svn/trunk/devicenzo.py | python
The first line removes all configuration, cookies, etc, you may have and the second one downloads the latest version (don't worry, it takes about 2 seconds) and launches it.
And voilá, a completely fresh out-of-the-box, webkit-based browser, with no previous history, cookies, or configuration, fairly feature-complete.
Note
this requires you having python and PyQt already installed (which is why devicenzo itself is so tiny)
A while ago I got an email from Anja Skrba asking me for permission to translate PyQt by Example into Serbo-Croatian.
And here it is all nice and translated. Lots of thanks to Anja for the hard work!
I am thrilled to announce the release of version 5.4.3 of Nikola a static website/blog generator.
The changelog is pretty long, more information at the announcement
Have fun!
This was an idea by Dinu Gherman: you can use rst2pdf as a flowable generator for reportlab. Suppose you want to create, in a reportlab "story", a bunch of paragraphs, with emphasis, links, etc, and perhaps a table.
Using restructured text, it's something like this:
This is a paragraph. It has a link: http://rst2pdf.ralsina.com.ar and then some random text. +-------------+---------------------------+ | A table | With cells | | | | | | | | | | | | | +-------------+---------------------------+ | And inside | | it some | | more text | | | | | +-----------------------------------------+ * And a list * Just to make it harder + with a nested item here
It is, of course, perfectly possible to generate a bunch of reportlab (or rather platypus) flowables to represent all this. It will just mean some 75 lines of code. And if you change anything, then you have to edit code!
Or you can take advantage of rst2pdf and do this:
from docutils.core import publish_doctree from rst2pdf.createpdf import RstToPdf from reportlab.lib.units import cm from reportlab.pdfgen.canvas import Canvas from reportlab.platypus import Frame rest_text = """ This is a paragraph. It has a link: http://rst2pdf.ralsina.com.ar and then some random text. +-------------+---------------------------+ | A table | With cells | | | | | | | | | | | | | +-------------+---------------------------+ | And inside | | it some | | more text | | | | | +-----------------------------------------+ * And a list * Just to make it harder + with a nested item here """ r2p = RstToPdf() doctree = publish_doctree(rest_text) story = r2p.gen_elements(doctree) canv = Canvas("platypus-rest.pdf") f = Frame(2 * cm, 2 * cm, 16 * cm, 18 * cm, showBoundary=True) f.addFromList(story, canv) canv.save()
This produces this pdf. And of course editing it is rather easier than editing code. Since you are not using rst2pdf to do the final PDF generation, you can use these flowables in your own documents.
Some things will not work, like headings, since rst2pdf creates flowables that do a ton of things like adding themselves on indexes and such. If you want a heading-like thing you can use classes:
.. class:: heading1 This will look like a heading This is a regular paragraph.
Other random restructured text features may or may not work, like footnotes or citations.
Since Nikola, my static blog/website generator is getting a substantial amount of code from others, I thought it may be a good idea to roughly document how it works internally. So, here is Nikola internals which is very much a work in progress.
If you are using Google's sitemap_gen to generate a sitemap for your site... don't.
For example, I just replaced it with ~30 lines of nicer code. and probably so can you.
Several people have migrated from Wordpress into Nikola, and here are some of their descriptions of the process:
In general, it seems to be working, but there's some work still to be done. Wordpress supports many different plugins and extensions which react to markup in their pages, and supporting that's almost an infinite task. Currently Nikola's importer handles a few of the more common. But if you try to import your blog and get less than ideal results, please file a bug and I'll do my best to fix it.
Usually the fixes are rather simple, it's just that I have never seen that specific thing ;-)
Have fun!