Here's a very big gun, there's your foot: PHP support in Nikola    Posted:


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:

  1. 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'),
    }
    
  2. 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),
    )
    
  3. Create a php post:

    nikola new_post posts/foo.php
    
  4. 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.

Comments

Nikola version 5.4.4 is out!    Posted:


Yes, version 5.4.4 of Nikola, my static site/blog generator is just published at the usual place, including the following improvements:

Features

  • New Japanese translation.
  • Nikola check exists with 1 if there is an error
  • New HIDE_UNTRANSLATED_POSTS option that ensures you don't have mixed-language pages (Issue #373)
  • New theme "site-planetoid" for use with the planetoid plugin.
  • New 'retired' tag for posts that should no longer be in feeds.

Bugfixes

  • Added post data as a uptodate check for mustache (Issue #456)
  • Rebuild post pages when the post's translation list changes (Issue #458)
  • Handle "-h" (Issue #460)
  • Added correct help for console command (Issue #460)
  • Escape twittercard data (Issue #452)
  • Added missing "twittercard" in story template
  • Added support for per-language tags (Issue #450)
  • Fix wrong path splitting (Issue #434)
  • Remember locale even when set_locale failes (Issue #446)
  • Decode path argument in new_post (Issue #442)
  • task_indexes had missing config dependencies (Issue #441)
  • Removed bogus links to slides assets that were removed
  • Compressed files were seen as unknown by "nikola check"
  • local search and mustache plugins must be disabled by default (Issue #437)
  • Avoid failure if there are no tags and USE_GZIP is enabled (Issue #439)
  • Fix aspect ratio detection in Vimeo videos (Issue #440)
  • Blogger importer was passing wrong options to "nikola init" (Issue #408)

Comments

Forget about "incognito mode", use a throwaway browser!    Posted:


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)

Comments

Serbo-Croatian version of PyQt By Example!    Posted:


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!

Comments

Nikola 5.4.3 released!    Posted:


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!

Comments

Using rst2pdf in Different Ways    Posted:


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.

The bad news

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.

Comments

The Password Is password (if you are on a planet or via RSS, follow the link to see what I mean)    Posted:


This post is password-protected.

Comments

Nikola Internals Doc    Posted:


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.

Comments

Are You Using Google's sitemap_gen? Don't.    Posted:


If you are using Google's sitemap_gen to generate a sitemap for your site... don't.

  1. It's abandoned
  2. It's python 2.x only
  3. The code is ghastly
  4. The output it produces is trivial

For example, I just replaced it with ~30 lines of nicer code. and probably so can you.

Comments

Migrating from Wordpress to Nikola    Posted:


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!

Comments

Contents © 2000-2013 Roberto Alsina
Share