Skip to main content

Ralsina.Me — Roberto Alsina's website

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

I am a very big pro­po­nent of stat­ic site gen­er­a­tors. I would not have both­ered writ­ing Niko­la oth­er­wise. But there is al­ways that feel­ing that maybe there is some lit­tle thing which is hard to im­ple­men­t, like a con­tact for­m.

And let's face it, the eas­i­est way to solve some of those things is by stick­ing a few lines of PHP in your HTM­L.

So, if you re­al­ly want to, you can do it. I think Niko­la (github mas­ter) is the first stat­ic site gen­er­a­tor that sup­ports php code. Here's how:

  1. Add php to your page_­com­pil­ers (be­cause I will nev­er put it there by de­fault­):

    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. Cre­ate 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 usu­al, and you should end up with a page with PHP ex­ten­sion, that has that PHP in the "con­tent" area, so it will fol­low your site's theme. Of course you can't do things like add HTTP head­ers and such, but hey, read the ti­tle.

Nikola version 5.4.4 is out!

Yes, ver­sion 5.4.4 of Niko­la, my stat­ic site/blog gen­er­a­tor is just pub­lished at the usu­al place, in­clud­ing the fol­low­ing im­prove­ments:

Features

  • New Ja­­pa­­nese tran­s­la­­tion.

  • Niko­la check ex­ists with 1 if there is an er­ror

  • New HIDE_UN­­TRAN­S­LAT­ED_­­POSTS op­­tion that en­­sures you don't have mixed-lan­guage pages (Is­­sue #373)

  • New theme "site-­­plan­e­­toid" for use with the plan­e­­toid plug­in.

  • New 're­tired' tag for posts that should no longer be in feed­s.

Bugfixes

  • Added post da­­ta as a up­­­to­­date check for mus­­tache (Is­­sue #456)

  • Re­build post pages when the post's tran­s­la­­tion list changes (Is­­sue #458)

  • Han­­dle "-h" (Is­­sue #460)

  • Added cor­rect help for con­­sole com­­mand (Is­­sue #460)

  • Es­­­cape twit­ter­­card da­­ta (Is­­sue #452)

  • Added mis­s­ing "twit­ter­­card" in sto­ry tem­­plate

  • Added sup­­port for per-lan­guage tags (Is­­sue #450)

  • Fix wrong path split­t­ing (Is­­sue #434)

  • Re­mem­ber lo­­cale even when set_lo­­cale failes (Is­­sue #446)

  • De­­code path ar­gu­­ment in new_­­post (Is­­sue #442)

  • task_in­dex­es had mis­s­ing con­­fig de­pen­­den­­cies (Is­­sue #441)

  • Re­­moved bo­­gus links to slides as­sets that were re­­moved

  • Com­­pressed files were seen as un­­known by "niko­la check"

  • lo­­cal search and mus­­tache plug­ins must be dis­­abled by de­­fault (Is­­sue #437)

  • Avoid fail­ure if there are no tags and USE_GZIP is en­abled (Is­­sue #439)

  • Fix as­pect ra­­tio de­tec­­tion in Vimeo videos (Is­­sue #440)

  • Blog­ger im­­porter was pass­ing wrong op­­tions to "niko­la init" (Is­­sue #408)

Boneshaker (The Clockwork Century, #1)

Review:

Nice steam­punk, even if half the physics make no sense what­so­ev­er (like, the blight be­ing heav­ier than air yet it flow­ing up from the ground, and ev­ery­one liv­ing un­der­ground).

I am go­ing to fol­low the se­ries at least.

Every Day (Every Day, #1)

Review:

A very ten­der book. I like that it does­n't try to ex­plain the pe­cu­liar na­ture of the main char­ac­ter. I'll have my kid read it when he's 12 or so.


Contents © 2000-2020 Roberto Alsina