Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Publicaciones sobre nikola (publicaciones antiguas, página 13)

Nikola Themes Repo is Now Official

Des­de ha­ce unos mi­nu­to­s, el co­man­do "ins­ta­ll_­the­me" de Niko­la gi­thub mas­ter saca los te­mas de http://­the­me­s.­niko­la.­ral­si­na.­me

Así que de gol­pe, en vez de 2 te­mas pa­ra ba­ja­r, hay 65 (aun­que la ma­yo­ría son va­ria­cio­nes via bootswa­tch de 2 te­ma­s, jin­ja-­de­fault es iden­ti­co a de­faul­t, y or­phan no sir­ve pa­ra na­da ;-)

¡Y aho­ra po­dés con­tri­buir te­ma­s! ¿Có­mo?

  1. Da­­me un pu­­ll re­­quest en http­s://­­gi­­thu­­b.­­co­­­m/­­ra­l­­si­­na/­­niko­­­la-­­the­­mes

    Po­­­né tu te­­ma en the­­me­s/ y man­­dá el pu­­ll re­­quest

  2. Man­­dá­­me un zip de tu te­­ma y yo lo agre­­go

Los te­mas con­tri­bui­dos van a tar­dar un ra­to en apa­re­cer por­que hay que re­vi­sar­los pa­ra sa­ber que no tie­nen có­di­go ma­li­cio­so, pe­ro los voy a pro­ce­s­ar, len­to pe­ro se­gu­ro. Si ya me man­das­te un te­ma y nun­ca lo pu­se en nin­gún la­do, te pi­do dis­cul­pas y que en­cuen­tres las ga­nas de in­ten­tar de nue­vo :-)

El si­tio de te­mas en sí no es exac­ta­men­te her­mo­so, pe­ro es fun­cio­na­l, y po­dés ba­jar los te­mas de ahí, ver si­tios de de­mo pa­ra ca­da te­ma, y has­ta hay screens­ho­ts au­to­ge­ne­ra­dos (que la­men­ta­ble­men­te no mues­tran los we­bfon­ts)

MinCSS is amazing

I had this is­sue open in the bug tra­cker for Niko­la (my sta­tic si­te ge­ne­ra­to­r) for a long ti­me: "A­dd min­css su­ppor­t".

We­ll, no, it does­n't ha­ve it ye­t, but I did so­me re­sear­ch on whe­ther it would be wor­th addin­g. And bo­y, min­css im­press­ed the he­ck out of me.

You see, Niko­la's the­mes tend to use una­dul­te­red boots­tra­p, whi­ch means they ca­rry a lar­ge num­ber of things that are not us­ed in their CSS. Be­si­des, it uses se­ve­ral sty­les­hee­ts from do­cu­til­s, pyg­men­ts, and mo­re.

What min­css does is exa­mi­ne your HT­ML and your CSS, and re­mo­ve all the unu­s­ed CSS. So, I wro­te a script that exa­mi­nes the Niko­la ou­tput and ove­rw­ri­tes the CSS fi­les wi­th the mi­ni­mal things that are ac­tua­lly nee­ded the­re.

And the re­sul­t?

He­re is the be­fo­re/a­fter for ea­ch CSS fi­le in Niko­la's de­mo si­te:

bootstrap-responsive.min.css  16849  3251
bootstrap.min.css            106059 14737
code.css                       3670  2114
colorbox.css                   6457   774
rst.css                        6559  2581
theme.css                      1287  1061
-----------------------------------------
                             140881 24518

But wai­t, Niko­la su­ppor­ts bund­ling all tho­se fi­les in­to a sin­gle lar­ge CSS fi­le to avoid ne­two­rk re­ques­ts (u­sing we­ba­sse­ts). Does it wo­rk in that ca­se too?

We­ll ye­s:

all-nocdn.css                167457 29496

But that is not all. The min­css fi­les are not mi­ni­fie­d. Pa­s­sing all-­no­cd­n.­css th­rou­gh Yui-­com­pres­sor sh­ri­nks it fur­ther to 20599 by­tes. Whi­ch, gzi­ppe­d, is a pal­try 4801 by­tes. That means the com­ple­te sty­ling of the who­le si­te is a sin­gle CSS fi­le le­ss than 5KB in si­ze.

