/
manual.txt
1905 lines (1384 loc) · 70.9 KB
/
manual.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.. title: The Nikola Handbook
.. slug: handbook
.. date: 2012-03-30 23:00:00 UTC-03:00
.. tags: mathjax
.. link:
.. description:
The Nikola Handbook
===================
:Version: 7.3.1
.. class:: alert alert-info pull-right
.. contents::
All You Need to Know
--------------------
After you have Nikola `installed <#installing-nikola>`_:
Create a empty site (with a setup wizard):
``nikola init mysite``
You can create a site with demo files in it with ``nikola init --demo mysite``
The rest of these commands have to be executed inside the new ``mysite`` folder.
Create a post:
``nikola new_post``
Edit the post:
The filename should be in the output of the previous command.
Build the site:
``nikola build``
Start the test server:
``nikola serve``
See the site:
http://127.0.0.1:8000
That should get you going. If you want to know more, this manual will always be here
for you.
DON'T READ THIS MANUAL. IF YOU NEED TO READ IT I FAILED, JUST USE THE THING.
On the other hand, if anything about Nikola is not as obvious as it should be, by all
means tell me about it :-)
What's Nikola and what can you do with it?
------------------------------------------
Nikola is a static website and blog generator. The very short explanation is
that it takes some texts you wrote, and uses them to create a folder full
of HTML files. If you upload that folder to a server, you will have a
rather full-featured website, done with little effort.
It's original goal is to create blogs, but it supports most kind of sites, and
can be used as a CMS, as long as what you present to the user is your own content
instead of something the user generates.
Nikola can do:
* A blog (`example <http://ralsina.me>`__)
* Your company's site
* Your personal site
* A software project's site (`example <http://getnikola.com>`__)
* A book's site
Since Nikola-based sites don't run any code on the server, there is no way to process
user input in forms.
Nikola can't do:
* Twitter
* Facebook
* An Issue tracker
* Anything with forms, really (except for `comments <#comments-and-annotations>`_!)
Keep in mind that "static" doesn't mean **boring**. You can have animations, slides
or whatever fancy CSS/HTML5 thingie you like. It only means all that HTML is
generated already before being uploaded. On the other hand, Nikola sites will
tend to be content-heavy. What Nikola is good at is at putting what you write
out there.
Getting Help
------------
.. class:: lead
`Get help here! <http://getnikola.com/contact.html>`_
TL;DR:
* You can file bugs at `the issue tracker <https://github.com/getnikola/nikola/issues>`__
* You can discuss Nikola at the `nikola-discuss google group <http://groups.google.com/group/nikola-discuss>`_
* You can subscribe to `the Nikola Blog <http://getnikola.com/blog>`_
* You can follow `Nikola on Twitter <https://twitter.com/GetNikola>`_
Why Static?
-----------
Most "modern" websites are *dynamic* in the sense that the contents of the site
live in a database, and are converted into presentation-ready HTML only when a
user wants to see the page. That's great. However, it presents some minor issues
that static site generators try to solve.
In a static site, the whole site, every page, *everything*, is created before
the first user even sees it and uploaded to the server as a simple folder full
of HTML files (and images, CSS, etc).
So, let's see some reasons for using static sites:
Security
Dynamic sites are prone to experience security issues. The solution for that
is constant vigilance, keeping the software behind the site updated, and
plain old good luck. The stack of software used to provide a static site,
like those Nikola generates, is much smaller (Just a web server).
A smaller software stack implies less security risk.
Obsolescense
If you create a site using (for example) WordPress, what happens when WordPress
releases a new version? You have to update your WordPress. That is not optional,
because of security and support issues. If I release a new version of Nikola, and
you don't update, *nothing* happens. You can continue to use the version you
have now forever, no problems.
Also, in the longer term, the very foundations of dynamic sites shift. Can you
still deploy a blog software based on Django 0.96? What happens when your
host stops supporting the php version you rely on? And so on.
You may say those are long term issues, or that they won't matter for years. Well,
I believe things should work forever, or as close to it as we can make them.
Nikola's static output and its input files will work as long as you can install
a Python 2.7/3.3 or newer under Linux, Windows, or OS X and can find a server
that sends files over HTTP. That's probably 10 or 15 years at least.
Also, static sites are easily handled by the Internet Archive.
Cost and Performance
On dynamic sites, every time a reader wants a page, a whole lot of database
queries are made. Then a whole pile of code chews that data, and HTML is
produced, which is sent to the user. All that requires CPU and memory.
On a static site, the highly optimized HTTP server reads the file from disk
(or, if it's a popular file, from disk cache), and sends it to the user. You could
probably serve a bazillion (technical term) pageviews from a phone using
static sites.
Lock-in
On server-side blog platforms, sometimes you can't export your own data, or
it's in strange formats you can't use in other services. I have switched
blogging platforms from Advogato to PyCs to two homebrew systems, to Nikola,
and have never lost a file, a URL, or a comment. That's because I have *always*
had my own data in a format of my choice.
With Nikola, you own your files, and you can do anything with them.
Features
--------
Nikola has a very defined feature set: it has every feature I needed for my own sites.
Hopefully, it will be enough for others, and anyway, I am open to suggestions.
If you want to create a blog or a site, Nikola provides:
* Front page (and older posts pages)
* RSS Feeds
* Pages and feeds for each tag you used
* Custom search
* Full yearly archives
* Custom output paths for generated pages
* Easy page template customization
* Static pages (not part of the blog)
* Internationalization support (my own blog is English/Spanish)
* Google sitemap generation
* Custom deployment (if it's a command, you can use it)
* A (very) basic look and feel you can customize, and is even text-mode friendly
* The input format is light markup (`reStructuredText <http://getnikola.com/quickstart.html>`__ or
`Markdown <http://daringfireball.net/projects/markdown/>`_)
* Easy-to-create image galleries
* Support for displaying source code
* Image slideshows
* Client-side cloud tags
Also:
* A preview web server
* "Live" re-rendering while you edit
* "Smart" builds: only what changed gets rebuilt (usually in seconds)
* Easy to extend with minimal Python knowledge.
Installing Nikola
-----------------
This is currently lacking on detail. Considering the niche Nikola is aimed at,
I suspect that's not a problem yet. So, when I say "get", the specific details
of how to "get" something for your specific operating system are left to you.
The short version is::
pip install nikola
Note that you need Python v2.7 or newer OR v3.3 or newer.
Some features require **extra dependencies**. You can install them all in bulk
by doing::
pip install nikola[extras]
Alternatively, you can install those packages one-by-one, when required (Nikola
will tell you what packages are needed)
After that, run ``nikola init --demo sitename`` and that will run the setup
wizard, which will create a folder called ``sitename`` containing a functional
demo site.
Nikola is packaged for some Linux distributions, you may get that instead. e.g.
If you are running Arch Linux, there are AUR packages, available in Python 2/3
and stable/git master flavors: `python-nikola`__ / `python2-nikola`__ for the
latest stable release or `python-nikola-git`__ / `python2-nikola-git`__ for the
GitHub master. (only one package may be installed at the same time.)
__ https://aur.archlinux.org/packages/python-nikola/
__ https://aur.archlinux.org/packages/python2-nikola/
__ https://aur.archlinux.org/packages/python-nikola-git/
__ https://aur.archlinux.org/packages/python2-nikola-git/
libxml/libxslt (files missing) errors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you get errors about various files missing while compiling ``lxml``, you must install headers for the ``libxml``, ``libxslt`` and ``zlib`` libraries, like so:
Debian systems::
sudo apt-get install libxml2-dev libxslt1-dev zlib1g-dev
Red Hat/RPM-based systems::
sudo yum install libxslt-devel libxml2-devel zlib-devel
Python.h not found
~~~~~~~~~~~~~~~~~~
If you get an error to the effect of ``Python.h not found``, you need to
install development packages for Python.
Debian systems::
sudo apt-get install python-dev
Red Hat/RPM-based systems::
sudo yum install python-devel
Note that many other distros/operating systems (including Arch Linux,
\*BSD and OS X) do not require such packages, as C headers are included
with the base distribution of Python.
Installation on Linux/Mac OS X/etc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(any POSIX-compatible OS will do.)
Using ``pip`` should suffice. You may also want to use distribution- or
system-specific packages for our dependencies.
There are **no known issues or caveats** on those OSes. Keep in mind that most
of our developers run Linux on a daily basis and may not have the full
knowledge required to resolve issues relating to your operating system.
Installation on Windows and Windows support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Nikola supports Windows! Keep in mind, though, that there are some
caveats:
#. ``lxml`` and ``Pillow`` require compiled extensions. Compiling them on
Windows is hard for most people. Fortunately, compiled packages exist.
Check their `PyPI <https://pypi.python.org/>`_ pages to find official packages,
`the unofficial Gohlke binaries <http://www.lfd.uci.edu/~gohlke/pythonlibs/>`_
site, or get them somewhere else. If you are using virtualenvs, using those
pre-built packages is possible through ``virtualenv --system-site-packages``.
#. Windows has some differences over POSIX, which may cause some features to
work incorrectly under Windows. If any problems occur, please do not
hesitate to report them. Some of the differences include:
* ``\`` as path separator (instead of ``/``)
* the concept of HDD partitions and letters (instead of
seamless mounting under one root)
* some characters in paths are disallowed (although this shouldn’t cause
problems)
* CR+LF (aka ``\r\n``) as the line separator (instead of LF ``\n``)
#. Most of our developers run Linux on a daily basis and may not have the full
knowledge required to resolve issues relating to Windows.
Getting Started
---------------
To create posts and pages in Nikola, you write them in one of the supported input formats.
Those source files are later converted to HTML
The recommended formats are reStructuredText and Markdown, but there is also support
for Textile and WikiCreole and even for just writing HTML. For more details,
read `Configuring other input formats`_.
.. note:: There is a great `quick tutorial to learn reStructuredText. <http://getnikola.com/quickstart.html>`__
First, let's see how you "build" your site. Nikola comes with a minimal site to get you started.
The tool used to do builds is called `doit <http://pydoit.org>`__, and it rebuilds the
files that are not up to date, so your site always reflects your latest content. To do our
first build, just run "nikola build"::
$ nikola build
Scanning posts....done!
. render_posts:stories/manual.html
. render_posts:posts/1.html
. render_posts:stories/1.html
. render_archive:output/2012/index.html
. render_archive:output/archive.html
. render_indexes:output/index.html
. render_pages:output/posts/welcome-to-nikola.html
. render_pages:output/stories/about-nikola.html
. render_pages:output/stories/handbook.html
. render_rss:output/rss.xml
. render_sources:output/stories/about-nikola.txt
⋮
⋮
⋮
Nikola will print a line for every output file it generates. If we do it again, that
will be much much shorter::
$ nikola build
Scanning posts....done!
That is because `doit <http://pydoit.org>`__ is smart enough not to generate
all the pages again, unless you changed something that the page requires. So, if you change
the text of a post, or its title, that post page, and all index pages where it is mentioned,
will be recreated. If you change the post page template, then all the post pages will be rebuilt.
Nikola is mostly a series of doit *tasks*, and you can see them by doing ``nikola list``::
$ nikola list
Scanning posts....done!
build_bundles
copy_assets
copy_files
deploy
redirect
render_archive
render_galleries
render_indexes
render_listings
render_pages
render_posts
render_rss
render_site
render_sources
render_tags
sitemap
You can make Nikola redo everything by calling ``nikola forget`` and then ``nikola build`` (or ``nikola build -a``,
you can make it do just a specific part of the site using task names, for example ``nikola build render_pages``,
and even individual files like ``nikola build output/index.html``
Nikola also has other commands besides ``build``::
$ nikola help
Nikola is a tool to create static websites and blogs. For full documentation and more information, please visit http://getnikola.com/
Available commands:
nikola auto automatically detect site changes, rebuild and optionally refresh a browser
nikola bootswatch_theme given a swatch name from bootswatch.com and a parent theme, creates a custom theme
nikola build run tasks
nikola check check links and files in the generated site
nikola clean clean action / remove targets
nikola console start an interactive Python console with access to your site
nikola deploy deploy the site
nikola doit_auto automatically execute tasks when a dependency changes
nikola dumpdb dump dependency DB
nikola forget clear successful run status from internal DB
nikola github_deploy deploy the site to GitHub pages
nikola help show help
nikola ignore ignore task (skip) on subsequent runs
nikola import_wordpress import a WordPress dump
nikola init create a Nikola site in the specified folder
nikola install_theme install theme into current site
nikola list list tasks from dodo file
nikola new_page create a new page in the site
nikola new_post create a new blog post or site page
nikola orphans list all orphans
nikola plugin manage plugins
nikola serve start the test webserver
nikola strace use strace to list file_deps and targets
nikola tabcompletion generate script for tab-completion
nikola version print the Nikola version number
nikola help show help / reference
nikola help <command> show command usage
nikola help <task-name> show task usage
The ``serve`` command starts a web server so you can see the site you are creating::
$ nikola serve -b
Serving HTTP on 127.0.0.1 port 8000 ...
After you do this, a web browser opens at http://127.0.0.1:8000/ and you should see
the sample site. This is useful as a "preview" of your work.
By default, the ``serve`` command runs the web server on port 8000 on the IP address 127.0.0.1.
You can pass in an IP address and port number explicitly using ``-a IP_ADDRESS``
(short version of ``--address``) or ``-p PORT_NUMBER`` (short version of ``--port``)
Example usage::
$ nikola serve --address 0.0.0.0 --port 8080
Serving HTTP on 0.0.0.0 port 8080 ...
Creating a Blog Post
--------------------
To create a new post, the easiest way is to run ``nikola new_post``. You will
be asked for a title for your post, and it will tell you where the post's file
is located.
By default, that file will contain also some extra information about your post ("the metadata").
It can be placed in a separate file by using the ``-2`` option, but it's generally
easier to keep it in a single location.
The contents of your post have to be written (by default) in `reStructuredText <http://docutils.sf.net>`__
but you can use a lot of different markups using the ``-f`` option.
Currently Nikola supports reStructuredText, Markdown, IPython Notebooks, HTML as input,
can also use Pandoc for conversion, and has support for BBCode, CreoleWiki, txt2tags, Textile
and more via `plugins <http://plugins.getnikola.com>`__.
For more details, read `Configuring other input formats`_.
You can control what markup compiler is used for each file extension with the ``COMPILERS``
option. The default configuration expects them to be placed in ``posts`` but that can be
changed (see below, the ``POSTS`` and ``PAGES`` options)
This is how it works::
$ nikola new_post
Creating New Post
-----------------
Enter title: How to make money
Your post's text is at: posts/how-to-make-money.txt
The content of that file is as follows::
.. title: How to make money
.. slug: how-to-make-money
.. date: 2012-09-15 19:52:05 UTC
.. tags:
.. link:
.. description:
.. type: text
Write your post here.
The ``slug`` is the page name. Since often titles will have
characters that look bad on URLs, it's generated as a "clean" version of the title.
The third line is the post's date, and is set to "now".
The other lines are optional. Tags are comma-separated. The ``link`` is an original
source for the content, and ``description`` is mostly useful for SEO.
``type`` is the post type, whatever you set here (prepended with ``post-``)
will become a CSS class of the ``<article>`` element for this post. Defaults to
``text`` (resulting in a ``post-text`` class)
You can add your own metadata fields in the same manner, if you use a theme that
supports them (for example: ``.. author: John Doe``)
To add these metadata fields to all new posts by default, you can set the
variable ``ADDITIONAL_METADATA`` in your configuration. For example, you can
add the author metadata to all new posts by default, by adding the following
to your configuration::
ADDITIONAL_METADATA = {
'author': 'John Doe'
}
.. sidebar:: Other Metadata Fields
Nikola will also use other metadata fields:
author
Author of the post, will be used in the RSS feed and possibly in the post
display (theme-dependent)
annotations / noannotations
Override the value of the ``ANNOTATIONS`` option for this specific post or page.
category
Like tags, except each post can have only one, and they usually have
more descriptive names.
hidetitle
Set "True" if you do not want to see the **page** title as a
heading of the output html file (does not work for posts).
nocomments
Set to "True" to disable comments. Example::
.. nocomments: True
password
The post will be encrypted and invisible until the reader enters the password.
Also, the post's sourcecode will not be available.
WARNING: **DO NOT** use for real confidential data. The algorithm used (RC4) is insecure. The implementation may also be easily brute-forced. Please consider using something else if you need *real* encryption!
More information: `Issue #1547 <https://github.com/getnikola/nikola/issues/1547>`_
previewimage
Designate a preview or other representative image path relative to BASE_URL
for use with Open Graph for posts. Adds the image when sharing on social
media and many other uses.
.. previewimage: images/looks_great_on_facebook.png
The image can be of any size and dimension (services will crop and adapt)
but should less than 1 MB and be larger than 300x300 (ideally 600x600).
template
Will change the template used to render this page/post specific page. Example::
.. template: story.tmpl
That template needs to either be part of the theme, or be placed in a ``templates/``
folder inside your site.
enclosure
Add an enclosure to this post when it's used in RSS. See `more information about enclosures <http://en.wikipedia.org/wiki/RSS_enclosure>`__
.. note:: The Two-File Format
Nikola originally used a separate ``.meta`` file. That will still work!
The format of the meta files is the same as shown above (i.e. only
the 7 base fields, in the order listed above), but without the
explanations::
How to make money
how-to-make-money
2012-09-15 19:52:05 UTC
However, starting with Nikola v7, you can now use ``.meta`` files and put
all metadata you want, complete with the explanations — they look just like
the beginning of our reST files.
.. title: How to make money
.. slug: how-to-make-money
.. date: 2012-09-15 19:52:05 UTC
Both file formats are supported; however, the new format is preferred, if
possible.
If you are writing a multilingual site, you can also create a per-language
post file (for example: ``how-to-make-money.es.txt`` with the default TRANSLATIONS_PATTERN, see below).
This one can replace metadata of the default language, for example:
* The translated title for the post or page
* A translated version of the page name
The pattern used for finding translations is controlled by the
TRANSLATIONS_PATTERN variable in your configuration file.
The default is to put the language code before the file extension,
so the German translation of ``some_file.rst`` should be named
``some_file.de.rst``. This is because the TRANSLATIONS_PATTERN variable is by
default set to::
TRANSLATIONS_PATTERN = "{path}.{lang}.{ext}"
.. note:: Considered languages
Nikola will only look for translation of input files for languages
specified in the TRANSLATIONS variable.
You can edit these files with your favourite text editor, and once you are happy
with the contents, generate the pages as explained in `Getting Started`_
Currently supported languages are:
* Basque
* Bulgarian
* Catalan
* Chinese (Simplified)
* Croatian
* Czech
* Dutch
* English
* Esperanto
* Estonian
* Finnish
* French
* German
* Greek
* Hindi
* Italian
* Japanese
* Norwegian Bokmål
* Persian
* Polish
* Portuguese (Brasil)
* Russian
* Slovak
* Slovene
* Spanish
* Turkish
* Urdu
If you wish to add support for more languages, check out the instructions
at the `theming guide <http://getnikola.com/theming.html>`_.
The post page is generated using the ``post.tmpl`` template, which you can use
to customize the output.
The place where the post will be placed by ``new_post`` is based on the ``POSTS``
and ``PAGES`` configuration options::
# POSTS and PAGES contains (wildcard, destination, template) tuples.
#
# The wildcard is used to generate a list of reSt source files
# (whatever/thing.txt).
#
# That fragment could have an associated metadata file (whatever/thing.meta),
# and optionally translated files (example for Spanish, with code "es"):
# whatever/thing.es.txt and whatever/thing.es.meta
#
# This assumes you use the default TRANSLATIONS_PATTERN.
#
# From those files, a set of HTML fragment files will be generated:
# cache/whatever/thing.html (and maybe cache/whatever/thing.html.es)
#
# These files are combined with the template to produce rendered
# pages, which will be placed at
# output / TRANSLATIONS[lang] / destination / pagename.html
#
# where "pagename" is the "slug" specified in the metadata file.
#
# The difference between POSTS and PAGES is that POSTS are added
# to feeds and are considered part of a blog, while PAGES are
# just independent HTML pages.
#
POSTS = (
("posts/*.txt", "posts", "post.tmpl"),
("posts/*.rst", "posts", "post.tmpl"),
)
PAGES = (
("stories/*.txt", "stories", "story.tmpl"),
("stories/*.rst", "stories", "story.tmpl"),
)
``new_post`` will use the *first* path in ``POSTS`` (or ``PAGES`` if ``-p`` is
supplied) that ends with the extension of your desired markup format (as
defined in ``COMPILERS`` in ``conf.py``) as the directory that the new post will be
written into. If no such entry can be found, the post won’t be created.
The ``new_post`` command supports some options::
$ nikola help new_post
Purpose: Create a new blog post or site page.
Usage: nikola new_post [options] [path]
Options:
-p, --page Create a page instead of a blog post.
-t ARG, --title=ARG Title for the page/post.
--tags=ARG Comma-separated tags for the page/post.
-1 Create post with embedded metadata (single file format)
-2 Create post with separate metadata (two file format)
-f ARG, --format=ARG Markup format for post, one of rest, markdown, wiki, bbcode, html, textile, txt2tags
The optional ``path`` parameter tells nikola exactly where to put it instead of guessing from your config.
So, if you do ``nikola new_post posts/random/foo.txt`` you will have a post in that path, with
"foo" as its slug.
Teasers
~~~~~~~
You may not want to show the complete content of your posts either on your
index page or in RSS feeds, but to display instead only the beginning of them.
If it's the case, you only need to add a "magical comment" in your post.
In reStructuredText::
.. TEASER_END
In Markdown (or basically, the resulting HTML of any format)::
<!-- TEASER_END -->
By default all your RSS feeds will be shortened (they'll contain only teasers)
whereas your index page will still show complete posts. You can change
this behaviour with your ``conf.py``: ``INDEX_TEASERS`` defines whether index
page should display the whole contents or only teasers. ``RSS_TEASERS``
works the same way for your RSS feeds.
By default, teasers will include a "read more" link at the end. If you want to
change that text, you can use a custom teaser::
.. TEASER_END: click to read the rest of the article
Or you can completely customize the link using the ``READ_MORE_LINK`` option::
# A HTML fragment with the Read more... link.
# The following tags exist and are replaced for you:
# {link} A link to the full post page.
# {read_more} The string “Read more” in the current language.
# {{ A literal { (U+007B LEFT CURLY BRACKET)
# }} A literal } (U+007D RIGHT CURLY BRACKET)
# READ_MORE_LINK = '<p class="more"><a href="{link}">{read_more}…</a></p>'
Drafts
~~~~~~
If you add a "draft" tag to a post, then it will not be shown in indexes and feeds.
It *will* be compiled, and if you deploy it it *will* be made available, so use
with care. If you wish your drafts to be not available in your deployed site, you
can set ``DEPLOY_DRAFTS = False`` in your configuration. This will not work if
lazily include ``nikola build`` in your ``DEPLOY_COMMANDS``.
Also if a post has a date in the future, it will not be shown in indexes until
you rebuild after that date. This behavior can be disabled by setting
``FUTURE_IS_NOW = True`` in your configuration, which will make future posts be
published immediately. Posts dated in the future are *not* deployed by default
(when ``FUTURE_IS_NOW = False``). To make future posts available in the
deployed site, you can set ``DEPLOY_FUTURE = True`` in your configuration.
Generally, you want FUTURE_IS_NOW and DEPLOY_FUTURE to be the same value.
Private (formerly retired) Posts
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you add a "private" tag to a post, then it will not be shown in indexes and feeds.
It *will* be compiled, and if you deploy it it *will* be made available, so it will
not generate 404s for people who had linked to it.
Queuing Posts
~~~~~~~~~~~~~
Some blogs tend to have new posts based on a schedule (for example,
every Mon, Wed, Fri) but the blog authors don't like to manually
schedule their posts. You can schedule your blog posts based on a
rule, by specifying a rule in the ``SCHEDULE_RULE`` in your
configuration. You can either post specific blog posts according to
this schedule by using the ``--schedule`` flag on the ``new_post``
command or post all new posts according to this schedule by setting
``SCHEDULE_ALL = True`` in your configuration. (Note: This feature
requires that the ``FUTURE_IS_NOW`` setting is set to ``False``)
For example, if you would like to schedule your posts to be on every
Monday, Wednesday and Friday at 7am, add the following
``SCHEDULE_RULE`` to your configuration ::
SCHEDULE_RULE = 'RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR;BYHOUR=7;BYMINUTE=0;BYSECOND=0'
For more details on how to specify a recurrence rule, look at the
`iCal specification <http://www.kanzaki.com/docs/ical/rrule.html>`_.
Say, you get a free Sunday, and want to write a flurry of new posts,
or at least posts for the rest of the week, you would run the
``new_post`` command with the ``--schedule`` flag, as many times as
you want::
$ nikola new_post --schedule
# Creates a new post to be posted on Monday, 7am.
$ nikola new_post -s
# Creates a new post to be posted on Wednesday, 7am.
$ nikola new_post -s
# Creates a new post to be posted on Friday, 7am.
.
.
.
All these posts get queued up according to your schedule, but note
that you will anyway need to build and deploy your site for the posts
to appear online. You can have a cron job that does this regularly.
Post Types
~~~~~~~~~~
Nikola supports specifying post types, just like Tumblr does. Post
types affect the look of your posts, by adding a ``post-YOURINPUTHERE``
CSS class to the post. Each post can have one and exactly one type. Nikola
styles the following types in the default themes:
+-----------------+----------------------------+------------------+
| Name(s) | Description | Styling |
+=================+============================+==================+
| text | plain text — default value | standard |
+-----------------+----------------------------+------------------+
| micro | “small” (short) posts | big serif font |
+-----------------+----------------------------+------------------+
Configuring other input formats
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In order to use input formats other than reStructuredText, you need some extra
setup.
1. Make sure you have the compiler for the input format you want. Some
input formats are supported out-of-the-box, but others must be installed from
the Plugins repository. You may also need some extra dependencies. You
will get helpful errors if you try to build when missing something.
2. You must ensure the compiler and your desired input file extension is included
in the ``COMPILERS`` dict and does not conflict with any other format. This
is extremely important for the pandoc compiler.
3. Finally, you must configure the ``POSTS`` and ``PAGES`` tuples. Follow the
instructions and the format set by pre-existing entries. Make sure to use
the same extension as is set in ``COMPILERS`` and configure the outputs
properly.
Creating a Page
---------------
Pages are the same as posts, except that:
* They are not added to the front page
* They don't appear on the RSS feed
* They use the ``story.tmpl`` template instead of ``post.tmpl`` by default
The default configuration expects the page's metadata and text files to be on the
``stories`` folder, but that can be changed (see ``PAGES`` option above).
You can create the page's files manually or use the ``new_post`` command
with the ``-p`` option, which will place the files in the folder that
has ``use_in_feed`` set to False.
Redirections
------------
If you need a page to be available in more than one place, you can define redirections
in your ``conf.py``::
# A list of redirection tuples, [("foo/from.html", "/bar/to.html")].
#
# A HTML file will be created in output/foo/from.html that redirects
# to the "/bar/to.html" URL. notice that the "from" side MUST be a
# relative URL.
#
# If you don't need any of these, just set to []
REDIRECTIONS = [("index.html", "/weblog/index.html")]
It's better if you can do these using your web server's configuration, but if
you can't, this will work.
Configuration
-------------
The configuration file is called ``conf.py`` and can be used to customize a lot of
what Nikola does. Its syntax is python, but if you don't know the language, it
still should not be terribly hard to grasp.
The default ``conf.py`` you get with Nikola should be fairly complete, and is quite
commented.
You surely want to edit these options::
# Data about this site
BLOG_AUTHOR = "Your Name" # (translatable)
BLOG_TITLE = "Demo Site" # (translatable)
SITE_URL = "http://getnikola.com/"
BLOG_EMAIL = "joe@demo.site"
BLOG_DESCRIPTION = "This is a demo site for Nikola." # (translatable)
Some options are demarked with a (translatable) comment above or right next to
them. For those options, two types of values can be provided:
* a string, which will be used for all languages
* a dict of language-value pairs, to have different values in each language
.. note:: It is possible to load the configuration from another file by specifying
``--conf=path/to/other.file`` on Nikola's command line. For example, to
build your blog using the configuration file ``configurations/test.config``,
you have to execute ``nikola build --conf=configurations/test.config``.
Customizing Your Site
---------------------
There are lots of things you can do to personalize your website, but let's see
the easy ones!
CSS tweaking
Using the default configuration, you can create a ``assets/css/custom.css``
file under ``files/`` or in your theme and then it will be loaded from the
``<head>`` blocks of your site pages. Create it and put your CSS code there,
for minimal disruption of the provided CSS files.
If you feel tempted to touch other files in assets, you probably will be better off
with a `custom theme <theming.html>`__.
If you want to use LESS_ or Sass_ for your custom CSS, or the theme you use
contains LESS or Sass code that you want to override, you will need to install
the `LESS plugin <http://plugins.getnikola.com/#less>`__ or
`SASS plugin <http://plugins.getnikola.com/#sass>`__ create a ``less`` or
``sass`` directory in your site root, put your ``.less`` or ``.scss`` files
there and a targets file containing the list of files you want compiled.
.. _LESS: http://lesscss.org/
.. _Sass: http://sass-lang.com/
Template tweaking
If you really want to change the pages radically, you will want to do a
`custom theme <theming.html>`__.
Navigation Links
The ``NAVIGATION_LINKS`` option lets you define what links go in a sidebar or menu
(depending on your theme) so you can link to important pages, or to other sites.
The format is a language-indexed dictionary, where each element is a tuple of
tuples which are one of:
1. A (url, text) tuple, describing a link
2. A (((url, text), (url, text), (url, text)), title) tuple, describing a submenu / sublist.
Example::
NAVIGATION_LINKS = {
DEFAULT_LANG: (
('/archive.html', 'Archives'),
('/categories/index.html', 'Tags'),
('/rss.xml', 'RSS'),
((('/foo', 'FOO'),
('/bar', 'BAR')), 'BAZ'),
),
}
.. note::
Support for submenus is theme-dependent. Only one level of
submenus is supported.
.. note::
Some themes, including the default Bootstrap 3 theme, may
present issues if the menu is too large. (in ``bootstrap3``, the
navbar can grow too large and cover contents.)
.. note::
If you link to directories, make sure to follow ``STRIP_INDEXES``. If
it’s set to ``True``, end your links with a ``/``, otherwise end them
with ``/index.html`` — or else they won’t be hilighted when active.
The ``SEARCH_FORM`` option contains the HTML code for a search form based on
duckduckgo.com which should always work, but feel free to change it to
something else.
Footer
``CONTENT_FOOTER`` is displayed, small at the bottom of all pages, I use it for
the copyright notice. The default shows a text formed using ``BLOG_AUTHOR``,
``BLOG_EMAIL``, the date and ``LICENSE``. Note you need to use
``CONTENT_FOOTER_FORMATS`` instead of regular str.format or %-formatting,
for compatibility with the translatable settings feature.
BODY_END
This option lets you define a HTML snippet that will be added at the bottom of body.
The main usage is a Google analytics snippet or something similar, but you can really
put anything there. Good place for JavaScript.
SOCIAL_BUTTONS_CODE
The ``SOCIAL_BUTTONS_CODE`` option lets you define a HTML snippet that will be added
at the bottom of body. It defaults to a snippet for AddThis, but you can
really put anything there. See `social_buttons.html` for more details.
Fancy Dates
-----------
Nikola can use various styles for presenting dates.
DATE_FORMAT
The date format to use if there is no JS or fancy dates are off. Compatible with Python’s ``strftime()`` syntax.
JS_DATE_FORMAT
The date format to use if fancy dates are on. Compatible with ``moment.js`` syntax.
DATE_FANCINESS = 0
Fancy dates are off, and DATE_FORMAT is used.
DATE_FANCINESS = 1
Dates are recalculated in user’s timezone. Requires JavaScript.
DATE_FANCINESS = 2
Dates are recalculated as relative time (eg. 2 days ago). Requires JavaScript.
In order to use fancy dates, your theme must support them. The built-in Bootstrap family supports it, but other themes might not by default.