Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into navigation_alt_links
  • Loading branch information
Kwpolska committed May 13, 2018
2 parents 33361bc + 4d95b69 commit f2b3520
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -14,6 +14,8 @@ Features

* Add ``NAVIGATION_ALT_LINKS`` option, displayed on the right side in
bootstrap4/bootblog4 (Issue #3030)
* Added documentation of Post objects to list of template variables
(Issue #3003)
* Support featured posts in bootblog4 (Issue #2964)
* Add ``THEME_CONFIG`` setting that themes can use in any way
* Use youtube-nocookie.com for better privacy in ``youtube`` reST
Expand Down
54 changes: 54 additions & 0 deletions docs/template-variables.rst
Expand Up @@ -17,6 +17,8 @@ Variables available in templates are listed below.
<https://getnikola.com/conf.html>`_ respectively.
* Templates often create their own functions (macros), and import macros from
other templates. Those macros are not listed here.
* This list has a partial documentation of post objects, but no other objects. For full docs, please consult
the code, or auto-generated code docs on `ReadTheDocs <http://nikola.readthedocs.io/>`_.

Variables and functions come from three places:

Expand Down Expand Up @@ -462,4 +464,56 @@ Name Type Description
``_link`` function ``Nikola.link`` function
================== ========== =====================================

Post object attributes
----------------------

*Usable anywhere post objects are accessible.*

This list only includes variables that make sense for templates. Some function signatures have been shortened to save space, ``?`` means the argument has default value.

More docs: `nikola.post.Post on ReadTheDocs <http://nikola.readthedocs.io/en/latest/nikola/#nikola.post.Post>`_. Check out the source of the Post class as well.

=================================================================== ========== =============================================================
Name Type Description
=================================================================== ========== =============================================================
``alltags`` list<str> All tags for the post
``author(lang=None)`` str Localized author or ``BLOG_AUTHOR``
``base_path`` str ``cache`` path with local ``os.sep``
``category_from_destpath`` bool If category was set by ``CATEGORY_DESTPATH_AS_DEFAULT``
``data(key, lang=None)`` ? Access to post data
``date`` datetime Date of post (from meta)
``description(key, lang=None)`` str Description of post (from meta)
``destination_path(lang?, extension?, sep?)`` str Destination path of post
``formatted_date(date_format, date=None)`` str Format a date (default: post date)
``formatted_updated(date_format)`` str Format the last update date
``guid(lang=None)`` str GUID of post (used for feeds)
``has_math`` bool If the post has math
``has_pretty_url(lang)`` bool If the post has a pretty URL
``is_draft`` bool If the post is a draft
``is_post`` bool If the post is not a page
``is_private`` bool If the post is private
``is_translation_available(lang)`` bool If the post is available in (translated to) a given language
``is_two_file`` bool If the post uses two-file metadata
``meta(key, lang=None)`` ? Metadata of the post (assumes current language)
``next_post`` Post Next post in the order
``paragraph_count`` int Paragraph count for a post
``permalink(lang?, absolute?, extension?, query?)`` str Permanent link for a post
``post_name`` str Source path, without extension
``post_status`` str Post status meta field (published, featured, private, draft)
``prev_post`` Post Previous post in the order
``previewimage`` str Preview image of the post
``publish_later`` bool True if the post is not yet published (due to date)
``reading_time`` int Approximate reading time in minutes (220 wpm)
``remaining_paragraph_count`` int Paragraph count after the teaser
``remaining_reading_time`` int Reading time after the teaser
``source_link`` str Absolute link to the post's source
``tags`` list<str> Tags for the current language
``tags_for_language(lang)`` list<str> Tags for a given language
``text(lang?, teaser_only?, strip_html?, show_read_more_link?, …)`` str The text of a post
``title(lang=None)`` str Localized title of post
``translated_to`` list<str> List of languages of post
``updated`` datetime Date of last update (from meta)
``use_in_feeds`` bool If this post should be displayed in feeds
=================================================================== ========== =============================================================

.. vim: nowrap textwidth=0
4 changes: 2 additions & 2 deletions nikola/plugins/task/indexes.py
Expand Up @@ -118,8 +118,8 @@ def provide_context_and_uptodate(self, classification, lang, node=None):
"title": self.site.config["INDEXES_TITLE"](lang) or self.site.config["BLOG_TITLE"](lang),
"description": self.site.config["BLOG_DESCRIPTION"](lang),
"pagekind": ["main_index", "index"],
"featured": [p for p in self.site.posts if p.post_status == 'featured'
and (lang in p.translated_to or kw["show_untranslated_posts"])],
"featured": [p for p in self.site.posts if p.post_status == 'featured' and
(lang in p.translated_to or kw["show_untranslated_posts"])],
}
kw.update(context)
return context, kw
Expand Down
4 changes: 2 additions & 2 deletions nikola/post.py
Expand Up @@ -466,11 +466,11 @@ def template_name(self):
return self.meta[lang]['template'] or self._template_name

def formatted_date(self, date_format, date=None):
"""Return the formatted date as unicode."""
"""Return the formatted date as string."""
return utils.LocaleBorg().formatted_date(date_format, date if date else self.date)

def formatted_updated(self, date_format):
"""Return the updated date as unicode."""
"""Return the updated date as string."""
return self.formatted_date(date_format, self.updated)

def title(self, lang=None):
Expand Down

0 comments on commit f2b3520

Please sign in to comment.