Tha­t, is im­pres­si­ve.

(Re)Introducing Alva, a Nikola Server

Over a year ago (ti­me flie­s!) I pos­ted so­me­thing about a pro­ject ca­lled Al­va. Let me quo­te mysel­f:

Al­va is al­most the oppo­si­te of Niko­la. If Niko­la is about making sta­tic si­tes, Al­va is a dy­na­mic si­te. Ho­we­ve­r, as He­gel su­gges­ts, from the the­sis and the an­ti­the­sis co­mes the syn­the­sis.

So, Al­va is about dy­na­mi­ca­lly crea­ting sta­tic si­tes. If you want to ha­ve Niko­la in your ser­ver ins­tead of in your own com­pu­te­r, and ha­ve the con­ve­nien­ce of an on­li­ne tool, tha­t's the ni­che Al­va tries to fi­ll.

So, you would ins­ta­ll Al­va, and use it like any other we­b-­ba­sed blo­gging tool. Ye­t, be­hind the sce­nes, you would ha­ve Niko­la, and all the per­for­man­ce and se­cu­ri­ty be­ne­fi­ts of sta­tic si­tes.

And ma­y­be so­me­da­y, I (or so­meo­ne) wi­ll put up a mul­ti-u­ser ver­sion of Al­va, and you wi­ll be able to get hos­ted blogs, kno­wing all the da­ta is yours and you can lea­ve an­y­ti­me and do your own thin­g.

The appro­ach I was taking at the ti­me pro­ved to be un­suc­ce­ss­fu­l, and the­re we­re a few other fai­lu­res along the wa­y. Of cour­se, the pro­blem was in how I was appro­aching the ta­sk. So I did the ri­ght thin­g, and lear­ned how to do it "ri­gh­t".

Sti­ll not usa­ble, sti­ll not hos­ted an­ywhe­re, but al­ready se­mi-­func­tio­na­l: Al­va li­ves now

The­re's a lot of wo­rk sti­ll to be do­ne. But I now know how to do it. To pre­vent the usual ar­gu­men­ts, he­re is a li­ttle ex­pla­na­tion of mo­ti­va­tio­n, toolin­g, etc.

Motivation

I want a way to host blogs ve­ry chea­pl­y. How chea­pl­y? I want at least 1000 rea­so­na­bly ac­ti­ve users in a $5 VP­S. That would make Al­va a rea­so­na­ble al­ter­na­ti­ve to hos­ted mul­ti-u­ser wor­dpress, whi­ch means it would be a rea­so­na­ble so­lu­tion (if se­tup is ea­sy enou­gh) for sma­ll-­to­-­me­dium or­ga­ni­za­tions whi­ch do­n't want to se­tup ex­pen­si­ve in­fras­truc­tu­re yet want to own their da­ta (thi­nk school­s, sma­ll bu­si­nesses, FLO­SS pro­jec­ts, etc.) I al­so want to pro­vi­de that ser­vi­ce, for free. Whi­ch is why ano­ther rea­son I want it to be su­per chea­p.

How does Al­va help pro­vi­de this su­pe­r-­cheap blog hos­tin­g?

  1. It nee­­ds to sca­­le fo­­­llo­­wing the nu­m­­ber of edi­­ts not views.

  2. If it ge­­ts too busy wi­­th edi­­ts, chan­­ges take lo­n­­ger to appea­­r, but the si­­te itself does­n't get any slo­­we­­r.

  3. Edi­­ting and se­r­­ving can be pro­­­vi­­ded by se­­pa­­ra­­te se­r­­vi­­ce­s, so I can use so­­­me su­­pe­­r-­­fast sta­­tic fi­­le se­r­­ver and a su­­pe­­r-­­co­n­­fi­­gu­­ra­­ble WS­­GI de­­plo­­­y­­men­­t.

  4. In­­di­­vi­­dual pa­­ges can be hea­­vi­­ly op­­ti­­mi­­zed so that they do­­wn­­load fast

