Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

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

Un Verificador de links simple para Nikola

Es­te script es un muy sim­ple ve­ri­fi­ca­dor de li­nks que se ase­gu­ra que las pá­gi­nas que Niko­la ge­ne­ra no ten­gan li­nks ro­to­s. Va a ser par­te de Niko­la pro­pia­men­te di­cho una vez que es­té más pu­li­do y doit so­por­te lis­tar los tar­ge­ts

Para probarlo, bajalo y ejecutálo desde el mismo lugar donde está tu conf.py, inmediatamente después de un doit.

import os
import urllib
from urlparse import urlparse

import lxml.html

def analyze(filename):
    try:
        # Use LXML to parse the HTML
        d = lxml.html.fromstring(open(filename).read())
        for l in d.iterlinks():
            # Get the target link
            target = l[0].attrib[l[1]]
            if target == "#":  # These are always valid
                continue
            parsed = urlparse(target)
            # We only handle relative links.
            # TODO: check if the URL points to inside the generated
            # site and check it anyway
            if parsed.scheme:
                continue
            # Ignore the fragment, since the link will still work
            # TODO: check that the fragment is valid
            if parsed.fragment:
                target = target.split('#')[0]
            # Calculate what file or folder this points to
            target_filename = os.path.abspath(
                os.path.join(os.path.dirname(filename), urllib.unquote(target)))
            # Check if it exists, or report it
            if not os.path.exists(target_filename):
                print "In %s broken link: " % filename, target
    except Exception as exc:
        # Something bad happened, report
        print "Error with:", filename, exc

# This is hackish: we use doit to get a list of all
# generated files. Minor modifications would let you check
# the non-generated files as well.

for task in os.popen('doit list --all', 'r').readlines():
    task = task.strip()
    if task.split(':')[0] in (
        'render_tags',
        'render_archive',
        'render_galleries',
        'render_indexes',
        'render_pages',
        'render_site') and '.html' in task:
            # It looks like a generated HTML file
            analyze(task.split(":")[-1])

Nikola 3.0.1 Available for Testing

Ver­sion 3.0.1 of Niko­la my stat­ic site gen­er­a­tor is ready for ini­tial us­er test­ing.

I have merged a bunch of patch­es from Kay Hayen and Kade­for:

  • dis­­qus_de­vel­op­er is gone

  • ad­dthis but­­tons are op­­tion­al (con­trolled by a new op­­tion)

  • You can have more than one stat­ic files fold­er to be merged in­­­to out­­put.

  • Im­age gal­­leries sup­­port up­­per­­case ex­ten­­sion­s.

  • Tem­­plates can not link to CSS that is em­p­­ty/mis­s­ing

  • Bet­ter Google Sitemaps

  • Pre­serve (some) meta­­da­­ta when copy­­ing files, like time­s­tamps

  • Don't over­write ex­ist­ing posts with doit new_­­post

  • Gen­er­ate valid URLs from uni­­code ti­­tles

So, if you want to try it out:

http­s://github.­com/ralsi­na/niko­la/zip­bal­l/3.0.1

I will make it a re­al re­lease if noth­ing bad shows up be­fore sun­day or mon­day.

Eso es un lindo tema.

//ralsina.me/galleries/random/k4y.thumbnail.png

Di­ce el au­tor que lo es­tá pu­lien­do y lo saca en unos día­s.

Nikola es RÁPIDO.

Por su­pues­to que no es­tá pen­sa­do pa­ra si­tios de e-­co­m­mer­ce, pe­ro si es­tás ha­cien­do un si­tio cor­po­ra­ti­vo sim­ple, o tu blo­g, ¿Por qué no ha­cer­lo lo más rá­pi­do po­si­ble?

Así que acá hay un da­to de Kay Ha­yen

http://www.nuitka.net/posts/images/nikola-speed-improvements.png

Adi­vi­ná cuan­do cam­bió a Niko­la

Pe­ro no te­nés por­qué con­fiar en ese grá­fi­co. Acá es­tá el re­por­te de Yahoo YS­low pa­ra es­te si­tio, que es­tá hos­tea­do en un VPS de $5 (i­gual que mis otros si­tio­s. El mis­mo VP­S. Jun­to con otros ser­vi­cio­s. Y mi co­re de Qua­ssel)

http://ubuntuone.com/6Xsg1blhiJK7nEcnhPFOM7

Saca un 94 en ese tes­t. Eso es 94 de 100 pun­tos po­si­bles en el ru­le­s­et "S­ma­ll Si­te or Blo­g".

¿Cuán­to tu­neo tie­ne el ser­ve­r? Le agre­gué una lí­nea a la con­fi­gu­ra­ción de Apa­che:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css

Eso ha­ce que com­pri­ma los ar­chi­vos an­tes de man­dar­los al usua­rio y me­jo­ró el ter­cer item de F a A.

Así que cuan­do te di­go que Niko­la ha­ce si­tios rá­pi­dos no me crea­s, mi­rá­lo.

Nikola 3 is out and it is good.

I just re­leased ver­sion 3 of my stat­ic site gen­er­a­tor, Niko­la

It's a ma­jor re­lease, there is hard­ly any code from the pre­vi­ous ver­sion that was not moved, prod­ded, bro­ken or fixed!

The main fea­tures of Niko­la:

  • Blogs, with tags, feed­s, archives, com­­ments, etc.

  • Themable

  • Fast build­s, thanks to doit

  • Flex­i­ble

  • Small code­base (pro­­gram­mers can un­der­­s­tand all of Niko­la in a few hours)

  • re­Struc­­tured­­Text and Mark­­down as in­­put lan­guages

  • Easy im­age gal­­leries (just drop files in a fold­er!)

  • Syn­­tax high­­­light­ing for al­­most any pro­­gram­ming lan­guage or markup

  • Mul­ti­lin­gual sites

  • Does­n't rein­vent wheel­s, lev­er­ages ex­ist­ing tool­s.

Changes for this re­lease (not ex­haus­tive!):

  • New op­­tion­al tem­­plate ar­gu­­ment for "niko­la init"

  • New "in­stal­l_the­me" task

  • Op­­tion­al ad­­dress op­­tion for the "serve" task

  • Bet­ter look­ing code­blocks

  • Rus­sian tran­s­la­­tion

  • Use mark­­down/reSt com­pil­er based on post ex­ten­­sion

  • Don't fail when there are no post­s/s­­to­ries/­­gal­­leries/­­tags

  • Use con­­fig­u­ra­­tion op­­tions as de­pen­­den­­cies

  • Use more rel­a­­tive links for eas­i­er site rel­lo­ca­­tion

  • Syn­­tax high­­­light for mark­­down

  • Bet­ter mul­ti­­core builds (make the -n 2 or -n 4 op­­tions work)

  • Con­­fig­urable out­­put fold­er

  • Don't fail on posts with pe­ri­ods in the name

  • Dif­fer­­ent page names for dif­fer­­ent lan­guages

  • Rec­og­nize (some) Mako tem­­plate de­pen­­den­­cies

  • Is now a more "nor­­mal" python pack­­age.


Contents © 2000-2020 Roberto Alsina