Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

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

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]

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.

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!


Contents © 2000-2024 Roberto Alsina