Tools

One of the gui­ding prin­ci­ples he­re is that to de­li­ver this sort of thin­g, in my spa­re ti­me, the de­ve­lo­p­ment pro­ce­ss nee­ds to be stin­gy wi­th the most li­mited re­sour­ce: me. I can't spend a lot of me he­re. I need to be ca­re­ful and not ove­r-­pro­mi­se.

So, whe­ne­ver the­re was a 3r­d-­par­ty tool that saves a sig­ni­fi­cant amount of ti­me, tha­t's what I am usin­g.

Django

Be­cau­se it has a mu­ch stron­ger 3r­d-­par­ty tool­set than Fla­sk or any mi­cro­-­fra­mewo­rk. For exam­ple, the Fla­sk equi­va­lent of djan­go­-a­llau­th bro­ke my wi­ll to li­ve. Be­cau­se the ad­min in­ter­fa­ce means I can start adding da­ta to see if it makes sen­se be­fo­re I wri­te all the re­qui­red views.

Django-allauth

Be­cau­se I do­n't want you to ha­ve to crea­te ac­coun­ts he­re un­le­ss you want to, this pro­vi­des (op­tio­nal) so­cial lo­gin and re­gis­tra­tio­n. This was ea­sy to se­tup and wo­rks al­m­sost ou­t-o­f-­the-­box

Bootstrap and Django-bootstrap-toolkit

