Skip to content
Permalink
Browse files
Merge branch 'master' into atom-one-file
  • Loading branch information
Kwpolska committed May 2, 2018
2 parents c626286 + 81a3aef commit d2ee19309b54673c190d525a296b1a890779eb50
@@ -7,6 +7,9 @@ Important compatibility changes
* Rename ``crumbs.tmpl`` to ``ui_helper.tmpl`` and the breadcrumbs
``bar`` function to ``breadcrumbs`` (your templates may need
changing as well)
* Rename ``post.is_mathjax`` to ``post.has_math``. Themes using
``post.is_mathjax`` must be updated; it is recommended that they are
changed to use ``math_helper.tmpl``.
* Reading reST docinfo metadata, including first heading as title,
requires ``USE_REST_DOCINFO_METADATA`` now (Issue #2987)
* RSS feeds might have changed their places due to ``RSS_PATH``
@@ -21,6 +24,9 @@ Features
* Add ``DISABLE_MAIN_ATOM_FEED`` setting (Issue #3016, Issue #3039)
* Add ``ATOM_FILENAME_BASE`` setting (defaults to ``index`` for
existing sites, but ``feed`` for new sites) (Issue #3016)
* Tags ``draft``, ``private`` and ``mathjax`` are no longer treated
special if ``USE_TAG_METADATA`` is set to ``False`` (default for
new sites) (Issue #2761)
* Produce a better error message when a template referenced in another
template is missing (Issue #3055)
* Support captioned images and image ordering in galleries (Issue #3017)
@@ -3,7 +3,8 @@
.. date: 2012-03-30 23:00:00 UTC-03:00
.. link:
.. description:
.. tags: mathjax
.. tags:
.. has_math: true
.. author: The Nikola Team
The Nikola Handbook
@@ -299,8 +300,14 @@ date
Adding a timezone is recommended. (required for posts)

tags
Comma-separated tags of the post. Some tags have special meaning, including
``draft``, ``private``, ``mathjax``
Comma-separated tags of the post.

status
Can be set to ``published`` (default), ``featured``, ``draft``, or ``private``.

has_math
If set to ``true`` or ``yes``, MathJax resp. KaTeX support is enabled
for this post.

category
Like tags, except each post can have only one, and they usually have
@@ -809,11 +816,11 @@ Or you can completely customize the link using the ``READ_MORE_LINK`` option.
Drafts
~~~~~~

If you add a "draft" tag to a post, then it will not be shown in indexes and feeds.
It *will* be compiled, and if you deploy it it *will* be made available, so use
with care. If you wish your drafts to be not available in your deployed site, you
can set ``DEPLOY_DRAFTS = False`` in your configuration. This will not work if
lazily include ``nikola build`` in your ``DEPLOY_COMMANDS``.
If you set the ``status`` metadata field of a post to ``draft``, it will not be shown
in indexes and feeds. It *will* be compiled, and if you deploy it it *will* be made
available, so use with care. If you wish your drafts to be not available in your
deployed site, you can set ``DEPLOY_DRAFTS = False`` in your configuration. This will
not work if lazily include ``nikola build`` in your ``DEPLOY_COMMANDS``.

Also if a post has a date in the future, it will not be shown in indexes until
you rebuild after that date. This behavior can be disabled by setting
@@ -826,9 +833,9 @@ Generally, you want FUTURE_IS_NOW and DEPLOY_FUTURE to be the same value.
Private Posts
~~~~~~~~~~~~~

If you add a "private" tag to a post, then it will not be shown in indexes and feeds.
It *will* be compiled, and if you deploy it it *will* be made available, so it will
not generate 404s for people who had linked to it.
If you set the ``status`` metadata field of a post to ``private``, it will not be shown
in indexes and feeds. It *will* be compiled, and if you deploy it it *will* be made
available, so it will not generate 404s for people who had linked to it.

Queuing Posts
~~~~~~~~~~~~~
@@ -967,8 +974,6 @@ Please note that tags are case-sensitive and that you cannot have two tags that
ERROR: Nikola: Tag Nikola is used in: posts/second-post.rst
ERROR: Nikola: Tag nikola is used in: posts/1.rst

Nikola uses some tags to mark a post as “special” — those are ``draft``, ``private``, ``mathjax`` (for math support).

You can also generate a tag cloud with the `tx3_tag_cloud <https://plugins.getnikola.com/#tx3_tag_cloud>`_ plugin.

Categories
@@ -2290,9 +2295,9 @@ Nikola uses MathJax by default. If you want to use KaTeX (faster and prettier,
but may not support every feature yet), set ``USE_KATEX = True`` in
``conf.py``.

To use mathematics in a post, you **must** add the ``mathjax`` tag, no matter
which renderer you are using. (Exception: posts that are Jupyter Notebooks are
automatically marked as math)
To use mathematics in a post, you **must** set the ``has_math`` metadata field
to ``true``. (Exception: posts that are Jupyter Notebooks are automatically
marked as math)

.. Note to editors: the paragraph below uses U+200B, zero-width space. Don’t break it.
@@ -1304,3 +1304,12 @@ GLOBAL_CONTEXT = {}
# GLOBAL_CONTEXT as parameter when the template is about to be
# rendered
GLOBAL_CONTEXT_FILLER = []

# If set to True, the tags 'draft', 'mathjax' and 'private' have special
# meaning. If set to False, these tags are handled like regular tags.
USE_TAG_METADATA = False

# If set to True, a warning is issued if one of the 'draft', 'mathjax'
# and 'private' tags are found in a post. Useful for checking that
# migration was successful.
WARN_ABOUT_TAG_METADATA = False
@@ -45,25 +45,25 @@
{% endmacro %}

{% macro math_scripts_ifpost(post) %}
{% if post.is_mathjax %}
{% if post.has_math %}
{{ math_scripts() }}
{% endif %}
{% endmacro %}

{% macro math_scripts_ifposts(posts) %}
{% if posts|selectattr("is_mathjax")|list %}
{% if posts|selectattr("has_math")|list %}
{{ math_scripts() }}
{% endif %}
{% endmacro %}

{% macro math_styles_ifpost(post) %}
{% if post.is_mathjax %}
{% if post.has_math %}
{{ math_styles() }}
{% endif %}
{% endmacro %}

{% macro math_styles_ifposts(posts) %}
{% if posts|selectattr("is_mathjax")|list %}
{% if posts|selectattr("has_math")|list %}
{{ math_styles() }}
{% endif %}
{% endmacro %}
@@ -45,25 +45,25 @@
</%def>

<%def name="math_scripts_ifpost(post)">
%if post.is_mathjax:
%if post.has_math:
${math_scripts()}
%endif
</%def>

<%def name="math_scripts_ifposts(posts)">
%if any(post.is_mathjax for post in posts):
%if any(post.has_math for post in posts):
${math_scripts()}
%endif
</%def>

<%def name="math_styles_ifpost(post)">
%if post.is_mathjax:
%if post.has_math:
${math_styles()}
%endif
</%def>

<%def name="math_styles_ifposts(posts)">
%if any(post.is_mathjax for post in posts):
%if any(post.has_math for post in posts):
${math_styles()}
%endif
</%def>
@@ -588,7 +588,9 @@ def __init__(self, **config):
'USE_KATEX': False,
'USE_OPEN_GRAPH': True,
'USE_SLUGIFY': True,
'USE_TAG_METADATA': True,
'TIMEZONE': 'UTC',
'WARN_ABOUT_TAG_METADATA': True,
'WRITE_TAG_CLOUD': False,
'DEPLOY_DRAFTS': True,
'DEPLOY_FUTURE': False,
@@ -915,17 +915,19 @@ def import_postpage_item(self, item, wordpress_namespace, out_folder=None, attac

tags = []
categories = []
post_status = 'published'
has_math = "no"
if status == 'trash':
LOGGER.warn('Trashed post "{0}" will not be imported.'.format(title))
return False
elif status == 'private':
tags.append('private')
is_draft = False
is_private = True
post_status = 'private'
elif status != 'publish':
tags.append('draft')
is_draft = True
is_private = False
post_status = 'draft'
else:
is_draft = False
is_private = False
@@ -943,7 +945,7 @@ def import_postpage_item(self, item, wordpress_namespace, out_folder=None, attac
tags.append(text)

if '$latex' in content:
tags.append('mathjax')
has_math = "yes"

for i, cat in enumerate(categories[:]):
cat = self._sanitize(cat, True)
@@ -1010,6 +1012,8 @@ def import_postpage_item(self, item, wordpress_namespace, out_folder=None, attac
"date": post_date,
"description": description,
"tags": ','.join(tags),
"status": post_status,
"has_math": has_math,
}
meta.update(other_meta)
if self.onefile:
@@ -78,7 +78,7 @@

__all__ = ('Post',)

TEASER_REGEXP = re.compile('<!--\s*(TEASER_END|END_TEASER)(:(.+))?\s*-->', re.IGNORECASE)
TEASER_REGEXP = re.compile(r'<!--\s*(TEASER_END|END_TEASER)(:(.+))?\s*-->', re.IGNORECASE)


class Post(object):
@@ -241,7 +241,9 @@ def __init__(

is_draft = False
is_private = False
post_status = 'published'
self._tags = {}
self.has_oldstyle_metadata_tags = False
for lang in self.translated_to:
if isinstance(self.meta[lang]['tags'], (list, tuple, set)):
_tag_list = self.meta[lang]['tags']
@@ -251,20 +253,63 @@ def __init__(
list(set([x.strip() for x in _tag_list])),
alg=natsort.ns.F | natsort.ns.IC)
self._tags[lang] = [t for t in self._tags[lang] if t]
if 'draft' in [_.lower() for _ in self._tags[lang]]:
is_draft = True
LOGGER.debug('The post "{0}" is a draft.'.format(self.source_path))
self._tags[lang].remove('draft')

if 'private' in self._tags[lang]:
is_private = True
LOGGER.debug('The post "{0}" is private.'.format(self.source_path))
self._tags[lang].remove('private')
status = self.meta[lang].get('status')
if status:
is_private = False
is_draft = False
if status in ('published', 'featured'):
post_status = status
elif status == 'private':
post_status = status
is_private = True
elif status == 'draft':
post_status = status
is_draft = True
else:
LOGGER.warn(('The post "{0}" has the unknown status "{1}". ' +
'Valid values are "published", "featured", "private" and "draft".').format(self.source_path, status))

if self.config['WARN_ABOUT_TAG_METADATA']:
show_warning = False
if 'draft' in [_.lower() for _ in self._tags[lang]]:
LOGGER.warn('The post "{0}" uses the "draft" tag.'.format(self.source_path))
show_warning = True
if 'private' in self._tags[lang]:
LOGGER.warn('The post "{0}" uses the "private" tag.'.format(self.source_path))
show_warning = True
if 'mathjax' in self._tags[lang]:
LOGGER.warn('The post "{0}" uses the "mathjax" tag.'.format(self.source_path))
show_warning = True
if show_warning:
LOGGER.warn('It is suggested that you convert special tags to metadata and set '
'USE_TAG_METADATA to False. You can use the upgrade_metadata_v8 '
'command plugin for conversion (install with: nikola plugin -i '
'upgrade_metadata_v8). Change the WARN_ABOUT_TAG_METADATA '
'configuration to disable this warning.')
if self.config['USE_TAG_METADATA']:
if 'draft' in [_.lower() for _ in self._tags[lang]]:
is_draft = True
LOGGER.debug('The post "{0}" is a draft.'.format(self.source_path))
self._tags[lang].remove('draft')
post_status = 'draft'
self.has_oldstyle_metadata_tags = True

if 'private' in self._tags[lang]:
is_private = True
LOGGER.debug('The post "{0}" is private.'.format(self.source_path))
self._tags[lang].remove('private')
post_status = 'private'
self.has_oldstyle_metadata_tags = True

if 'mathjax' in self._tags[lang]:
self.has_oldstyle_metadata_tags = True

# While draft comes from the tags, it's not really a tag
self.is_draft = is_draft
self.is_private = is_private
self.is_post = use_in_feeds
self.post_status = post_status
self.use_in_feeds = use_in_feeds and not is_draft and not is_private \
and not self.publish_later

@@ -311,15 +356,27 @@ def _has_pretty_url(self, lang):
return self.has_pretty_url(lang)

@property
def is_mathjax(self):
"""Return True if this post has the mathjax tag in the current language or is a python notebook."""
def has_math(self):
"""Return True if this post has has_math set to True or is a python notebook.
Alternatively, it will return True if it has set the mathjax tag in the
current language and the USE_TAG_METADATA config setting is True.
"""
if self.compiler.name == 'ipynb':
return True
lang = nikola.utils.LocaleBorg().current_lang
if self.is_translation_available(lang):
return 'mathjax' in self.tags_for_language(lang)
if self.meta[lang].get('has_math') in ('true', 'True', 'yes', '1', 1, True):
return True
if self.config['USE_TAG_METADATA']:
return 'mathjax' in self.tags_for_language(lang)
# If it has math in ANY other language, enable it. Better inefficient than broken.
return 'mathjax' in self.alltags
for lang in self.translated_to:
if self.meta[lang].get('has_math') in ('true', 'True', 'yes', '1', 1, True):
return True
if self.config['USE_TAG_METADATA']:
return 'mathjax' in self.alltags
return False

@property
def alltags(self):
@@ -14,7 +14,7 @@
import jinja2

dumb_replacements = [
["{% if any(post.is_mathjax for post in posts) %}", '{% if posts|selectattr("is_mathjax")|list %}'],
["{% if any(post.has_math for post in posts) %}", '{% if posts|selectattr("has_math")|list %}'],
["json.dumps(title)", "title|tojson"],
["{{ parent.extra_head() }}", "{{ super() }}"],
["{{ parent.content() }}", "{{ super() }}"],

0 comments on commit d2ee193

Please sign in to comment.