Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

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

Soporte de Twitter Cards en Nikola

Es­te fea­tu­re de Niko­la la im­ple­men­tó @a­mo­k­le­be­n, y aho­ra, si se lo pe­dís a twi­tter tu si­tio pue­de te­ner­lo.

¿Qué son las Twi­tter Car­d­s? ¿Vis­te que pa­ra al­gu­nos si­tio­s, si cli­queás en un tweet que tie­ne un li­nk ves un pre­view chi­qui­to del con­te­ni­do? Bue­no, eso es una twi­tter car­d.

To­da­vía hay que me­jo­rar­lo un po­co pa­ra so­por­tar "me­dia" car­d­s, pe­ro fun­cio­na:

//ralsina.me/galleries/random/twitter-card.png

Sí, esa es una ima­gen del twi­tter card de es­te pos­t. ¿Muy me­ta, no?

No te­nés que ha­cer na­da, pe­ro es­cri­bir el me­ta­da­ta "des­crip­tio­n" ayu­da a ha­cer­la más pre­ci­sa (Y tam­bién fun­cio­na con Google+).

Nikola 5.4 is out!

I am th­ri­lled to an­noun­ce the re­lea­se of ver­sion 5.4 of Niko­la, a sta­tic si­te/­blog ge­ne­ra­tor

He­re's the (in­com­ple­te!) chan­ge­log for this re­lea­se 1:

