Skip to content

Commit

Permalink
merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Sep 4, 2015
2 parents 9d1a505 + 096cd9f commit dbb0403
Show file tree
Hide file tree
Showing 19 changed files with 470 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -6,6 +6,8 @@ Features

* Made TAG_PATH translatable (Issue #1914)
* Made CATEGORY_PATH translatable (Issue #1914)
* Display post counts for archive links (Issue #2011)
* Document link/path handlers (Issue #2008)

Bugfixes
--------
Expand Down
11 changes: 10 additions & 1 deletion docs/manual.txt
Expand Up @@ -207,6 +207,15 @@ To set Nikola up and create your first site, read the `Getting Started Guide <ht
Creating a Blog Post
--------------------

.. sidebar:: Magic Links

You will want to do things like "link from one post to another" or "link to an image gallery",
etc. Sure, you can just figure out the URLs for each thing and use that. Or you can use
Nikola's special link URLs. Those are done using the syntax ``link://kind/name`` and
a full list of the included ones is `here <link://slug/path-handlers>`__ (BTW, I linked
to that using ``link://slug/path-handlers``)


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.
Expand Down Expand Up @@ -637,7 +646,7 @@ Categories and tags use simple lists by default that show only titles and
dates; however, you can switch them to full indexes by using
``CATEGORY_PAGES_ARE_INDEXES`` and ``TAG_PAGES_ARE_INDEXES``, respectively.

Something similar happens with authors. To use full indexes in authors, set
Something similar happens with authors. To use full indexes in authors, set
``AUTHOR_PAGES_ARE_INDEXES`` to ``True``.

Static indexes
Expand Down
240 changes: 240 additions & 0 deletions docs/path_handlers.txt
@@ -0,0 +1,240 @@
.. title: Path Handlers for Nikola
.. slug: path-handlers
.. author: The Nikola Team

Nikola supports special links with the syntax ``link://kind/name``. Here is
the description for all the supported kinds.


archive
Link to archive path, name is the year.

Example:

link://archive/2013 => /archives/2013/index.html


archive_atom
Link to atom archive path, name is the year.

Example:

link://archive_atom/2013 => /archives/2013/index.atom


author
Link to an author's page.

Example:

link://author/joe => /authors/joe.html


author_atom
Link to an author's Atom feed.

Example:

link://author_atom/joe => /authors/joe.atom


author_index
Link to the author's index.

Example:

link://authors/ => /authors/index.html


author_rss
Link to an author's RSS feed.

Example:

link://author_rss/joe => /authors/joe.rss


category
A link to a category.

Example:

link://category/dogs => /categories/dogs.html


category_atom
A link to a category's Atom feed.

Example:

link://category_atom/dogs => /categories/dogs.atom


category_index
A link to the category index.

Example:

link://category_index => /categories/index.html


category_rss
A link to a category's RSS feed.

Example:

link://category_rss/dogs => /categories/dogs.xml


filename
Link to post or story by source filename.

Example:

link://filename/manual.txt => /docs/handbook.html


gallery
Link to an image gallery's path.

It will try to find a gallery with that name if it's not ambiguous
or with that path. For example:

link://gallery/london => /galleries/trips/london/index.html

link://gallery/trips/london => /galleries/trips/london/index.html


gallery_global
Link to the global gallery path, which contains all the images in galleries.

There is only one copy of an image on multilingual blogs, in the site root.

link://gallery_global/london => /galleries/trips/london/index.html

link://gallery_global/trips/london => /galleries/trips/london/index.html

(a ``gallery`` link could lead to eg. /en/galleries/trips/london/index.html)


gallery_rss
Link to an image gallery's RSS feed.

It will try to find a gallery with that name if it's not ambiguous
or with that path. For example:

link://gallery_rss/london => /galleries/trips/london/rss.xml

link://gallery_rss/trips/london => /galleries/trips/london/rss.xml


index
Link to a numbered index.

Example:

link://index/3 => /index-3.html


index_atom
Link to a numbered Atom index.

Example:

link://index_atom/3 => /index-3.atom


listing
A link to a listing.

It will try to use the file name if it's not ambiguous, or the file path.

Example:

link://listing/hello.py => /listings/tutorial/hello.py.html

link://listing/tutorial/hello.py => /listings/tutorial/hello.py.html


post_path
Link to the destination of an element in the POSTS/PAGES settings.

Example:

link://post_path/posts => /blog


root
Link to the current language's root.

Example:

link://root_path => /

link://root_path => /translations/spanish/


rss
A link to the RSS feed path.

Example:

link://rss => /blog/rss.xml


section_index
Link to the index for a section.

Example:

link://section_index/cars => /cars/index.html


section_index_atom
Link to the Atom index for a section.

Example:

link://section_index_atom/cars => /cars/index.atom


slug
A link to a post with given slug, if not ambiguous.

Example:

links://slug/yellow-camaro => /posts/cars/awful/yellow-camaro/index.html


tag
A link to a tag's page.

Example:

link://tag/cats => /tags/cats.html


tag_atom
A link to a tag's Atom feed.

Example:

link://tag_atom/cats => /tags/cats.atom


tag_index
A link to the tag index.

Example:

link://tag_index => /tags/index.html


tag_rss
A link to a tag's RSS feed.

Example:

link://tag_rss/cats => /tags/cats.xml


1 change: 1 addition & 0 deletions docs/sphinx/path_handlers.txt
1 change: 1 addition & 0 deletions nikola/data/samplesite/stories/path_handlers.txt
5 changes: 4 additions & 1 deletion nikola/data/themes/base-jinja/templates/list.tmpl
Expand Up @@ -8,8 +8,11 @@
</header>
{% if items %}
<ul class="postlist">
{% for text, link in items %}
{% for text, link, count in items %}
<li><a href="{{ link }}">{{ text }}</a>
{% if count %}
({{ count }})
{% endif %}
{% endfor %}
</ul>
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion nikola/data/themes/base-jinja/templates/sectionindex.tmpl
Expand Up @@ -16,6 +16,6 @@
<p class="feedlink"><a href="{{ _link('section_index_atom', posts[0].section_slug()) }}" type="application/atom+xml">{{ messages('Updates') }}</a></p>
{% endif %}
</header>
{{ parent.content() }}
{{ super() }}
</article>
{% endblock %}
5 changes: 4 additions & 1 deletion nikola/data/themes/base/templates/list.tmpl
Expand Up @@ -8,8 +8,11 @@
</header>
%if items:
<ul class="postlist">
% for text, link in items:
% for text, link, count in items:
<li><a href="${link}">${text}</a>
% if count:
(${count})
% endif
% endfor
</ul>
%else:
Expand Down
32 changes: 27 additions & 5 deletions nikola/nikola.py
Expand Up @@ -814,7 +814,7 @@ def init_plugins(self, commands_only=False):
# Remove compiler extensions we don't need
if p[-1].details.has_option('Nikola', 'compiler') and p[-1].details.get('Nikola', 'compiler') in self.disabled_compilers:
bad_candidates.add(p)
utils.LOGGER.debug('Not loading comopiler extension {}', p[-1].name)
utils.LOGGER.debug('Not loading compiler extension {}', p[-1].name)
self.plugin_manager._candidates = list(set(self.plugin_manager._candidates) - bad_candidates)
self.plugin_manager.loadPlugins()

Expand Down Expand Up @@ -1368,21 +1368,38 @@ def path(self, kind, name, lang=None, is_link=False):
return ""

def post_path(self, name, lang):
"""Handle post_path paths."""
"""Link to the destination of an element in the POSTS/PAGES settings.
Example:
link://post_path/posts => /blog
"""
return [_f for _f in [self.config['TRANSLATIONS'][lang],
os.path.dirname(name),
self.config['INDEX_FILE']] if _f]

def root_path(self, name, lang):
"""Handle root_path paths."""
"""Link to the current language's root.
Example:
link://root_path => /
link://root_path => /translations/spanish/
"""
d = self.config['TRANSLATIONS'][lang]
if d:
return [d, '']
else:
return []

def slug_path(self, name, lang):
"""Handle slug paths."""
"""A link to a post with given slug, if not ambiguous.
Example:
links://slug/yellow-camaro => /posts/cars/awful/yellow-camaro/index.html
"""
results = [p for p in self.timeline if p.meta('slug') == name]
if not results:
utils.LOGGER.warning("Cannot resolve path request for slug: {0}".format(name))
Expand All @@ -1392,7 +1409,12 @@ def slug_path(self, name, lang):
return [_f for _f in results[0].permalink(lang).split('/') if _f]

def filename_path(self, name, lang):
"""Handle filename paths."""
"""Link to post or story by source filename.
Example:
link://filename/manual.txt => /docs/handbook.html
"""
results = [p for p in self.timeline if p.source_path == name]
if not results:
utils.LOGGER.warning("Cannot resolve path request for filename: {0}".format(name))
Expand Down

0 comments on commit dbb0403

Please sign in to comment.