Niko­la is al­ready hea­vi­ly in­ves­ted in boots­tra­p, so it just ma­de sen­se to go fur­ther do­wn that road. I un­ders­tand boots­tra­p, and djan­go­-­boos­tra­p-­toolkit is ea­sy enou­gh (al­thou­gh I can't make their date­pi­cker wo­rk)

Django-datetime-widget

Be­cau­se fi­gh­ting is bo­rin­g.

Django-debug-toolbar

Be­cau­se Djan­go­'s me­cha­nis­ms to find tem­pla­tes and sta­tic fi­les are many and con­fu­se me.

Redis + RQ + django-rq

It's crucial for the whole approach to use job queues in order to detach the rendering from the actual Django app. This combination makes job dispatching ridiculously easy, setup is trivial (install everything, start redis, a few lines of config, ./manage.py rqworker and off you go) and they provide a django admin page where I can see the failed jobs, which is awesome.

South

Be­cau­se it's ea­sy enou­gh, and allo­ws me so­me free­dom ex­plo­ring da­ta or­ga­ni­za­tion in my mo­dels wi­thout co­m­mi­tting to it fo­re­ver or re­crea­ting da­ta­ba­ses wi­th test da­ta all the ti­me.

Gatling

I wi­ll pro­ba­bly ser­ve the ge­ne­ra­ted si­tes via ga­tling just like my cu­rrent si­tes be­cau­se it has the sim­plest na­med do­main con­fi­gu­ra­tion po­s­si­ble, it's fast and ve­ry li­ght in re­sour­ce usage.

Markitup

A cool, sim­ple edi­tor wi­th li­ve pre­views that su­ppor­ts al­most eve­ry ma­rku­p. Not WY­SIW­YG or even WY­SIW­YM so po­s­si­bly I wi­ll ha­ve to add an al­ter­na­ti­ve. I started using djan­go­-­ma­rki­tup but it's not a good idea (it uses a old ver­sion of ma­rki­tup whi­ch re­qui­res JQue­ry < 1.9) and am in the pro­ce­ss of just using Ma­rki­tup ma­nua­ll­y.

So, feel free to gi­ve Al­va a try an­d/or gi­ve me a han­d, co­m­men­ts wel­co­me.

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

I am a ve­ry big pro­po­nent of sta­tic si­te ge­ne­ra­tor­s. I would not ha­ve bo­the­red wri­ting Niko­la othe­rwi­se. But the­re is alwa­ys that fee­ling that ma­y­be the­re is so­me li­ttle thing whi­ch is hard to im­ple­men­t, like a con­tact for­m.

And le­t's fa­ce it, the ea­siest way to sol­ve so­me of tho­se things is by sti­cking a few li­nes of PHP in your HT­M­L.

So, if you rea­lly want to, you can do it. I thi­nk Niko­la (gi­thub mas­te­r) is the first sta­tic si­te ge­ne­ra­tor that su­ppor­ts php co­de. He­re's ho­w:

  1. Add php to your pa­ge_­com­pi­lers (be­cau­se I wi­ll ne­ver put it the­re by de­faul­t):

    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 pos­ts or pa­ges to your pos­t_­pa­ges:

    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. Crea­te a php pos­t:

    nikola new_post posts/foo.php
  4. Put php in the­re:

    <!--
    .. date: 2013/04/16 09:57:09
    .. title: php test
    .. slug: foo
    -->
    
    <?php
    Print "Hello, World!";
    ?>

Build the si­te as usua­l, and you should end up wi­th a pa­ge wi­th PHP ex­ten­sio­n, that has that PHP in the "con­ten­t" area, so it wi­ll fo­llow your si­te's the­me. Of cour­se you can't do things like add HTTP hea­ders and su­ch, but he­y, read the ti­tle.

Nikola version 5.4.4 is out!

Ye­s, ver­sion 5.4.4 of Niko­la, my sta­tic si­te/­blog ge­ne­ra­tor is just pu­blis­hed at the usual pla­ce, in­clu­ding the fo­llo­wing im­pro­ve­men­ts:

Features

  • New Ja­­pa­­ne­­se tran­s­­la­­tio­­n.

  • Niko­­­la che­­ck exis­­ts wi­­th 1 if the­­re is an error

  • New HI­­DE_UN­­TRAN­S­­LA­TE­­D_­­PO­S­­TS op­­tion that en­­su­­res you do­­n't ha­­ve mixe­­d-­­lan­­gua­­ge pa­­ges (Is­­sue #373)

  • New the­­me "si­­te-­­pla­­ne­­toi­­d" for use wi­­th the pla­­ne­­toid plu­­gi­n.

  • New 're­­ti­­re­­d' tag for po­s­­ts that should no lo­n­­ger be in fee­­d­s.

Bugfixes

  • Added post da­­ta as a up­­to­­­da­­te che­­ck for mus­­ta­­che (Is­­sue #456)

  • Re­­build post pa­­ges when the po­s­­t's tran­s­­la­­tion list chan­­ges (Is­­sue #458)

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

  • Added co­­­rrect help for co­n­­so­­­le co­­­m­­mand (Is­­sue #460)

  • Es­­ca­­pe twi­­tte­r­­card da­­ta (Is­­sue #452)

  • Added mis­­sing "twi­­tte­r­­ca­r­­d" in sto­­­ry te­m­­pla­­te

  • Added su­­pport for pe­­r-­­lan­­gua­­ge tags (Is­­sue #450)

  • Fix wrong pa­­th spli­­tting (Is­­sue #434)

  • Re­­me­m­­ber lo­­­ca­­le even when se­­t_­­lo­­­ca­­le fai­­les (Is­­sue #446)

  • De­­co­­­de pa­­th ar­­gu­­ment in new_­­post (Is­­sue #442)

  • ta­sk_i­n­­dexes had mis­­sing co­n­­fig de­­pen­­den­­cies (Is­­sue #441)

  • Re­­mo­­­ved bo­­­gus li­nks to sli­­des asse­­ts that we­­re re­­mo­­­ved

  • Co­m­­press­ed fi­­les we­­re seen as unk­­no­­wn by "niko­­­la che­­ck"

  • lo­­­cal sea­r­­ch and mus­­ta­­che plu­­gins must be di­s­a­­bled by de­­fault (Is­­sue #437)

  • Avoid fai­­lu­­re if the­­re are no tags and USE_­G­­ZIP is ena­­bled (Is­­sue #439)

  • Fix as­­pect ra­­tio de­­te­c­­tion in Vi­­meo vi­­deos (Is­­sue #440)

  • Blo­­­gger im­­po­r­­ter was pa­s­­sing wrong op­­tions to "niko­­­la ini­­t" (Is­­sue #408)


Contents © 2000-2020 Roberto Alsina