PageRenderTime 81ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/nikola/data/samplesite/stories/manual.txt

https://github.com/mwcz/nikola
Plain Text | 1136 lines | 820 code | 316 blank | 0 comment | 0 complexity | fc9829c4663edd37d5e6d4ebd4f5bec4 MD5 | raw file
  1. The Nikola Handbook
  2. ===================
  3. :Version: 5.4.4
  4. .. class:: alert alert-info pull-right
  5. .. contents::
  6. All You Need to Know
  7. --------------------
  8. After you have Nikola installed:
  9. Create a empty site:
  10. ``nikola init mysite``
  11. You can create a site with demo files in it with ``nikola init --demo mysite``
  12. The rest of these commands have to be executed inside the new ``mysite`` folder.
  13. Create a post:
  14. ``nikola new_post``
  15. Edit the post:
  16. The filename should be in the output of the previous command.
  17. Build the site:
  18. ``nikola build``
  19. Start the test server:
  20. ``nikola serve``
  21. See the site:
  22. http://127.0.0.1:8000
  23. That should get you going. If you want to know more, this manual will always be here
  24. for you.
  25. DON'T READ THIS MANUAL. IF YOU NEED TO READ IT I FAILED, JUST USE THE THING.
  26. On the other hand, if anything about Nikola is not as obvious as it should be, by all
  27. means tell me about it :-)
  28. What's Nikola and what can you do with it?
  29. ------------------------------------------
  30. Nikola is a static website and blog generator. The very short explanation is
  31. that it takes some texts you wrote, and uses them to create a folder full
  32. of HTML files. If you upload that folder to a server, you will have a
  33. rather full-featured website, done with little effort.
  34. It's original goal is to create blogs, but it supports most kind of sites, and
  35. can be used as a CMS, as long as what you present to the user is your own content
  36. instead of something the user generates.
  37. Nikola can do:
  38. * A blog (`example <http://lateral.netmanagers.com.ar>`__)
  39. * Your company's site
  40. * Your personal site
  41. * A software project's site (`example <http://nikola.ralsina.com.ar>`__)
  42. * A book's site
  43. Since Nikola-based sites don't run any code on the server, there is no way to process
  44. user input in forms.
  45. Nikola can't do:
  46. * Twitter
  47. * Facebook
  48. * An Issue tracker
  49. * Anything with forms, really (except for comments_!)
  50. Keep in mind that "static" doesn't mean **boring**. You can have animations, slides
  51. or whatever fancy CSS/HTML5 thingie you like. It only means all that HTML is
  52. generated already before being uploaded. On the other hand, Nikola sites will
  53. tend to be content-heavy. What Nikola is good at is at putting what you write
  54. out there.
  55. Getting Help
  56. ------------
  57. * Feel free to contact me at ralsina@netmanagers.com.ar for questions about Nikola.
  58. * You can file bugs at `the issue tracker <http://code.google.com/p/nikola-generator/issues/list>`__
  59. * You can discuss Nikola at the `nikola-discuss google group <http://groups.google.com/group/nikola-discuss>`_
  60. * You can subscribe to `the Nikola Blog <http://nikola.ralsina.com.ar/blog>`_
  61. * You can follow `Nikola on Twitter <https://twitter.com/#!/nikolagenerator>`_
  62. Why Static?
  63. -----------
  64. Most "modern" websites are *dynamic* in the sense that the contents of the site
  65. live in a database, and are converted into presentation-ready HTML only when a
  66. user wants to see the page. That's great. However, it presents some minor issues
  67. that static site generators try to solve.
  68. In a static site, the whole site, every page, *everything*, is created before
  69. the first user even sees it and uploaded to the server as a simple folder full
  70. of HTML files (and images, CSS, etc).
  71. So, let's see some reasons for using static sites:
  72. Security
  73. Dynamic sites are prone to experience security issues. The solution for that
  74. is constant vigilance, keeping the software behind the site updated, and
  75. plain old good luck. The stack of software used to provide a static site,
  76. like those Nikola generates, is much smaller (Just a webserver).
  77. A smaller software stack implies less security risk.
  78. Obsolescense
  79. If you create a site using (for example) Wordpress, what happens when Wordpress
  80. releases a new version? You have to update your Wordpress. That is not optional,
  81. because of security and support issues. If I release a new version of Nikola, and
  82. you don't update, *nothing* happens. You can continue to use the version you
  83. have now forever, no problems.
  84. Also, in the longer term, the very foundations of dynamic sites shift. Can you
  85. still deploy a blog software based on Django 0.96? What happens when your
  86. host stops supporting the php version you rely on? And so on.
  87. You may say those are long term issues, or that they won't matter for years. Well,
  88. I believe things should work forever, or as close to it as we can make them.
  89. Nikola's static output and its input files will work as long as you can install
  90. a Python > 2.6 in a Linux, Windows, or Mac and can find a server
  91. that sends files over HTTP. That's probably 10 or 15 years at least.
  92. Also, static sites are easily handled by the Internet Archive.
  93. Cost and Performance
  94. On dynamic sites, every time a reader wants a page, a whole lot of database
  95. queries are made. Then a whole pile of code chews that data, and HTML is
  96. produced, which is sent to the user. All that requires CPU and memory.
  97. On a static site, the highly optimized HTTP server reads the file from disk
  98. (or, if it's a popular file, from disk cache), and sends it to the user. You could
  99. probably serve a bazillion (technical term) pageviews from a phone using
  100. static sites.
  101. Lockin
  102. On server-side blog platforms, sometimes you can't export your own data, or
  103. it's in strange formats you can't use in other services. I have switched
  104. blogging platforms from Advogato to PyCs to two homebrewed systems, to Nikola,
  105. and have never lost a file, a URL, or a comment. That's because I have *always*
  106. had my own data in a format of my choice.
  107. With Nikola, you own your files, and you can do anything with them.
  108. Features
  109. --------
  110. Nikola has a very defined featureset: it has every feature I needed for my own sites.
  111. Hopefully, it will be enough for others, and anyway, I am open to suggestions.
  112. If you want to create a blog or a site, Nikola provides:
  113. * Front page (and older posts pages)
  114. * RSS Feeds
  115. * Pages and feeds for each tag you used
  116. * Custom search
  117. * Full yearly archives
  118. * Custom output paths for generated pages
  119. * Easy page template customization
  120. * Static pages (not part of the blog)
  121. * Internationalization support (my own blog is English/Spanish)
  122. * Google sitemap generation
  123. * Custom deployment (if it's a command, you can use it)
  124. * A (very) basic look and feel you can customize, and is even text-mode friendly
  125. * The input format is light markup (`reStructuredText <quickstart.html>`_ or
  126. `Markdown <http://daringfireball.net/projects/markdown/>`_)
  127. * Easy-to-create image galleries
  128. * Support for displaying source code
  129. * Image slideshows
  130. * Client-side cloud tags
  131. Also:
  132. * A preview webserver
  133. * "Live" re-rendering while you edit
  134. * "Smart" builds: only what changed gets rebuilt (usually in seconds)
  135. * Easy to extend with minimal Python knowledge.
  136. Installing Nikola
  137. -----------------
  138. This is currently lacking on detail. Considering the niche Nikola is aimed at,
  139. I suspect that's not a problem yet. So, when I say "get", the specific details
  140. of how to "get" something for your specific operating system are left to you.
  141. The short version is: ``pip install https://github.com/ralsina/nikola/archive/master.zip``
  142. Longer version:
  143. #. Get `Nikola <http://nikola.ralsina.com.ar/>`_
  144. #. Install dependencies. To do that, either:
  145. #. ``pip install -r requirements.txt`` or...
  146. #. Install your distribution's packages for all the things
  147. mentioned below, if they exist, or...
  148. #. Get all of these manually (but why?, use requirements.txt):
  149. #. Get python, if you don't have it.
  150. #. Get `doit <http://pydoit.org>`_
  151. #. Get `docutils <http://docutils.sf.net>`_
  152. #. Get `Mako <http://makotemplates.org>`_
  153. #. Get `PIL <http://www.pythonware.com/products/pil/>`_ (or Pillow)
  154. #. Get `Pygments <http://pygments.org/>`_
  155. #. Get `unidecode <http://pypi.python.org/pypi/Unidecode/>`_
  156. #. Get `lxml <http://lxml.de/>`_
  157. #. Get `yapsy <http://yapsy.sourceforge.net>`_
  158. #. Get `configparser <http://pypi.python.org/pypi/configparser/3.2.0r3>`_
  159. #. run ``python setup.py install``
  160. After that, run ``nikola init --demo sitename`` and that will create a folder called
  161. ``sitename`` containing a functional demo site.
  162. Nikola is packaged for some Linux distributions, you may get that instead.
  163. *NOTE*: If you get a ``ERROR: /bin/sh: 1: xslt-config: not found`` or ``fatal error:
  164. libxml/xmlversion.h: No such file or directory`` when running ``pip install -r requirements.txt``, install *libxml* and *libxslt* libraries, like so:
  165. Debian systems:
  166. sudo apt-get install libxml2-dev
  167. sudo apt-get install libxslt1-dev
  168. RHEL systems:
  169. yum install libxslt-devel libxml2-devel
  170. Getting Started
  171. ---------------
  172. To create posts and pages in Nikola, you write them in one of the supported input formats.
  173. Those source files are later converted to HTML
  174. The recommended formats are restructured text and Markdown, but there is also support
  175. for textile and WikiCreole and even for just writing HTML.
  176. .. note:: There is a great `quick tutorial to learn restructured text. <quickstart.html>`_
  177. First, let's see how you "build" your site. Nikola comes with a minimal site to get you started.
  178. The tool used to do builds is called `doit <http://pydoit.org>`_, and it rebuilds the
  179. files that are not up to date, so your site always reflects your latest content. To do our
  180. first build, just run "nikola build"::
  181. $ nikola build
  182. Scanning posts . . done!
  183. . render_posts:stories/manual.html
  184. . render_posts:posts/1.html
  185. . render_posts:stories/1.html
  186. . render_archive:output/2012/index.html
  187. . render_archive:output/archive.html
  188. . render_indexes:output/index.html
  189. . render_pages:output/posts/welcome-to-nikola.html
  190. . render_pages:output/stories/about-nikola.html
  191. . render_pages:output/stories/handbook.html
  192. . render_rss:output/rss.xml
  193. . render_sources:output/stories/about-nikola.txt
  194. :
  195. :
  196. :
  197. Nikola will print a line for every output file it generates. If we do it again, that
  198. will be much much shorter::
  199. $ nikola build
  200. Scanning posts . . done!
  201. That is because `doit <http://pydoit.org>`_ is smart enough not to generate
  202. all the pages again, unless you changed something that the page requires. So, if you change
  203. the text of a post, or its title, that post page, and all index pages where it is mentioned,
  204. will be recreated. If you change the post page template, then all the post pages will be rebuilt.
  205. Nikola is mostly a series of doit *tasks*, and you can see them by doing ``nikola build list``::
  206. $ nikola build list
  207. Scanning posts . . done!
  208. build_bundles
  209. copy_assets
  210. copy_files
  211. deploy
  212. redirect
  213. render_archive
  214. render_galleries
  215. render_indexes
  216. render_listings
  217. render_pages
  218. render_posts
  219. render_rss
  220. render_site
  221. render_sources
  222. render_tags
  223. sitemap
  224. You can make Nikola redo everything by calling ``nikola build forget``, you can make it do just a specific
  225. part of the site using task names, for example ``nikola build render_pages``, and even individual files like
  226. ``nikola build render_indexes:output/index.html``
  227. Nikola also has other commands besides ``build``::
  228. $ nikola help
  229. Nikola
  230. Available commands:
  231. nikola auto automatically execute tasks when a dependency changes
  232. nikola bootswatch_theme Given a swatch name and a parent theme, creates a custom theme.
  233. nikola build run tasks
  234. nikola check Check links and files in the generated site.
  235. nikola clean clean action / remove targets
  236. nikola console A short explanation.
  237. nikola deploy Deploy the site.
  238. nikola dumpdb dump dependency DB
  239. nikola forget clear successful run status from internal DB
  240. nikola help show help
  241. nikola ignore ignore task (skip) on subsequent runs
  242. nikola import_blogger Import a blogger dump.
  243. nikola import_wordpress Import a wordpress dump.
  244. nikola init Create a Nikola site in the specified folder.
  245. nikola install_theme Install theme into current site.
  246. nikola list list tasks from dodo file
  247. nikola new_post Create a new blog post or site page.
  248. nikola run run tasks
  249. nikola serve Start the test webserver.
  250. nikola strace use strace to list file_deps and targets
  251. nikola help show help / reference
  252. nikola help <command> show command usage
  253. nikola help <task-name> show task usage
  254. The ``serve`` command starts a web server so you can see the site you are creating::
  255. $ nikola serve
  256. Serving HTTP on 127.0.0.1 port 8000 ...
  257. After you do this, you can point your web browser to http://localhost:8000 and you should see
  258. the sample site. This is useful as a "preview" of your work.
  259. By default, the ``serve`` command runs the web server on port 8000 on the IP address 127.0.0.1.
  260. You can pass in an IP address and port number explicity using ``-a IP_ADDRESS``
  261. (short version of ``--address``) or ``-p PORT_NUMBER`` (short version of ``--port``)
  262. Example usage::
  263. $ nikola serve --address 0.0.0.0 --port 8080
  264. Serving HTTP on 0.0.0.0 port 8080 ...
  265. Creating a Blog Post
  266. --------------------
  267. To create a new post, the easiest way is to run ``nikola new_post``. You will
  268. be asked for a title for your post, and it will tell you where the post's file
  269. is located.
  270. By default, that file will contain also some extra information about your post ("the metadata").
  271. It can be placed in a separate file by using the ``-2`` option, but it's generally
  272. easier to keep it in a single location.
  273. The contents of your post have to be written (by default) in `restructured text <http://docutils.sf.net>`_
  274. but you can use a lot of different markups using the ``-f`` option. Currently
  275. Nikola supports bbcode, wiki, markdown, html, txt2tags and textile in addition
  276. to restructured text.
  277. You can control what markup compiler is used for each file extension with the ``post_compilers``
  278. option. The default configuration expects them to be placed in ``posts`` but that can be
  279. changed (see below, the post_pages option)
  280. This is how it works::
  281. $ nikola new_post
  282. Creating New Post
  283. -----------------
  284. Enter title: How to make money
  285. Your post's text is at: posts/how-to-make-money.txt
  286. The content of that file is as follows::
  287. .. title: How to make money
  288. .. slug: how-to-make-money
  289. .. date: 2012/09/15 19:52:05
  290. .. tags:
  291. .. link:
  292. .. description:
  293. Write your post here.
  294. The ``slug`` is the pagename. Since often titles will have
  295. characters that look bad on URLs, it's generated as a "clean" version of the title.
  296. The third line is the post's date, and is set to "now".
  297. The other lines are optional. Tags are comma-separated. The ``link`` is an original
  298. source for the content, and ``description`` is mostly useful for SEO.
  299. You can add your own metadata fields in the same manner, if you use a theme that
  300. supports them (for example: ``.. author: John Doe``)
  301. .. sidebar:: Other Metadata Fields
  302. Nikola will also use other metadata fields:
  303. nocomments
  304. Set to "True" to disable comments. Example::
  305. .. nocomments: True
  306. template
  307. Will change the template used to render this page/post specific page. Example::
  308. .. template: story.tmpl
  309. password
  310. The post will be encrypted and invisible until the reader enters the password.
  311. Also, the post's sourcecode will not be available.
  312. .. note:: The Two-File Format
  313. Nikola originally used a separate ``.meta`` file. That will still work!
  314. The format of the meta files is the same as shown above, but without the
  315. explanations::
  316. How to make money
  317. how-to-make-money
  318. 2012/09/15 19:52:05
  319. If you are writing a multilingual site, you can also create a per-language
  320. post file (for example: ``how-to-make-money.txt.es``). This one can replace
  321. metadata of the default language, for example:
  322. * The translated title for the post or page
  323. * A translated version of the pagename
  324. You can edit these files with your favourite text editor, and once you are happy
  325. with the contents, generate the pages as explained in `Getting Started`_
  326. Currently supported languages are
  327. * Catalan
  328. * English
  329. * French
  330. * German
  331. * Greek
  332. * Italian
  333. * Polish
  334. * Russian
  335. * Simplified Chinese.
  336. * Spanish
  337. If you wish to add support for more languages, check out the instructions
  338. at the `theming guide <http://nikola.ralsina.com.ar/theming.html>`_.
  339. The post page is generated using the ``post.tmpl`` template, which you can use
  340. to customize the output.
  341. The place where the post will be placed by ``new_post`` is based on the ``post_pages``
  342. configuration option::
  343. # post_pages contains (wildcard, destination, template, use_in_feed) tuples.
  344. #
  345. # The wildcard is used to generate a list of reSt source files (whatever/thing.txt)
  346. # That fragment must have an associated metadata file (whatever/thing.meta),
  347. # and opcionally translated files (example for spanish, with code "es"):
  348. # whatever/thing.txt.es and whatever/thing.meta.es
  349. #
  350. # From those files, a set of HTML fragment files will be generated:
  351. # cache/whatever/thing.html (and maybe cache/whatever/thing.html.es)
  352. #
  353. # These files are combinated with the template to produce rendered
  354. # pages, which will be placed at
  355. # output / TRANSLATIONS[lang] / destination / pagename.html
  356. #
  357. # where "pagename" is specified in the metadata file.
  358. #
  359. # if use_in_feed is True, then those posts will be added to the site's
  360. # rss feeds.
  361. #
  362. post_pages = (
  363. ("posts/*.txt", "posts", "post.tmpl", True),
  364. ("stories/*.txt", "stories", "story.tmpl", False),
  365. )
  366. It will use the first location that has the last parameter set to True, or the last
  367. one in the list if all of them have it set to False.
  368. The ``new_post`` command supports some options::
  369. $ nikola help new_post
  370. Purpose: Create a new blog post or site page.
  371. Usage: nikola new_post [options] [path]
  372. Options:
  373. -p, --page Create a page instead of a blog post.
  374. -t ARG, --title=ARG Title for the page/post.
  375. --tags=ARG Comma-separated tags for the page/post.
  376. -1 Create post with embedded metadata (single file format)
  377. -2 Create post with separate metadata (two file format)
  378. -f ARG, --format=ARG Markup format for post, one of rest, markdown, wiki, bbcode, html, textile, txt2tags
  379. The optional ``path`` parameter tells nikola exactly where to put it instead of guessing from your config.
  380. So, if you do ``nikola new_post posts/random/foo.txt`` you will have a post in that path, with
  381. "foo" as its slug.
  382. Teasers
  383. ~~~~~~~
  384. You may not want to show the complete content of your posts either on your
  385. index page or in RSS feeds, but to display instead only the beginning of them.
  386. If it's the case, you only need to add a "magical comment" in your post.
  387. In restructuredtext::
  388. .. TEASER_END
  389. In Markdown::
  390. <!-- TEASER_END -->
  391. By default all your RSS feeds will be shortened (they'll contain only teasers)
  392. whereas your index page will still show complete posts. You can change
  393. this behaviour with your ``conf.py``: ``INDEX_TEASERS`` defines whether index
  394. page should display the whole contents or only teasers. ``RSS_TEASERS``
  395. works the same way for your RSS feeds.
  396. By default, teasers will include a "read more" link at the end. If you want to
  397. change that text, you can use a custom teaser::
  398. .. TEASER_END: click to read the rest of the article
  399. Drafts
  400. ~~~~~~
  401. If you add a "draft" tag to a post, then it will not be shown in indexes and feeds.
  402. It *will* be compiled, and if you deploy it it *will* be made available, so use
  403. with care.
  404. Creating a Page
  405. ---------------
  406. Pages are the same as posts, except that:
  407. * They are not added to the front page
  408. * They don't appear on the RSS feed
  409. * They use the ``story.tmpl`` template instead of ``post.tmpl`` by default
  410. The default configuration expects the page's metadata and text files to be on the
  411. ``stories`` folder, but that can be changed (see post_pages option above).
  412. You can create the page's files manually or use the ``new_post`` command
  413. with the ``-p`` option, qhich will place the files in the folder that
  414. has ``use_in_feed`` set to False.
  415. Redirections
  416. ------------
  417. If you need a page to be available in more than one place, you can define redirections
  418. in your ``conf.py``::
  419. # A list of redirection tuples, [("foo/from.html", "/bar/to.html")].
  420. #
  421. # A HTML file will be created in output/foo/from.html that redirects
  422. # to the "/bar/to.html" URL. notice that the "from" side MUST be a
  423. # relative URL.
  424. #
  425. # If you don't need any of these, just set to []
  426. REDIRECTIONS = [("index.html", "/weblog/index.html")]
  427. It's better if you can do these using your web server's configuration, but if
  428. you can't, this will work.
  429. Configuration
  430. -------------
  431. The configuration file is called ``conf.py`` and can be used to customize a lot of
  432. what Nikola does. Its syntax is python, but if you don't know the language, it
  433. still should not be terribly hard to grasp.
  434. The default ``conf.py`` you get with Nikola should be fairly complete, and is quite
  435. commented, but just in case, here is a full,
  436. `customized example configuration <sampleconfig.html>`_ (the one I use for
  437. `my site <http://lateral.netmanagers.com.ar>`_)
  438. You surely want to edit these options::
  439. # Data about this site
  440. BLOG_TITLE = "Demo Site"
  441. SITE_URL = "http://nikola.ralsina.com.ar"
  442. BLOG_EMAIL = "joe@demo.site"
  443. BLOG_DESCRIPTION = "This is a demo site for Nikola."
  444. Customizing Your Site
  445. ---------------------
  446. There are lots of things you can do to personalize your website, but let's see
  447. the easy ones!
  448. CSS tweaking
  449. The default configuration includes a file, ``themes/default/assets/css/custom.css``
  450. which is empty. Put your CSS there, for minimal disruption of the provided CSS files.
  451. If you feel tempted to touch other files in assets, you probably will be better off
  452. with a `custom theme <theming.html>`_.
  453. Template tweaking
  454. If you really want to change the pages radically, you will want to do a
  455. `custom theme <theming.html>`_.
  456. Sidebar
  457. ``LICENSE`` is a HTML snippet for things like a CC badge, or whatever you prefer.
  458. The 'sidebar_links' option lets you define what links go in the right-hand
  459. sidebar, so you can link to important pages, or to other sites.
  460. The ``SEARCH_FORM`` option contains the HTML code for a search form based on
  461. duckduckgo.com which should always work, but feel free to change it to
  462. something else.
  463. Footer
  464. ``CONTENT_FOOTER`` is displayed, small at the bottom of all pages, I use it for
  465. the copyright notice.
  466. Analytics
  467. This is probably a misleading name, but the ``ANALYTICS`` option lets you define
  468. a HTML snippet that will be added at the bottom of body. The main usage is
  469. a Google analytics snippet or something similar, but you can really put anything
  470. there.
  471. Adding Files
  472. ------------
  473. Any files you want to be in ``output/`` but are not generated by Nikola (for example,
  474. ``favicon.ico``, just put it in ``files/``. Everything there is copied into
  475. ``output`` by the ``copy_files`` task. Remember that you can't have files that collide
  476. with files Nikola generates (it will give an error).
  477. .. admonition:: Important
  478. Don't put any files manually in ``output/``. Ever. Really. Maybe someday Nikola
  479. will just wipe ``output/`` and then you will be sorry. So, please don't do that.
  480. If you want to copy more than one folder of static files into ``output`` you can
  481. change the FILES_FOLDERS option::
  482. # One or more folders containing files to be copied as-is into the output.
  483. # The format is a dictionary of "source" "relative destination".
  484. # Default is:
  485. # FILES_FOLDERS = {'files': '' }
  486. # Which means copy 'files' into 'output'
  487. Getting More Themes
  488. -------------------
  489. There are not so many themes for Nikola. On occasion, I port something I like, and make
  490. it available for download. Nikola has a builtin theme download/install mechanism, its
  491. ``install_theme`` command::
  492. $ nikola install_theme -l
  493. Themes:
  494. -------
  495. blogtxt
  496. readable
  497. $ nikola install_theme -n blogtxt
  498. Downloading: http://nikola.ralsina.com.ar/themes/blogtxt.zip
  499. Extracting: blogtxt into themes
  500. And there you are, you now have themes/blogtxt installed. It's very rudimentary, but it
  501. should work in most cases.
  502. If you create a nice theme, please share it! You can post about it on
  503. `the nikola forum <http://groups.google.com/group/nikola-discuss>`_ and I will
  504. make it available for download.
  505. One other option is to tweak an existing theme using a different color scheme,
  506. typography and CSS in general. Nikola provides a ``bootswatch_theme`` option
  507. to create a custom theme by downloading free CSS files from http://bootswatch.com::
  508. $ nikola bootswatch_theme -n custom_theme -s spruce -p site
  509. Creating 'custom_theme' theme from 'spruce' and 'site'
  510. Downloading: http://bootswatch.com/spruce/bootstrap.min.css
  511. Downloading: http://bootswatch.com/spruce/bootstrap.css
  512. Theme created. Change the THEME setting to "custom_theme" to use it.
  513. You can even try what different swatches do on an existing site using
  514. their handy `bootswatchlet <http://news.bootswatch.com/post/29555952123/a-bookmarklet-for-bootswatch>`_
  515. Play with it, there's cool stuff there. This feature was suggested by
  516. `clodo <http://elgalpondebanquito.com.ar>`_.
  517. Deployment
  518. ----------
  519. Nikola doesn't really have a concept of deployment. However, if you can specify your
  520. deployment procedure as a series of commands, you can put them in the ``DEPLOY_COMMANDS``
  521. option, and run them with ``nikola deploy``.
  522. One caveat is that if any command has a % in it, you should double them.
  523. Here is an example, from my own site's deployment script::
  524. DEPLOY_COMMANDS = [
  525. 'rsync -rav --delete output/* ralsina@lateral.netmanagers.com.ar:/srv/www/lateral',
  526. 'rdiff-backup output ~/bartleblog-backup',
  527. "links -dump 'http://www.twingly.com/ping2?url=lateral.netmanagers.com.ar'",
  528. 'rsync -rav ~/bartleblog-backup/* ralsina@netmanagers.com.ar:bartleblog-backup',
  529. ]
  530. Other interesting ideas are using
  531. `git as a deployment mechanism <http://toroid.org/ams/git-website-howto>`_ (or any other VCS
  532. for that matter), using `lftp mirror <http://lftp.yar.ru/>`_ or unison, or dropbox, or
  533. Ubuntu One. Any way you can think of to copy files from one place to another is good enough.
  534. Comments
  535. --------
  536. While Nikola creates static sites, there is a minimum level of user interaction you
  537. are probably expecting: comments.
  538. The default templates contain support for `Disqus <http://disqus.com>`_. All you have
  539. to do is register a forum, put its short name in the ``DISQUS_FORUM`` option.
  540. Disqus is a good option because:
  541. 1) It doesn't require any server-side software on your site
  542. 2) They offer you a way to export your comments, so you can take
  543. them with you if you need to.
  544. 3) It's free.
  545. 4) It's damn nice.
  546. You can disable comments for a post by adding a "nocomments" metadata field to it::
  547. .. nocomments: True
  548. .. admonition:: Important
  549. In some cases, when you run the test site, you won't see the comments.
  550. That can be fixed by adding the disqus_developer flag to the templates
  551. but it's probably more trouble than it's worth.
  552. Image Galleries
  553. ---------------
  554. To create an image gallery, all you have to do is add a folder inside ``galleries``,
  555. and put images there. Nikola will take care of creating thumbnails, index page, etc.
  556. If you click on images on a gallery, you should see a bigger image, thanks to
  557. the excellent `colorbox <http://www.jacklmoore.com/colorbox>`_
  558. The gallery pages are generated using the ``gallery.tmpl`` template, and you can
  559. customize it there (you could switch to another lightbox instead of colorbox, change
  560. its settings, change the layout, etc.).
  561. The ``conf.py`` options affecting gallery pages are these::
  562. # Galleries are folders in galleries/
  563. # Final location of galleries will be output / GALLERY_PATH / gallery_name
  564. GALLERY_PATH = "galleries"
  565. THUMBNAIL_SIZE = 180
  566. MAX_IMAGE_SIZE = 1280
  567. USE_FILENAME_AS_TITLE = True
  568. If you add a file in ``galleries/gallery_name/index.txt`` its contents will be
  569. converted to HTML and inserted above the images in the gallery page.
  570. If you add some image filenames in ``galleries/gallery_name/exclude.meta``, they
  571. will be excluded in the gallery page.
  572. If ``USE_FILENAME_AS_TITLE`` is True the filename (parsed as a readable string)
  573. is used as the photo caption. If the filename starts with a number, it will
  574. be stripped. For example ``03_an_amazing_sunrise.jpg`` will be render as *An amazing sunrise*.
  575. Here is a `demo gallery </galleries/demo>`_ of historic, public domain Nikola
  576. Tesla pictures taken from `this site <http://kerryr.net/pioneers/gallery/tesla.htm>`_.
  577. Post Processing Filters
  578. -----------------------
  579. You can apply post processing to the files in your site, in order to optimize them
  580. or change them in arbitrary ways. For example, you may want to compress all CSS
  581. and JS files using yui-compressor.
  582. To do that, you can use the provided helper adding this in your ``config.py``::
  583. from nikola import filters
  584. FILTERS = {
  585. ".css": [filters.yui_compressor],
  586. ".js": [filters.yui_compressor],
  587. }
  588. Where ``filters.yui_compressor`` is a helper function provided by Nikola. You can
  589. replace that with strings describing command lines, or arbitrary python functions.
  590. If there's any specific thing you expect to be generally useful as a filter, contact
  591. me and I will add it to the filters library so that more people use it.
  592. Optimizing Your Website
  593. -----------------------
  594. One of the main goals of Nikola is to make your site fast and light. So here are a few
  595. tips we have found when setting up Nikola with Apache. If you have more, or
  596. different ones, or about other webservers, please share!
  597. #. Use a speed testing tool. I used Yahoo's YSlow but you can use any of them, and
  598. it's probably a good idea to use more than one.
  599. #. Enable compression in Apache::
  600. AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
  601. #. If even after you did the previous step the CSS files are not sent compressed::
  602. AddType text/css .css
  603. #. Optionally you can greate static compressed copies and save some CPU on your server
  604. with the GZIP_FILES option in Nikola.
  605. #. The webassets Nikola plugin can drastically decrease the number of CSS and JS files your site fetches.
  606. #. Through the filters feature, you can run your files through arbitrary commands, so that images
  607. are recompressed, Javascript is minimized, etc.
  608. #. The USE_CDN option offloads standard Javascript and CSS files to a CDN so they are not
  609. downloaded from your server.
  610. Restructured Text Extensions
  611. ----------------------------
  612. Nikola includes support for a few directives that are not part of docutils, but which
  613. we think are handy for website development.
  614. Youtube
  615. ~~~~~~~
  616. To link to a youtube video, you need the id of the video. For example, if the
  617. URL of the video is http://www.youtube.com/watch?v=8N_tupPBtWQ what you need is
  618. **8N_tupPBtWQ**
  619. Once you have that, all you need to do is::
  620. .. youtube:: 8N_tupPBtWQ
  621. Vimeo
  622. ~~~~~
  623. To link to a vimeo video, you need the id of the video. For example, if the
  624. URL of the video is http://www.vimeo.com/20241459 then the id is **20241459**
  625. Once you have that, all you need to do is::
  626. .. vimeo:: 20241459
  627. If you are running python 2.6 or later, or have the json module installed and
  628. have internet connectivity when generating your site, the height and width of
  629. the embedded player will be set to the native height and width of the video.
  630. You can override this if you wish::
  631. .. vimeo:: 20241459
  632. :height: 240
  633. :width: 320
  634. Soundcloud
  635. ~~~~~~~~~~
  636. This directive lets you share music from http://soundcloud.com You first need to get the
  637. ID for the piece, which you can find in the "share" link. For example, if the
  638. Wordpress code starts like this::
  639. [soundcloud url="http://api.soundcloud.com/tracks/78131362"
  640. The ID is 78131362 and you can embed the audio with this::
  641. .. soundcloud:: 78131362
  642. Code
  643. ~~~~
  644. The ``code`` directive has been included in docutils since version 0.9 and now
  645. replaces Nikola's ``code-block`` directive. To ease the transition, two aliases
  646. for ``code`` directive are provided: ``code-block`` and ``sourcecode``::
  647. .. code:: python
  648. :number-lines:
  649. print("Our virtues and our failings are inseparable")
  650. Listing
  651. ~~~~~~~
  652. To use this, you have to put your source code files inside ``listings`` or whatever your
  653. ``LISTINGS_FOLDER`` variable is set to. Assuming you have a ``foo.py`` inside that folder::
  654. .. listing:: foo.py python
  655. Will include the source code from ``foo.py``, highlight its syntax in python mode,
  656. and also create a ``listings/foo.py.html`` page and the listing will have a title linking to it.
  657. Listings support a few extra options so that you can display a fragment instead of the whole
  658. file in a document:
  659. start-at
  660. Takes a string, and starts displaying the code at the first line that matches it.
  661. start-before
  662. Takes a string, and starts displaying the code right before the first line that matches it.
  663. end-at
  664. Takes a string, and stops displaying the code at the first line that matches it.
  665. end-before
  666. Takes a string, and stops displaying the code right before the first line that matches it.
  667. If you set start-at and start-before, start-at wins. If you set end-at and end-before, end-at wins.
  668. If you make it so your listing ends before it starts, it's frowned upon and nothing will be shown.
  669. Gist
  670. ~~~~
  671. You can easily embed GitHub gists with this directive, like this::
  672. .. gist:: 2395294
  673. Producing this:
  674. .. gist:: 2395294
  675. This degrades gracefully if the browser doesn't support javascript.
  676. Slideshows
  677. ~~~~~~~~~~
  678. To create an image slideshow, you can use the ``slides`` directive. For example::
  679. .. slides::
  680. /galleries/demo/tesla_conducts_lg.jpg
  681. /galleries/demo/tesla_lightning2_lg.jpg
  682. /galleries/demo/tesla4_lg.jpg
  683. /galleries/demo/tesla_lightning1_lg.jpg
  684. /galleries/demo/tesla_tower1_lg.jpg
  685. Importing Your Wordpress Site Into Nikola
  686. -----------------------------------------
  687. If you like Nikola, and want to start using it, but you have a Wordpress blog, Nikola
  688. supports importing it. Here's the steps to do it:
  689. 1) Get a XML dump of your site [#]_
  690. 2) nikola import_wordpress -f mysite.wordpress.2012-12-20.xml
  691. After some time, this will crate a ``new_site`` folder with all your data. It currently supports
  692. the following:
  693. * All your posts and pages
  694. * Keeps "draft" status
  695. * Your tags and categories
  696. * Imports your attachments and fixes links to point to the right places
  697. * Will try to add redirects that send the old post URLs to the new ones
  698. * Will give you a url_map so you know where each old post was
  699. This is also useful for Disqus thread migration!
  700. * Will try to convert the content of your posts. This is *not* error free, because
  701. wordpress uses some unholy mix of HTML and strange things. Currently we are treating it
  702. as markdown, which does a reasonabe job of it.
  703. You will find your old posts in ``new_site/posts/post-title.wp`` in case you need to fix
  704. any of them.
  705. This feature is a work in progress, and the only way to improve it is to have it used for
  706. as many sites as possible and make it work better each time, so I am happy to get requests
  707. about it.
  708. .. [#] The dump needs to be in 1.2 format. You can check by reading it, it should say
  709. ``xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"`` near the top of the
  710. file. If it says ``1.1`` instead of ``1.2`` you will have to update your
  711. wordpress before dumping.
  712. Other versions may or may not work.
  713. Importing To A Custom Location Or Into An Existing Site
  714. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  715. It is possible to either import into a location you desire or into an already existing Nikola site.
  716. To do so you can specify a location after the dump.::
  717. $ nikola import_wordpress -f mysite.wordpress.2012-12-20.xml -o import_location
  718. With this command Nikola will import into the folder ``import_location``.
  719. If the folder already exists Nikola will not overwrite an existing ``conf.py``.
  720. Instead a new file with a timestamp at the end of the filename will be created.
  721. Using Twitter Cards
  722. -------------------
  723. Twitter Cards enable you to show additional information in Tweets that link
  724. to you content.
  725. Nikola supports `Twitter Cards <https://dev.twitter.com/docs/cards>`_.
  726. They are implemented to use *Open Graph* tags whenever possible.
  727. .. admonition:: Important
  728. To use Twitter Cards you need to opt-in on Twitter.
  729. To do so please use the form that can be found at https://dev.twitter.com/form/participate-twitter-cards
  730. To enable and configure your use of Twitter Cards please modify the
  731. corresponding lines in your ``conf.py``.
  732. An example configuration that uses the Twitter nickname of the website
  733. and the authors Twitter user ID is found below.
  734. .. code-block:: python
  735. TWITTER_CARD = {
  736. 'use_twitter_cards': True, # enable Twitter Cards / Open Graph
  737. 'site': '@website', # twitter nick for the website
  738. # 'site:id': 123456, # Same as site, but the website's Twitter user ID instead.
  739. # 'creator': '@username', # Username for the content creator / author.
  740. 'creator:id': 654321, # Same as creator, but the Twitter user's ID.
  741. }
  742. Extra Plugins
  743. -------------
  744. These are plugins that may not be widely used or that are a bit too radical or
  745. experimental for the general public.
  746. To enable them for your site please look for `ENABLED_EXTRAS` in your ``conf.py``.
  747. Planetoid
  748. ~~~~~~~~~
  749. This plugin converts Nikola into the equivalent of `Planet <http://www.planetplanet.org/>`_
  750. a feed aggregator. It requires `PeeWee <https://github.com/coleifer/peewee>`_ and
  751. `Feedparser <http://code.google.com/p/feedparser/>`_ to work.
  752. It has a configuration option: PLANETOID_REFRESH which is the number of minutes
  753. before retrying a feed (defaults to 60).
  754. You need to create a ``feeds`` file containing the data of which feeds you want to
  755. aggregate. The format is very simple::
  756. # Roberto Alsina
  757. http://feeds2.feedburner.com/PostsInLateralOpinionAboutPython
  758. Roberto Alsina
  759. #. Lines that start with ``#`` are comments and ignored.
  760. #. Lines that start with http are feed URLs.
  761. #. URL lines have to be followed by the "real name" of the feed.
  762. After all that is in place, just run ``nikola build`` and you'll get
  763. a planet.
  764. If you run ``nikola build`` for the first time you need to actually issue
  765. the command three times until the planet is build.
  766. There is a special theme for the planets called `site-planetoid`. To use
  767. this set `THEME` in your ``conf.py`` to ``'site-planetoid'``.
  768. This is special in the case that it redirects users to the original URL of the post
  769. when they try to open a post.
  770. Local Search
  771. ~~~~~~~~~~~~
  772. If you don't want to depend on google or duckduckgo to implement search for you,
  773. or just want it to wok even if you are offline, enable this plugin and the
  774. search will be performed client side.
  775. This plugin implements a Tipue-based local search for your site.
  776. To use it, copy task_localsearch.plugin and task_localsearch
  777. into a plugins/ folder in your nikola site.
  778. After you build your site, you will have several new files in assets/css and assets/js
  779. and a tipue_search.html that you can use as a basis for using this in your site.
  780. For more information about how to customize it and use it, please refer to the tipue
  781. docs at http://www.tipue.com/search/
  782. Tipue is under an MIT license (see MIT-LICENSE.txt)
  783. Here's a set of example settings for conf.py that should work nicely with the "site" theme::
  784. SEARCH_FORM = """
  785. <span class="navbar-form pull-left">
  786. <input type="text" id="tipue_search_input">
  787. </span>"""
  788. ANALYTICS = """
  789. <script type="text/javascript" src="/assets/js/tipuesearch_set.js"></script>
  790. <script type="text/javascript" src="/assets/js/tipuesearch.js"></script>
  791. <script type="text/javascript">
  792. $(document).ready(function() {
  793. $('#tipue_search_input').tipuesearch({
  794. 'mode': 'json',
  795. 'contentLocation': '/assets/js/tipuesearch_content.json',
  796. 'showUrl': false
  797. });
  798. });
  799. </script>
  800. """
  801. EXTRA_HEAD_DATA = """
  802. <link rel="stylesheet" type="text/css" href="/assets/css/tipuesearch.css">
  803. <div id="tipue_search_content" style="margin-left: auto; margin-right: auto; padding: 20px;"></div>
  804. """
  805. The <div> in EXTRA_HEAD_DATA is a hack but it will migrate into the <body> of the
  806. documents thanks to magic, and will hold the search results after the user searches.
  807. Mustache
  808. ~~~~~~~~
  809. This task gives you a ``mustache.html`` file which lets you access your whole
  810. blog without reloading the page, using client-side templates. Makes it much
  811. faster and modern ;-)
  812. License
  813. -------
  814. Nikola is released under a `MIT license <https://github.com/ralsina/nikola/blob/master/LICENSE.txt>`_ which
  815. is a free software license. Some components shipped along with Nikola, or required by it are
  816. released under other licenses.
  817. If you are not familiar with free software licensing: In general, you should be able to
  818. do pretty much anything you want, unless you modify Nikola. If you modify it, and share
  819. it with someone else, that someone else should get all your modifications under the same
  820. license you got it.