Features

  • Twi­­tter Card / Open Gra­­ph su­­ppo­r­­t.

  • Smart ma­­th su­­pport

  • New soun­­dcould di­­re­c­­ti­­ve

  • Cus­­tom "read mo­­­re" li­nks

  • Be­­­tter ti­­me dis­­pla­­y, ti­­me­­zo­­­ne su­­pport

  • Be­­­tter doit in­­te­­gra­­tion (Is­­sue #151)

  • Make the who­­­le lis­­tings fo­l­­der bro­­ws­a­­ble (Is­­sue #128)

  • New GZI­­P_­­FI­­LE­S/­G­­ZI­­P_EX­­TEN­­SIONS op­­tions to crea­­te gzi­­pped co­­­pies of so­­­me fi­­les (Is­­sue #348)

  • New op­­tio­­­nal pa­­th pa­­ra­­me­­ter to new_­­post co­­­m­­man­­d.

  • Wo­r­­dpress im­­po­r­­te­­r: op­­tion to not do­­wn­­load fi­­les

  • Wo­r­­dpress im­­po­r­­te­­r: op­­tion to squash new­­li­­nes

  • Se­­pa­­ra­ted BLO­­­G_URL in­­to SI­­TE_URL and BA­SE_URL

  • Added DI­S­A­­BLE­­D_­­PLU­­GINS op­­tion (Is­­sue #354)

Bugfixes

  • Added mis­­sing </­­di­­v> in de­­fault the­­me te­m­­pla­­tes.

  • Wo­r­­dpress im­­po­r­­t: Des­­cri­p­­tion is le­­ft em­p­­ty if no des­­cri­p­­tion is foun­­d.

  • When run­­ning the build co­­­m­­mand it is now po­­s­­si­­ble to get he­l­­p.

  • Load jQue­­ry be­­­fo­­­re boots­­trap in JS bun­d­­le (Is­­sue #327)

  • Ge­­ne­­ra­­te va­­lid HT­­M­­L5 for re­­di­­re­c­­ts (Is­­sue #276)

  • Fixed "niko­­­la che­­ck"

  • Fixed in­­te­r­­na­­tio­­­na­­li­­zed RSS li­nks

  • Make co­­­m­­man­­ds that need to be run in a si­­te fail gra­­ce­­fu­­lly (Is­­sue #342)

  • Use lo­­­ca­­li­­zed li­nks on lx­­ml fixer

  • Re­­di­­re­c­­tions created du­­ring the im­­port from wo­r­­dpress are now wri­­tten to co­n­­f.­­py

  • Stop pa­r­­sing me­­ta­­da­­ta in post fi­­le on first blank li­­ne

  • Me­­ta­­da­­ta han­d­­ling clea­­nups by To­r­­dek

  • Fixed blo­­­ck­­quo­­­te font si­­ze in­­co­n­­sis­­ten­­cy

  • Wo­r­­dpress Im­­po­r­­t: Do not break in­­den­­ta­­tion (is­­sue #189)

  • Make things wo­­­rk even if SI­­TE_URL has a pa­­th (Fix #307)

1

The­re are al­so so­me ex­tra bi­ts of do­cu­men­ta­tio­n, and a awe­so­me be­ta the­me ca­lled "si­te-­re­vea­l" ba­sed on boots­trap and re­vea­l.­js!

Creating a Site (Not a Blog) with Nikola

One of the most fre­quent ques­tions I get about Niko­la is "but how do I crea­te a si­te tha­t's not a blo­g?". And of cour­se, tha­t's be­cau­se the do­cu­men­ta­tion is hea­vi­ly blo­g-o­rien­te­d. This do­cu­ment wi­ll chan­ge that ;-)

Sin­ce it starte­d, Niko­la has had the ca­pa­bi­li­ties to crea­te ge­ne­ric si­tes. For exam­ple, Niko­la's own si­te is a fair­ly ge­ne­ric one. Le­t's go step by step on how you can do so­me­thing like tha­t.

As usual when starting a nikola site, you start with nikola init which creates a empty semi-configured site:

$ nikola init mysite
Created empty site at mysite.

Then we go into the new mysite folder, and make the needed changes in the conf.py configuration file:

##############################################
# Configuration, please edit
##############################################


# Data about this site
BLOG_AUTHOR = "Roberto Alsina"
BLOG_TITLE = "Not a Blog"
# This is the main URL for your site. It will be used
# in a prominent link
SITE_URL = "http://notablog.ralsina.me"
BLOG_EMAIL = "ralsina@kde.org"
BLOG_DESCRIPTION = "This is a demo site (not a blog) for Nikola."

#
# Some things in the middle you don't really need to change...
#

post_pages = (
    ("pages/*.txt", "", "story.tmpl", False),
)

And now we are ready to crea­te our first pa­ge:

$ nikola new_post -p
Creating New Post
-----------------

Enter title: index
Your post's text is at:  pages/index.txt

No­ta

The -p option in the nikola new_post command means we are creating a page and not a blog post.

We can now build and pre­view our si­te:

$ nikola build
Scanning posts.done!
.  render_site:output/categories/index.html
.  render_sources:output/index.txt
.  render_rss:output/rss.xml
:
:
: [Much more of the same]

$ nikola serve
Serving HTTP on 127.0.0.1 port 8000 ...

And you can see your (ve­ry emp­ty) si­te in http://­lo­calhos­t:8000

So, what's in that pages/index.txt file?

.. title: index
.. slug: index
.. date: 2013/03/01 10:26:17
.. tags:
.. link:
.. description:


Write your post here.

Title is the page title, slug is the name of the generated HTML file (in this case it would be index.html) the date doesn't matter much in not-blogs, same for tags and link. Description is useful for SEO purposes if you care for that.

And be­lo­w, the con­ten­t. By de­fault you are ex­pec­ted to use reS­truc­tu­red text but Niko­la su­ppor­ts a ton of for­ma­ts, in­clu­ding Ma­rk­do­wn, plain HT­M­L, BB­Co­de, Wiki, and Tex­ti­le.

So, le­t's gi­ve the pa­ge a ni­cer ti­tle, and so­me fake con­ten­t. Sin­ce the de­fault Niko­la the­me (ca­lled "si­te") is ba­sed on boots­trap you can use an­y­thing you like from it:

.. title: Welcome To The Fake Site
.. slug: index
.. date: 2013/03/01 10:26:17
.. tags:
.. link:
.. description: Fake Site version 1, welcome page!


.. class:: hero-unit span6

.. admonition:: This is a Fake Site

    It pretends to be about things, but is really just an example.
    So, don't click this button, it leads nowhere.

    .. class:: btn

    Click Me!


.. class:: span5

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris non nunc turpis.
Phasellus a ullamcorper leo. Sed fringilla dapibus orci eu ornare. Quisque
gravida quam a mi dignissim consequat. Morbi sed iaculis mi. Vivamus ultrices
mattis euismod. Mauris aliquet magna eget mauris volutpat a egestas leo rhoncus.
In hac habitasse platea dictumst. Ut sed mi arcu. Nullam id massa eu orci
convallis accumsan. Nunc faucibus sodales justo ac ornare. In eu congue eros.
Pellentesque iaculis risus urna. Proin est lorem, scelerisque non elementum at,
semper vel velit. Phasellus consectetur orci vel tortor tempus imperdiet. Class
aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos
himenaeos.

[And more in the same vein]

TI­P: Ni­ce URLs

If you like your URLs without the ".html" then you want to create folders and put the pages in index.html inside them. Example:

nikola new_post -p pages/foo/index.txt

whi­ch wi­ll crea­te a pa­ge you could ac­ce­ss as "http://­your­si­te.­co­m/­foo"

And that's it. You will want to change the SIDEBAR_LINKS option to create a reasonable "menu" for your site, you will want to hack the theme (check nikola help bootswatch_theme for a quick & dirty solution), and you may want to add a blog later on, for company news or whatever.

TI­P: So, how do I add a blog no­w?

First, change the post_pages option like this:

post_pages = (
    ("pages/*.txt", "", "story.tmpl", False),
    ("posts/*.txt", "blog", "post.tmpl", True),
)

And to avoid a conflict (because blogs try to generate /index.html:

INDEX_PATH = "blog"

Create a post with nikola new_post and that's it, you now have a blog in http://yoursite.com/blog (you may want to add links to it in SIDEBAR_LINKS of course).

You can see the fi­nis­hed si­te in http://­no­ta­blo­g.­ral­si­na.­me and its fu­ll con­fi­gu­ra­tion in //­ral­si­na.­me/­lis­tings/­no­ta­blo­g/­con­f.­p­y.ht­ml

I ho­pe this was hel­pfu­l!

Load Testing Nikola

Niko­la ge­ne­ra­tes sta­tic si­tes, so load tes­ting it is not ve­ry in­te­res­tin­g, ex­cept as a ben­ch­ma­rk for the di­ffe­ren­ce be­tween sta­tic and dy­na­mic si­tes.

To­day I was told about bli­tz.io and sin­ce a qui­ck test is free, I thou­gh­t, why no­t? The re­sult is qui­te im­pres­si­ve: a cheap VP­S, using ga­tling as a web ser­ve­r, whi­ch is al­most con­fi­gu­ra­tio­n-­free and not meant for ex­tre­me­ly hi­gh load­s, can hand­le rou­gh­ly 9 mi­llion dai­ly hi­ts.

Let me say that agai­n: 9 mi­llion hi­ts. On a un­con­fi­gu­red $5 ser­ve­r. He­re's the re­port

How mu­ch tu­ning does it take for a wor­dpress ins­tan­ce to ser­ve tha­t? On what har­dwa­re?

And tha­t's on­ly half the pic­tu­re. Not on­ly are Niko­la's sta­tic pa­ges in­cre­di­bly li­ght on your ser­ve­r, we ha­ve al­so spent a lot of effort tr­ying to make in­di­vi­dual pa­ges load fas­t, for a be­tter user ex­pe­rien­ce. So­me of the te­ch­ni­ques us­ed for fas­t-­loading si­tes are:

  • Using we­­ba­sse­­ts to bun­d­­le CSS and JS in­­to si­n­­gle fi­­le­s.

  • Au­­to­­­ma­­tic su­­pport for CD­Ns for the co­­­m­­mon JS li­­bra­­ries

  • Su­­pport for tran­s­­pa­­ren­­tly using HT­­M­­L/­­CSS/­­JS/I­­ma­­ge co­m­­pres­­sion tools

So, if you try so­me­thing like YS­lo­w! on a Niko­la si­te, it wi­ll gi­ve you a sco­re of rou­gh­ly 93 up to 98 (out of 100) de­pen­ding on your web­ser­ver con­fi­gu­ra­tio­n.

BTW: I rea­lly want to get that up to 100. Rea­lly want it

So, re­mem­be­r, if your si­te can be ser­ved sta­ti­ca­ll­y, it's going to be chea­pe­r, fas­te­r, safe­r. And if you ever get 9 mi­llion hi­ts a da­y, it wi­ll be avai­la­ble.

Disclaimer:

Bli­tz.io is sen­ding me a t-s­hirt ;-)

New Nikola Tutorial

Tim van der Lin­den es­cri­bió un tu­to­rial im­pre­sio­nan­te acer­ca de có­mo usó Niko­la pa­ra crear su nue­vo si­tio shi­saa.­jp

Do­cu­men­ta to­do el pro­ce­so des­de ins­ta­lar Niko­la has­ta ha­cer su pro­pio te­ma.

Aún si ve­nís usan­do Niko­la ca­paz que ves al­go nue­vo así que va­le la pe­na leer­lo (a­par­te el te­ma que hi­zo es muy bo­ni­to :-)


Contents © 2000-2020 Roberto Alsina