mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge remote-tracking branch 'origin/master' into fix-functional-tests
Conflicts: tests/support.py
This commit is contained in:
commit
fe9388a7a4
47 changed files with 1711 additions and 184 deletions
|
|
@ -8,14 +8,14 @@ Is it mandatory to have a configuration file?
|
|||
|
||||
No, it's not. Configuration files are just an easy way to configure Pelican.
|
||||
For basic operations, it's possible to specify options while invoking Pelican
|
||||
via the command line. See `pelican --help` for more information.
|
||||
via the command line. See ``pelican --help`` for more information.
|
||||
|
||||
I'm creating my own theme. How do I use Pygments for syntax highlighting?
|
||||
=========================================================================
|
||||
|
||||
Pygments adds some classes to the generated content. These classes are used by
|
||||
themes to style code syntax highlighting via CSS. Specifically, you can
|
||||
customize the appearance of your syntax highlighting via the `.codehilite pre`
|
||||
customize the appearance of your syntax highlighting via the ``.codehilite pre``
|
||||
class in your theme's CSS file. To see how various styles can be used to render
|
||||
Django code, for example, you can use the demo `on the project website
|
||||
<http://pygments.org/demo/15101/>`_.
|
||||
|
|
@ -30,7 +30,7 @@ How can I help?
|
|||
|
||||
There are several ways to help out. First, you can use Pelican and report any
|
||||
suggestions or problems you might have on `the bugtracker
|
||||
<http://github.com/ametaireau/pelican/issues>`_.
|
||||
<https://github.com/ametaireau/pelican/issues>`_.
|
||||
|
||||
If you want to contribute, please fork `the git repository
|
||||
<https://github.com/ametaireau/pelican/>`_, make your changes, and issue
|
||||
|
|
|
|||
|
|
@ -98,6 +98,9 @@ GITHUB_URL :
|
|||
|
||||
GOOGLE_ANALYTICS :
|
||||
'UA-XXXX-YYYY' pour activer Google analytics ;
|
||||
|
||||
GOSQUARED_SITENAME :
|
||||
'XXX-YYYYYY-X' pour activer GoSquared ;
|
||||
|
||||
JINJA_EXTENSIONS :
|
||||
Liste d'extension Jinja2 que vous souhaitez utiliser ;
|
||||
|
|
|
|||
|
|
@ -4,17 +4,48 @@ Getting started
|
|||
Installing
|
||||
==========
|
||||
|
||||
You're ready? Let's go! You can install Pelican via several different methods. The simplest is via `pip <http://pip.openplans.org/>`_::
|
||||
You're ready? Let's go! You can install Pelican via several different methods.
|
||||
The simplest is via `pip <http://www.pip-installer.org/>`_::
|
||||
|
||||
$ pip install pelican
|
||||
|
||||
If you have the project source, you can install Pelican using the distutils
|
||||
method. I recommend doing so in a virtualenv::
|
||||
If you don't have pip installed, an alternative method is easy_install::
|
||||
|
||||
$ virtualenv pelican_venv
|
||||
$ source bin/activate
|
||||
$ easy_install pelican
|
||||
|
||||
While the above is the simplest method, the recommended approach is to create
|
||||
a virtual environment for Pelican via `virtualenv <http://www.virtualenv.org/>`_
|
||||
and `virtualenvwrapper <http://www.doughellmann.com/projects/virtualenvwrapper/>`_
|
||||
before installing Pelican::
|
||||
|
||||
$ pip install virtualenvwrapper
|
||||
$ mkvirtualenv pelican
|
||||
|
||||
Once the virtual environment has been created and activated, Pelican can be
|
||||
be installed via pip or easy_install as noted above. Alternatively, if you
|
||||
have the project source, you can install Pelican using the distutils
|
||||
method::
|
||||
|
||||
$ cd path-to-Pelican-source
|
||||
$ python setup.py install
|
||||
|
||||
If you have Git installed and prefer to install the latest bleeding-edge
|
||||
version of Pelican rather than a stable release, use the following command::
|
||||
|
||||
$ pip install -e git://github.com/ametaireau/pelican#egg=pelican
|
||||
|
||||
Upgrading
|
||||
---------
|
||||
|
||||
If you installed a stable Pelican release via pip or easy_install and wish to
|
||||
upgrade to the latest stable release, you can do so by adding ``--upgrade`` to
|
||||
the relevant command. For pip, that would be::
|
||||
|
||||
$ pip install --upgrade pelican
|
||||
|
||||
If you installed Pelican via distutils or the bleeding-edge method, simply
|
||||
perform the same step to install the most recent version.
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
|
|
@ -24,7 +55,7 @@ At this time, Pelican is dependent on the following Python packages:
|
|||
* jinja2, for templating support
|
||||
* docutils, for supporting reStructuredText as an input format
|
||||
|
||||
If you're not using Python 2.7, you will also need `argparse`.
|
||||
If you're not using Python 2.7, you will also need the ``argparse`` package.
|
||||
|
||||
Optionally:
|
||||
|
||||
|
|
@ -42,7 +73,7 @@ file system (for instance, about the category of your articles), but some
|
|||
information you need to provide in the form of metadata inside your files.
|
||||
|
||||
You can provide this metadata in reStructuredText text files via the
|
||||
following syntax (give your file the `.rst` extension)::
|
||||
following syntax (give your file the ``.rst`` extension)::
|
||||
|
||||
My super title
|
||||
##############
|
||||
|
|
@ -53,11 +84,10 @@ following syntax (give your file the `.rst` extension)::
|
|||
:author: Alexis Metaireau
|
||||
|
||||
|
||||
You can also use Markdown syntax (with a file ending in `.md`).
|
||||
Markdown generation will not work until you explicitly install the `markdown`
|
||||
distribution. You can do so on a normal system using `pip install markdown`
|
||||
|
||||
::
|
||||
You can also use Markdown syntax (with a file ending in ``.md``).
|
||||
Markdown generation will not work until you explicitly install the ``Markdown``
|
||||
package, which can be done via ``pip install Markdown``. Metadata syntax for
|
||||
Markdown posts should follow this pattern::
|
||||
|
||||
Date: 2010-12-03
|
||||
Title: My super title
|
||||
|
|
@ -69,17 +99,17 @@ distribution. You can do so on a normal system using `pip install markdown`
|
|||
Note that, aside from the title, none of this metadata is mandatory: if the date
|
||||
is not specified, Pelican will rely on the file's "mtime" timestamp, and the
|
||||
category can be determined by the directory in which the file resides. For
|
||||
example, a file located at `python/foobar/myfoobar.rst` will have a category of
|
||||
`foobar`.
|
||||
example, a file located at ``python/foobar/myfoobar.rst`` will have a category of
|
||||
``foobar``.
|
||||
|
||||
Generate your blog
|
||||
------------------
|
||||
|
||||
To launch Pelican, just use the `pelican` command::
|
||||
To launch Pelican, just use the ``pelican`` command::
|
||||
|
||||
$ pelican /path/to/your/content/ [-s path/to/your/settings.py]
|
||||
|
||||
And… that's all! Your weblog will be generated and saved in the `content/`
|
||||
And… that's all! Your weblog will be generated and saved in the ``content/``
|
||||
folder.
|
||||
|
||||
The above command will use the default theme to produce a simple site. It's not
|
||||
|
|
@ -93,19 +123,23 @@ the options you can use::
|
|||
Kickstart a blog
|
||||
----------------
|
||||
|
||||
You also can use the `pelican-quickstart` script to start a new blog in
|
||||
seconds, by just answering few questions. Just run `pelican-quickstart` and
|
||||
You also can use the ``pelican-quickstart`` script to start a new blog in
|
||||
seconds by just answering a few questions. Just run ``pelican-quickstart`` and
|
||||
you're done! (Added in Pelican 3.0)
|
||||
|
||||
Pages
|
||||
-----
|
||||
|
||||
If you create a folder named `pages`, all the files in it will be used to
|
||||
If you create a folder named ``pages``, all the files in it will be used to
|
||||
generate static pages.
|
||||
|
||||
Then, use the `DISPLAY_PAGES_ON_MENU` setting, which will add all the pages to
|
||||
Then, use the ``DISPLAY_PAGES_ON_MENU`` setting, which will add all the pages to
|
||||
the menu.
|
||||
|
||||
If you want to exclude any pages from being linked to or listed in the menu
|
||||
then add a ``status: hidden`` attribute to its metadata. This is useful for
|
||||
things like making error pages that fit the generated theme of your site.
|
||||
|
||||
Importing an existing blog
|
||||
--------------------------
|
||||
|
||||
|
|
@ -115,8 +149,8 @@ a simple script. See :ref:`import`.
|
|||
Translations
|
||||
------------
|
||||
|
||||
It is possible to translate articles. To do so, you need to add a `lang` meta
|
||||
attribute to your articles/pages and set a `DEFAULT_LANG` setting (which is
|
||||
It is possible to translate articles. To do so, you need to add a ``lang`` meta
|
||||
attribute to your articles/pages and set a ``DEFAULT_LANG`` setting (which is
|
||||
English [en] by default). With those settings in place, only articles with the
|
||||
default language will be listed, and each article will be accompanied by a list
|
||||
of available translations for that article.
|
||||
|
|
@ -169,18 +203,18 @@ For RestructuredText::
|
|||
|
||||
For Markdown, format your code blocks thusly::
|
||||
|
||||
::identifier
|
||||
:::identifier
|
||||
your code goes here
|
||||
|
||||
The specified identifier should be one that appears on the
|
||||
`list of available lexers <http://pygments.org/docs/lexers/>`_.
|
||||
|
||||
Autoreload
|
||||
----------
|
||||
Auto-reload
|
||||
-----------
|
||||
|
||||
It's possible to tell Pelican to watch for your modifications, instead of
|
||||
manually launching it every time you want to see your changes. To enable this,
|
||||
run the `pelican` command with the `-r` or `--autoreload` options.
|
||||
manually re-running it every time you want to see your changes. To enable this,
|
||||
run the ``pelican`` command with the ``-r`` or ``--autoreload`` option.
|
||||
|
||||
Publishing drafts
|
||||
-----------------
|
||||
|
|
@ -203,3 +237,4 @@ You can either use your browser to open the files on your disk::
|
|||
Or run a simple web server using Python::
|
||||
|
||||
cd output && python -m SimpleHTTPServer
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ A French version of the documentation is available at :doc:`fr/index`.
|
|||
getting_started
|
||||
settings
|
||||
themes
|
||||
plugins
|
||||
internals
|
||||
pelican-themes
|
||||
importer
|
||||
|
|
|
|||
|
|
@ -12,34 +12,34 @@ original author wrote with some software design information.
|
|||
Overall structure
|
||||
=================
|
||||
|
||||
What `pelican` does is take a list of files and process them into some
|
||||
What Pelican does is take a list of files and process them into some
|
||||
sort of output. Usually, the input files are reStructuredText and Markdown
|
||||
files, and the output is a blog, but both input and output can be anything you
|
||||
want.
|
||||
|
||||
The logic is separated into different classes and concepts:
|
||||
|
||||
* `writers` are responsible for writing files: .html files, RSS feeds, and so
|
||||
* **Writers** are responsible for writing files: .html files, RSS feeds, and so
|
||||
on. Since those operations are commonly used, the object is created once and
|
||||
then passed to the generators.
|
||||
|
||||
* `readers` are used to read from various formats (Markdown and
|
||||
* **Readers** are used to read from various formats (Markdown and
|
||||
reStructuredText for now, but the system is extensible). Given a file, they return
|
||||
metadata (author, tags, category, etc.) and content (HTML-formatted).
|
||||
|
||||
* `generators` generate the different outputs. For instance, Pelican comes with
|
||||
`ArticlesGenerator` and `PageGenerator`. Given a configuration, they can do
|
||||
* **Generators** generate the different outputs. For instance, Pelican comes with
|
||||
``ArticlesGenerator`` and ``PageGenerator``. Given a configuration, they can do
|
||||
whatever they want. Most of the time, it's generating files from inputs.
|
||||
|
||||
* `pelican` also uses `templates`, so it's easy to write your own theme. The
|
||||
syntax is `jinja2`, and, trust me, really easy to learn, so don't hesitate
|
||||
to jump in and build your own theme.
|
||||
* Pelican also uses templates, so it's easy to write your own theme. The
|
||||
syntax is `Jinja2 <http://jinja.pocoo.org/>`_ and is very easy to learn, so
|
||||
don't hesitate to jump in and build your own theme.
|
||||
|
||||
How to implement a new reader?
|
||||
==============================
|
||||
|
||||
Is there an awesome markup language you want to add to Pelican?
|
||||
Well, the only thing you have to do is to create a class with a `read`
|
||||
Well, the only thing you have to do is to create a class with a ``read``
|
||||
method that returns HTML content and some metadata.
|
||||
|
||||
Take a look at the Markdown reader::
|
||||
|
|
@ -65,8 +65,8 @@ Take a look at the Markdown reader::
|
|||
Simple, isn't it?
|
||||
|
||||
If your new reader requires additional Python dependencies, then you should wrap
|
||||
their `import` statements in a `try...except` block. Then inside the reader's
|
||||
class, set the `enabled` class attribute to mark import success or failure.
|
||||
their ``import`` statements in a ``try...except`` block. Then inside the reader's
|
||||
class, set the ``enabled`` class attribute to mark import success or failure.
|
||||
This makes it possible for users to continue using their favourite markup method
|
||||
without needing to install modules for formats they don't use.
|
||||
|
||||
|
|
@ -76,17 +76,17 @@ How to implement a new generator?
|
|||
Generators have two important methods. You're not forced to create
|
||||
both; only the existing ones will be called.
|
||||
|
||||
* `generate_context`, that is called first, for all the generators.
|
||||
* ``generate_context``, that is called first, for all the generators.
|
||||
Do whatever you have to do, and update the global context if needed. This
|
||||
context is shared between all generators, and will be passed to the
|
||||
templates. For instance, the `PageGenerator` `generate_context` method finds
|
||||
all the pages, transforms them into objects, and populates the context with
|
||||
them. Be careful *not* to output anything using this context at this stage,
|
||||
as it is likely to change by the effect of other generators.
|
||||
templates. For instance, the ``PageGenerator`` ``generate_context`` method
|
||||
finds all the pages, transforms them into objects, and populates the context
|
||||
with them. Be careful *not* to output anything using this context at this
|
||||
stage, as it is likely to change by the effect of other generators.
|
||||
|
||||
* `generate_output` is then called. And guess what is it made for? Oh,
|
||||
* ``generate_output`` is then called. And guess what is it made for? Oh,
|
||||
generating the output. :) It's here that you may want to look at the context
|
||||
and call the methods of the `writer` object that is passed as the first
|
||||
argument of this function. In the `PageGenerator` example, this method will
|
||||
and call the methods of the ``writer`` object that is passed as the first
|
||||
argument of this function. In the ``PageGenerator`` example, this method will
|
||||
look at all the pages recorded in the global context and output a file on
|
||||
the disk (using the writer method `write_file`) for each page encountered.
|
||||
the disk (using the writer method ``write_file``) for each page encountered.
|
||||
|
|
|
|||
108
docs/plugins.rst
Normal file
108
docs/plugins.rst
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
.. _plugins:
|
||||
|
||||
Plugins
|
||||
#######
|
||||
|
||||
Since version 3.0, Pelican manages plugins. Plugins are a way to add features
|
||||
to Pelican without having to directly hack Pelican code.
|
||||
|
||||
Pelican is shipped with a set of core plugins, but you can easily implement
|
||||
your own (and this page describes how).
|
||||
|
||||
How to use plugins
|
||||
==================
|
||||
|
||||
To load plugins, you have to specify them in your settings file. You have two
|
||||
ways to do so.
|
||||
Either by specifying strings with the path to the callables::
|
||||
|
||||
PLUGINS = ['pelican.plugins.gravatar',]
|
||||
|
||||
Or by importing them and adding them to the list::
|
||||
|
||||
from pelican.plugins import gravatar
|
||||
PLUGINS = [gravatar, ]
|
||||
|
||||
If your plugins are not in an importable path, you can specify a ``PLUGIN_PATH``
|
||||
in the settings::
|
||||
|
||||
PLUGIN_PATH = "plugins"
|
||||
PLUGINS = ["list", "of", "plugins"]
|
||||
|
||||
How to create plugins
|
||||
=====================
|
||||
|
||||
Plugins are based on the concept of signals. Pelican sends signals, and plugins
|
||||
subscribe to those signals. The list of signals are defined in a following
|
||||
section.
|
||||
|
||||
The only rule to follow for plugins is to define a ``register`` callable, in
|
||||
which you map the signals to your plugin logic. Let's take a simple example::
|
||||
|
||||
from pelican import signals
|
||||
|
||||
def test(sender):
|
||||
print "%s initialized !!" % sender
|
||||
|
||||
def register():
|
||||
signals.initialized.connect(test)
|
||||
|
||||
|
||||
List of signals
|
||||
===============
|
||||
|
||||
Here is the list of currently implemented signals:
|
||||
|
||||
========================= ============================ =========================================
|
||||
Signal Arguments Description
|
||||
========================= ============================ =========================================
|
||||
initialized pelican object
|
||||
article_generate_context article_generator, metadata
|
||||
article_generator_init article_generator invoked in the ArticlesGenerator.__init__
|
||||
========================= ============================ =========================================
|
||||
|
||||
The list is currently small, don't hesitate to add signals and make a pull
|
||||
request if you need them!
|
||||
|
||||
List of plugins
|
||||
===============
|
||||
|
||||
Not all the list are described here, but a few of them have been extracted from
|
||||
the Pelican core and provided in ``pelican.plugins``. They are described here:
|
||||
|
||||
Tag cloud
|
||||
---------
|
||||
|
||||
Translation
|
||||
-----------
|
||||
|
||||
Github Activity
|
||||
---------------
|
||||
|
||||
This plugin makes use of the ``feedparser`` library that you'll need to
|
||||
install.
|
||||
|
||||
Set the ``GITHUB_ACTIVITY_FEED`` parameter to your Github activity feed.
|
||||
For example, my setting would look like::
|
||||
|
||||
GITHUB_ACTIVITY_FEED = 'https://github.com/kpanic.atom'
|
||||
|
||||
On the templates side, you just have to iterate over the ``github_activity``
|
||||
variable, as in the example::
|
||||
|
||||
{% if GITHUB_ACTIVITY_FEED %}
|
||||
<div class="social">
|
||||
<h2>Github Activity</h2>
|
||||
<ul>
|
||||
|
||||
{% for entry in github_activity %}
|
||||
<li><b>{{ entry[0] }}</b><br /> {{ entry[1] }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div><!-- /.github_activity -->
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
``github_activity`` is a list of lists. The first element is the title
|
||||
and the second element is the raw HTML from Github.
|
||||
|
|
@ -1,40 +1,40 @@
|
|||
Some history about pelican
|
||||
Some history about Pelican
|
||||
##########################
|
||||
|
||||
.. warning::
|
||||
|
||||
This page comes from a report the original author (Alexis Métaireau) wrote
|
||||
right after writing pelican, in december 2010. The information may not be
|
||||
up to date.
|
||||
right after writing Pelican, in December 2010. The information may not be
|
||||
up-to-date.
|
||||
|
||||
Pelican is a simple static blog generator. It parses markup files
|
||||
(markdown or restructured text for now), and generate a HTML folder
|
||||
(Markdown or reStructuredText for now) and generates an HTML folder
|
||||
with all the files in it.
|
||||
I've chosen to use python to implement pelican because it seemed to
|
||||
I've chosen to use Python to implement Pelican because it seemed to
|
||||
be simple and to fit to my needs. I did not wanted to define a class for
|
||||
each thing, but still wanted to keep my things loosely coupled.
|
||||
It turns out that it was exactly what I wanted. From time to time,
|
||||
thanks to the feedback of some users, it took me a very few time to
|
||||
provide fixes on it. So far, I've re-factored the pelican code by two
|
||||
times, each time took less than 30 minutes.
|
||||
provide fixes on it. So far, I've re-factored the Pelican code by two
|
||||
times; each time took less than 30 minutes.
|
||||
|
||||
Use case
|
||||
========
|
||||
|
||||
I was previously using wordpress, a solution you can host on a web
|
||||
I was previously using WordPress, a solution you can host on a web
|
||||
server to manage your blog. Most of the time, I prefer using markup
|
||||
languages such as Markdown or RestructuredText to type my articles.
|
||||
languages such as Markdown or reStructuredText to type my articles.
|
||||
To do so, I use vim. I think it is important to let the people choose the
|
||||
tool they want to write the articles. In my opinion, a blog manager
|
||||
should just allow you to take any kind of input and transform it to a
|
||||
weblog. That's what pelican does.
|
||||
weblog. That's what Pelican does.
|
||||
You can write your articles using the tool you want, and the markup
|
||||
language you want, and then generate a static HTML weblog
|
||||
language you want, and then generate a static HTML weblog.
|
||||
|
||||
.. image:: _static/overall.png
|
||||
|
||||
To be flexible enough, pelican have a template support, so you can
|
||||
easily write you own themes if you want to.
|
||||
To be flexible enough, Pelican has template support, so you can easily write
|
||||
your own themes if you want to.
|
||||
|
||||
Design process
|
||||
==============
|
||||
|
|
@ -42,19 +42,18 @@ Design process
|
|||
Pelican came from a need I have. I started by creating a single file
|
||||
application, and I have make it grow to support what it does by now.
|
||||
To start, I wrote a piece of documentation about what I wanted to do.
|
||||
Then, I have created the content I wanted to parse (the restructured
|
||||
text files), and started experimenting with the code.
|
||||
Pelican was 200 lines long, and contained almost ten functions and one
|
||||
class when it was first usable.
|
||||
Then, I created the content I wanted to parse (the reStructuredText files)
|
||||
and started experimenting with the code. Pelican was 200 lines long and
|
||||
contained almost ten functions and one class when it was first usable.
|
||||
|
||||
I have been facing different problems all over the time, and wanted to
|
||||
add features to pelican while using it. The first change I have done was
|
||||
I have been facing different problems all over the time and wanted to
|
||||
add features to Pelican while using it. The first change I have done was
|
||||
to add the support of a settings file. It is possible to pass the options to
|
||||
the command line, but can be tedious if there is a lot of them.
|
||||
In the same way, I have added the support of different things over
|
||||
time: atom feeds, multiple themes, multiple markup support, etc.
|
||||
At some point, it appears that the “only one file” mantra was not good
|
||||
enough for pelican, so I decided to rework a bit all that, and split this in
|
||||
time: Atom feeds, multiple themes, multiple markup support, etc.
|
||||
At some point, it appears that the "only one file" mantra was not good
|
||||
enough for Pelican, so I decided to rework a bit all that, and split this in
|
||||
multiple different files.
|
||||
|
||||
I’ve separated the logic in different classes and concepts:
|
||||
|
|
@ -64,59 +63,59 @@ I’ve separated the logic in different classes and concepts:
|
|||
Since those operations are commonly used, the object is created
|
||||
once, and then passed to the generators.
|
||||
|
||||
* *readers* are used to read from various formats (Markdown, and
|
||||
Restructured Text for now, but the system is extensible). Given a
|
||||
file, they return metadata (author, tags, category etc) and
|
||||
content (HTML formated).
|
||||
* *readers* are used to read from various formats (Markdown and
|
||||
reStructuredText for now, but the system is extensible). Given a
|
||||
file, they return metadata (author, tags, category, etc) and
|
||||
content (HTML formatted).
|
||||
|
||||
* *generators* generate the different outputs. For instance, pelican
|
||||
* *generators* generate the different outputs. For instance, Pelican
|
||||
comes with an ArticlesGenerator and PagesGenerator, into
|
||||
others. Given a configuration, they can do whatever you want
|
||||
them to do. Most of the time it’s generating files from inputs
|
||||
them to do. Most of the time it's generating files from inputs
|
||||
(user inputs and files).
|
||||
|
||||
I also deal with contents objects. They can be `Articles`, `Pages`, `Quotes`,
|
||||
or whatever you want. They are defined in the contents.py module,
|
||||
and represent some content to be used by the program.
|
||||
I also deal with contents objects. They can be ``Articles``, ``Pages``,
|
||||
``Quotes``, or whatever you want. They are defined in the ``contents.py``
|
||||
module and represent some content to be used by the program.
|
||||
|
||||
In more details
|
||||
===============
|
||||
In more detail
|
||||
==============
|
||||
|
||||
Here is an overview of the classes involved in pelican.
|
||||
Here is an overview of the classes involved in Pelican.
|
||||
|
||||
.. image:: _static/uml.jpg
|
||||
|
||||
The interface do not really exists, and I have added it only to clarify the
|
||||
whole picture. I do use duck typing, and not interfaces.
|
||||
The interface does not really exist, and I have added it only to clarify the
|
||||
whole picture. I do use duck typing and not interfaces.
|
||||
|
||||
Internally, the following process is followed:
|
||||
|
||||
* First of all, the command line is parsed, and some content from
|
||||
the user are used to initialize the different generator objects.
|
||||
the user is used to initialize the different generator objects.
|
||||
|
||||
* A `context` is created. It contains the settings from the command
|
||||
* A ``context`` is created. It contains the settings from the command
|
||||
line and a settings file if provided.
|
||||
* The `generate_context` method of each generator is called, updating
|
||||
* The ``generate_context`` method of each generator is called, updating
|
||||
the context.
|
||||
|
||||
* The writer is created, and given to the `generate_output` method of
|
||||
* The writer is created and given to the ``generate_output`` method of
|
||||
each generator.
|
||||
|
||||
I make two calls because it is important that when the output is
|
||||
generated by the generators, the context will not change. In other
|
||||
words, the first method `generate_context` should modify the context,
|
||||
whereas the second `generate_output` method should not.
|
||||
words, the first method ``generate_context`` should modify the context,
|
||||
whereas the second ``generate_output`` method should not.
|
||||
|
||||
Then, it is up to the generators to do what the want, in the
|
||||
`generate_context` and `generate_content` method.
|
||||
Taking the `ArticlesGenerator` class will help to understand some others
|
||||
concepts. Here is what happens when calling the `generate_context`
|
||||
``generate_context`` and ``generate_content`` method.
|
||||
Taking the ``ArticlesGenerator`` class will help to understand some others
|
||||
concepts. Here is what happens when calling the ``generate_context``
|
||||
method:
|
||||
|
||||
* Read the folder “path”, looking for restructured text files, load
|
||||
each of them, and construct a content object (`Article`) with it. To do so,
|
||||
use `Reader` objects.
|
||||
* Update the `context` with all those articles.
|
||||
each of them, and construct a content object (``Article``) with it. To do so,
|
||||
use ``Reader`` objects.
|
||||
* Update the ``context`` with all those articles.
|
||||
|
||||
Then, the `generate_content` method uses the `context` and the `writer` to
|
||||
generate the wanted output
|
||||
Then, the ``generate_content`` method uses the ``context`` and the ``writer`` to
|
||||
generate the wanted output.
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ Setting name (default value) What doe
|
|||
default datetime object by passing the tuple to
|
||||
the datetime.datetime constructor.
|
||||
`JINJA_EXTENSIONS` (``[]``) A list of any Jinja2 extensions you want to use.
|
||||
`DELETE_OUTPUT_DIRECTORY` (``False``) Delete the output directory as well as
|
||||
the generated files.
|
||||
`DELETE_OUTPUT_DIRECTORY` (``False``) Delete the content of the output directory before
|
||||
generating new files.
|
||||
`LOCALE` (''[#]_) Change the locale. A list of locales can be provided
|
||||
here or a single string representing one locale.
|
||||
When providing a list, all the locales will be tried
|
||||
|
|
@ -65,6 +65,7 @@ Setting name (default value) What doe
|
|||
`rst2pdf`.
|
||||
`RELATIVE_URLS` (``True``) Defines whether Pelican should use relative URLs or
|
||||
not.
|
||||
`PLUGINS` (``[]``) The list of plugins to load. See :ref:`plugins`.
|
||||
`SITENAME` (``'A Pelican Blog'``) Your site name
|
||||
`SITEURL` Base URL of your website. Not defined by default,
|
||||
which means the base URL is assumed to be "/" with a
|
||||
|
|
@ -94,6 +95,12 @@ Setting name (default value) What doe
|
|||
index pages for collections of content e.g. tags and
|
||||
category index pages.
|
||||
`PAGINATED_DIRECT_TEMPLATES` (``('index',)``) Provides the direct templates that should be paginated.
|
||||
`SUMMARY_MAX_LENGTH` (``50``) When creating a short summary of an article, this will
|
||||
be the default length in words of the text created.
|
||||
This only applies if your content does not otherwise
|
||||
specify a summary. Setting to None will cause the summary
|
||||
to be a copy of the original content.
|
||||
|
||||
===================================================================== =====================================================================
|
||||
|
||||
.. [#] Default is the system locale.
|
||||
|
|
@ -373,6 +380,7 @@ Setting name (default value) What does it do?
|
|||
value is `static`, but if your theme has
|
||||
other static paths, you can put them here.
|
||||
`CSS_FILE` (``'main.css'``) Specify the CSS file you want to load.
|
||||
`WEBASSETS` (``False``) Asset management with `webassets` (see below)
|
||||
================================================ =====================================================
|
||||
|
||||
By default, two themes are available. You can specify them using the `-t` option:
|
||||
|
|
@ -400,6 +408,7 @@ Setting name What does it do ?
|
|||
`GITHUB_URL` Your GitHub URL (if you have one). It will then
|
||||
use this information to create a GitHub ribbon.
|
||||
`GOOGLE_ANALYTICS` 'UA-XXXX-YYYY' to activate Google Analytics.
|
||||
`GOSQUARED_SITENAME` 'XXX-YYYYYY-X' to activate GoSquared.
|
||||
`MENUITEMS` A list of tuples (Title, URL) for additional menu
|
||||
items to appear at the beginning of the main menu.
|
||||
`PIWIK_URL` URL to your Piwik server - without 'http://' at the
|
||||
|
|
@ -422,7 +431,58 @@ adding the following to your configuration::
|
|||
|
||||
CSS_FILE = "wide.css"
|
||||
|
||||
.. _pelican-themes: :doc:`pelican-themes`
|
||||
Asset management
|
||||
----------------
|
||||
|
||||
The `WEBASSETS` setting allows to use the `webassets`_ module to manage assets
|
||||
(css, js). The module must first be installed::
|
||||
|
||||
pip install webassets
|
||||
|
||||
`webassets` allows to concatenate your assets and to use almost all of the
|
||||
hype tools of the moment (see the `documentation`_):
|
||||
|
||||
* css minifier (`cssmin`, `yuicompressor`, ...)
|
||||
* css compiler (`less`, `sass`, ...)
|
||||
* js minifier (`uglifyjs`, `yuicompressor`, `closure`, ...)
|
||||
|
||||
Others filters include gzip compression, integration of images in css with
|
||||
`datauri` and more. Webassets also append a version identifier to your asset
|
||||
url to convince browsers to download new versions of your assets when you use
|
||||
far future expires headers.
|
||||
|
||||
When using it with Pelican, `webassets` is configured to process assets in the
|
||||
``OUTPUT_PATH/theme`` directory. You can use it in your templates with a
|
||||
template tag, for example:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% assets filters="cssmin", output="css/style.min.css", "css/inuit.css", "css/pygment-monokai.css", "css/main.css" %}
|
||||
<link rel="stylesheet" href="{{ ASSET_URL }}">
|
||||
{% endassets %}
|
||||
|
||||
will produce a minified css file with the version identifier:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<link href="http://{SITEURL}/theme/css/style.min.css?b3a7c807" rel="stylesheet">
|
||||
|
||||
Another example for javascript:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% assets filters="uglifyjs,gzip", output="js/packed.js", "js/jquery.js", "js/base.js", "js/widgets.js" %}
|
||||
<script src="{{ ASSETS_URL }}"></script>
|
||||
{% endassets %}
|
||||
|
||||
will produce a minified and gzipped js file:
|
||||
|
||||
.. code-block:: html
|
||||
|
||||
<script src="http://{SITEURL}/theme/js/packed.js?00703b9d"></script>
|
||||
|
||||
.. _webassets: https://github.com/miracle2k/webassets
|
||||
.. _documentation: http://webassets.readthedocs.org/en/latest/builtin_filters.html
|
||||
|
||||
Example settings
|
||||
================
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@
|
|||
How to create themes for Pelican
|
||||
################################
|
||||
|
||||
Pelican uses the great `jinja2 <http://jinja.pocoo.org>`_ templating engine to
|
||||
generate its HTML output. The jinja2 syntax is really simple. If you want to
|
||||
create your own theme, feel free to take inspiration from the "simple" theme,
|
||||
which is available `here
|
||||
<https://github.com/ametaireau/pelican/tree/master/pelican/themes/simple/templates>`_
|
||||
Pelican uses the great `Jinja2 <http://jinja.pocoo.org/>`_ templating engine to
|
||||
generate its HTML output. Jinja2 syntax is really simple. If you want to
|
||||
create your own theme, feel free to take inspiration from the `"simple" theme
|
||||
<https://github.com/ametaireau/pelican/tree/master/pelican/themes/simple/templates>`_.
|
||||
|
||||
Structure
|
||||
=========
|
||||
|
|
|
|||
|
|
@ -10,13 +10,33 @@ GitHub comes with an interesting "pages" feature: you can upload things there
|
|||
and it will be available directly from their servers. As Pelican is a static
|
||||
file generator, we can take advantage of this.
|
||||
|
||||
User Pages
|
||||
----------
|
||||
GitHub allows you to create user pages in the form of ``username.github.com``.
|
||||
Whatever is created in the master branch will be published. For this purpose,
|
||||
just the output generated by Pelican needs to pushed to GitHub.
|
||||
|
||||
So given a repository containing your articles, just run Pelican over the posts
|
||||
and deploy the master branch to GitHub::
|
||||
|
||||
$ pelican -s pelican.conf.py ./path/to/posts -o /path/to/output
|
||||
|
||||
Now add all the files in the output directory generated by Pelican::
|
||||
|
||||
$ git add /path/to/output/*
|
||||
$ git commit -am "Your Message"
|
||||
$ git push origin master
|
||||
|
||||
Project Pages
|
||||
-------------
|
||||
For creating Project pages, a branch called ``gh-pages`` is used for publishing.
|
||||
The excellent `ghp-import <https://github.com/davisp/ghp-import>`_ makes this
|
||||
really easy. You will have to install it::
|
||||
really easy, which can be installed via::
|
||||
|
||||
$ pip install ghp-import
|
||||
|
||||
Then, given a repository containing your articles, you would simply have
|
||||
to run Pelican and upload the output to GitHub::
|
||||
Then, given a repository containing your articles, you would simply run
|
||||
Pelican and upload the output to GitHub::
|
||||
|
||||
$ pelican -s pelican.conf.py .
|
||||
$ ghp-import output
|
||||
|
|
@ -25,9 +45,8 @@ to run Pelican and upload the output to GitHub::
|
|||
And that's it.
|
||||
|
||||
If you want, you can put that directly into a post-commit hook, so each time you
|
||||
commit, your blog is up to date on GitHub!
|
||||
commit, your blog is up-to-date on GitHub!
|
||||
|
||||
Put the following into `.git/hooks/post-commit`::
|
||||
Put the following into ``.git/hooks/post-commit``::
|
||||
|
||||
pelican -s pelican.conf.py . && ghp-import output && git push origin
|
||||
gh-pages
|
||||
pelican -s pelican.conf.py . && ghp-import output && git push origin gh-pages
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue