Skip to content

Commit

Permalink
merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed Mar 9, 2016
2 parents 4015aee + 6e46b1a commit 2372fef
Show file tree
Hide file tree
Showing 33 changed files with 313 additions and 123 deletions.
31 changes: 31 additions & 0 deletions CHANGES.txt
@@ -1,11 +1,41 @@
New in master
=============

Features
--------

* New ``--one-file`` option to wordpress importer (Issue #2262)
* New Pygal-based chart shortcode (Issue #2170)
* Add ``post_type`` to post-list directive (Issue #2272)
* Use ``sys.executable`` for launching pip in ``plugin`` (Issue #2275)

Bugfixes
--------

* Fix a JSON conversion bug in the WordPress importer (Issue #2264)
* Don’t create download directories when not downloading WordPress
attachments (Issue #2260)
* Don’t display “Good link” messages in ``nikola check -l`` by default,
can be re-enabled with ``-v`` option (Issue #2268)
* Fix a format string in ``nikola check`` (Issue #2267)
* Don't crash wordpress importer when posts are "empty" (Issue #2263)
* Don't put untranslated and nonexistant posts in sitemap (Issue #2289)
* Mark as failed tasks when filters fail (Issue #2169)

New in v7.7.6
=============

Features
--------

* Add ``FRONT_INDEX_HEADER`` setting to allow adding greeting notices
to the main index page (Issue #2249)

Bugfixes
--------

* Make Jupyter posts build (Issues #2248, #2252)

New in v7.7.5
=============

Expand All @@ -24,6 +54,7 @@ Features
if ``GITHUB_COMMIT_SOURCE`` is set to True (Issue #2186)
* Hugo-like shortcodes (Issue #1707)
* New Galician translation
* New PRESERVE_EXIF_DATA option to copy EXIF when resizing images (Issue #2204)
* New facilities for data persistence and data caching (Issues #2209 and #2009)
* (internal) allow ``scripts/jinjify.py`` usage with scripts (Issue #2240)

Expand Down
2 changes: 1 addition & 1 deletion docs/extending.txt
Expand Up @@ -9,7 +9,7 @@
Extending Nikola
================

:Version: 7.7.5
:Version: 7.7.6
:Author: Roberto Alsina <ralsina@netmanagers.com.ar>

.. class:: alert alert-info pull-right
Expand Down
Binary file modified docs/man/nikola.1.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/man/nikola.rst
Expand Up @@ -6,7 +6,7 @@ Nikola
A Static Site and Blog Generator
--------------------------------

:Version: Nikola v7.7.5
:Version: Nikola v7.7.6
:Manual section: 1
:Manual group: User Commands

Expand Down
40 changes: 31 additions & 9 deletions docs/manual.txt
Expand Up @@ -9,7 +9,7 @@
The Nikola Handbook
===================

:Version: 7.7.5
:Version: 7.7.6

.. class:: alert alert-info pull-right

Expand Down Expand Up @@ -813,28 +813,49 @@ To use them from plugins, please see `Extending Nikola <https://getnikola.com/ex
Using a shortcode
~~~~~~~~~~~~~~~~~

In your content files, a shortcode can be called by using the ``{{% name parameters %}}`` form. Shortcode parameters are space delimited. Parameters with spaces can be quoted (or backslash escaped).
In your content files, a shortcode can be called by using the {{% raw %}}{{% name parameters %}}{{% /raw %}} form. Shortcode parameters are space delimited. Parameters with spaces can be quoted (or backslash escaped).

The first word is always the name of the shortcode. Parameters follow the name. Depending upon how the shortcode is defined, the parameters may be named, positional or both. The format for named parameters models that of HTML with the format name="value".

Some shortcodes use or require closing shortcodes. Like HTML, the opening and closing shortcodes match (name only), the closing being prepended with a slash.

Example of a paired shortcode (note that we don't have a highlight shortcode yet ;-)::

{{% highlight python %}} A bunch of code here {{% /highlight %}}
{{% raw %}}{{% highlight python %}} A bunch of code here {{% /highlight %}}{{% /raw %}}

Built-in shortcodes
~~~~~~~~~~~~~~~~~~~

post-list
Will show a list of posts, see the `Post List directive for details <#post-list>`__


media
Display media embedded from a URL, for example, this will embed a youtube video::

{{% raw %}}{{% media url="https://www.youtube.com/watch?v=Nck6BZga7TQ" %}}{{% /raw %}}

In reStructuredText this shortcode will fail because docutils turns that URL to a link and everything breaks, use the `media directive <#media>`__ instead.

chart
Create charts via PyGal. This is similar to the `chart directive <#chart>`__ except the syntax is adapted to
shortcodes. This is an example::

{{% raw %}}{{% chart Bar title='Browser usage evolution (in %)' %}}
x_labels='["2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012"]'%}}
'Firefox', [None, None, 0, 16.6, 25, 31]
'Chrome', [None, None, None, None, None, None]
'IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6]
'Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4]
{{% /chart %}}{{% /raw %}}

In reStructuredText the quoting needed to pass arguments gets insane really fast, use the chart directive
instead (the syntax is nicer anyway)

Template-based shortcodes
~~~~~~~~~~~~~~~~~~~~~~~~~

If you put a template in ``shortcodes/`` called ``mycode.tmpl`` then Nikola will create a shortcode
called ``mycode`` you can use. Any options you pass to the shortcode will be available as variables
called ``mycode`` you can use. Any options you pass to the shortcode will be available as variables
for that template. If you use the shortcode as paired, then the contents between the paired tags will
be available in the ``data`` variable.

Expand All @@ -846,7 +867,7 @@ For example, if your ``shortcodes/foo.tmpl`` contains this::

And your post contains this::

{{% foo bar=bla %}}
{{% raw %}}{{% foo bar=bla %}}{{% /raw %}}

Then the output file will contain::

Expand Down Expand Up @@ -1388,13 +1409,14 @@ The currently available filters are:
.. sidebar:: Creating your own filters

You can use any program name that works in place as a filter, like ``sed -i``
and you can use arbitrary python functions as filters, too.
and you can use arbitrary Python functions as filters, too.

If your program doesn't run in-place, then you can use Nikola's runinplace function.
If your program doesn't run in-place, then you can use Nikola's ``runinplace`` function (from the ``filters`` module).
For example, this is how the yui_compressor filter is implemented:

.. code-block:: python

from nikola.filters import runinplace
def yui_compressor(infile):
return runinplace(r'yui-compressor --nomunge %1 -o %2', infile)

Expand Down
6 changes: 3 additions & 3 deletions docs/path_handlers.txt
Expand Up @@ -2,8 +2,8 @@
.. 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.
Nikola supports special links with the syntax ``link://kind/name``. In the templates you can also
use ``_link(kind, name)`` Here is the description for all the supported kinds.

.. class:: dl-horizontal

Expand Down Expand Up @@ -204,7 +204,7 @@ slug

Example:

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


tag
Expand Down
2 changes: 1 addition & 1 deletion docs/social_buttons.txt
Expand Up @@ -9,7 +9,7 @@
Using Alternative Social Buttons with Nikola
============================================

:Version: 7.7.5
:Version: 7.7.6

.. class:: alert alert-info pull-right

Expand Down
4 changes: 2 additions & 2 deletions docs/sphinx/conf.py
Expand Up @@ -54,9 +54,9 @@
# built documents.
#
# The short X.Y version.
version = '7.7.5'
version = '7.7.6'
# The full version, including alpha/beta/rc tags.
release = '7.7.5'
release = '7.7.6'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion docs/theming.txt
Expand Up @@ -9,7 +9,7 @@
Theming Nikola
==============

:Version: 7.7.5
:Version: 7.7.6
:Author: Roberto Alsina <ralsina@netmanagers.com.ar>

.. class:: alert alert-info pull-right
Expand Down
2 changes: 1 addition & 1 deletion nikola/__init__.py
Expand Up @@ -29,7 +29,7 @@
from __future__ import absolute_import
import os

__version__ = "7.7.5"
__version__ = "7.7.6"
DEBUG = bool(os.getenv('NIKOLA_DEBUG'))

from .nikola import Nikola # NOQA
Expand Down
11 changes: 11 additions & 0 deletions nikola/conf.py.in
Expand Up @@ -391,6 +391,12 @@ HIDDEN_AUTHORS = ['Guest']
# output / TRANSLATION[lang] / INDEX_PATH / index-*.html
# INDEX_PATH = ""

# Optional HTML that displayed on “main” blog index.html files.
# May be used for a greeting. (translatable)
FRONT_INDEX_HEADER = {
DEFAULT_LANG: ''
}

# Create per-month archives instead of per-year
# CREATE_MONTHLY_ARCHIVE = False
# Create one large archive instead of per-year
Expand Down Expand Up @@ -562,6 +568,11 @@ GITHUB_COMMIT_SOURCE = True
#
# If set to False, it will sort by filename instead. Defaults to True
# GALLERY_SORT_BY_DATE = True

# If set to True, EXIF data will be copied when an image is thumbnailed or
# resized.
# PRESERVE_EXIF_DATA = False

#
# Folders containing images to be used in normal posts or pages. Images will be
# scaled down according to IMAGE_THUMBNAIL_SIZE and MAX_IMAGE_SIZE options, but
Expand Down
3 changes: 3 additions & 0 deletions nikola/data/themes/base-jinja/templates/index.tmpl
Expand Up @@ -12,6 +12,9 @@

{% block content %}
{% block content_header %}{% endblock %}
{% if 'main_index' in pagekind %}
{{ front_index_header }}
{% endif %}
<div class="postindex">
{% for post in posts %}
<article class="h-entry post-{{ post.meta('type') }}">
Expand Down
3 changes: 3 additions & 0 deletions nikola/data/themes/base/templates/index.tmpl
Expand Up @@ -12,6 +12,9 @@

<%block name="content">
<%block name="content_header"></%block>
% if 'main_index' in pagekind:
${front_index_header}
% endif
<div class="postindex">
% for post in posts:
<article class="h-entry post-${post.meta('type')}">
Expand Down
8 changes: 6 additions & 2 deletions nikola/image_processing.py
Expand Up @@ -52,7 +52,7 @@ class ImageProcessor(object):

image_ext_list_builtin = ['.jpg', '.png', '.jpeg', '.gif', '.svg', '.bmp', '.tiff']

def resize_image(self, src, dst, max_size, bigger_panoramas=True):
def resize_image(self, src, dst, max_size, bigger_panoramas=True, preserve_exif_data=False):
"""Make a copy of the image in the requested size."""
if not Image or os.path.splitext(src)[1] in ['.svg', '.svgz']:
self.resize_svg(src, dst, max_size, bigger_panoramas)
Expand All @@ -70,6 +70,7 @@ def resize_image(self, src, dst, max_size, bigger_panoramas=True):
exif = im._getexif()
except Exception:
exif = None
_exif = im.info.get('exif')
if exif is not None:
for tag, value in list(exif.items()):
decoded = ExifTags.TAGS.get(tag, tag)
Expand All @@ -84,7 +85,10 @@ def resize_image(self, src, dst, max_size, bigger_panoramas=True):
break
try:
im.thumbnail(size, Image.ANTIALIAS)
im.save(dst)
if _exif is not None and preserve_exif_data:
im.save(dst, exif=_exif)
else:
im.save(dst)
except Exception as e:
self.logger.warn("Can't thumbnail {0}, using original "
"image as thumbnail ({1})".format(src, e))
Expand Down
11 changes: 8 additions & 3 deletions nikola/nikola.py
Expand Up @@ -412,6 +412,7 @@ def __init__(self, **config):
'FILES_FOLDERS': {'files': ''},
'FILTERS': {},
'FORCE_ISO8601': False,
'FRONT_INDEX_HEADER': '',
'GALLERY_FOLDERS': {'galleries': 'galleries'},
'GALLERY_SORT_BY_DATE': True,
'GLOBAL_CONTEXT_FILLER': [],
Expand Down Expand Up @@ -454,6 +455,7 @@ def __init__(self, **config):
'POSTS_SECTION_FROM_META': False,
'POSTS_SECTION_NAME': "",
'POSTS_SECTION_TITLE': "{name}",
'PRESERVE_EXIF_DATA': False,
'PAGES': (("stories/*.txt", "stories", "story.tmpl"),),
'PANDOC_OPTIONS': [],
'PRETTY_URLS': False,
Expand Down Expand Up @@ -554,6 +556,7 @@ def __init__(self, **config):
'BODY_END',
'EXTRA_HEAD_DATA',
'NAVIGATION_LINKS',
'FRONT_INDEX_HEADER',
'INDEX_READ_MORE_LINK',
'FEED_READ_MORE_LINK',
'INDEXES_TITLE',
Expand Down Expand Up @@ -587,6 +590,7 @@ def __init__(self, **config):
'posts_section_descriptions',
'posts_section_name',
'posts_section_title',
'front_index_header',
)
# WARNING: navigation_links SHOULD NOT be added to the list above.
# Themes ask for [lang] there and we should provide it.
Expand Down Expand Up @@ -866,7 +870,7 @@ def init_plugins(self, commands_only=False):
# FIXME TemplateSystem should not be needed
if p[-1].details.get('Nikola', 'PluginCategory') not in {'Command', 'Template'}:
bad_candidates.add(p)
else: # Not commands-only
elif self.configured: # Not commands-only, and configured
# Remove compilers we don't use
if p[-1].name in self.bad_compilers:
bad_candidates.add(p)
Expand Down Expand Up @@ -954,6 +958,7 @@ def _set_global_context(self):
self._GLOBAL_CONTEXT['show_blog_title'] = self.config.get('SHOW_BLOG_TITLE')
self._GLOBAL_CONTEXT['logo_url'] = self.config.get('LOGO_URL')
self._GLOBAL_CONTEXT['blog_description'] = self.config.get('BLOG_DESCRIPTION')
self._GLOBAL_CONTEXT['front_index_header'] = self.config.get('FRONT_INDEX_HEADER')
self._GLOBAL_CONTEXT['color_hsl_adjust_hex'] = utils.color_hsl_adjust_hex
self._GLOBAL_CONTEXT['colorize_str_from_base_color'] = utils.colorize_str_from_base_color

Expand Down Expand Up @@ -1331,7 +1336,7 @@ def render_shortcode(t_data=template_data, **kw):
def register_shortcode(self, name, f):
"""Register function f to handle shortcode "name"."""
if name in self.shortcode_registry:
utils.LOGGER.warn('Shortcode name conflict: %s', name)
utils.LOGGER.warn('Shortcode name conflict: {}', name)
return
self.shortcode_registry[name] = f

Expand Down Expand Up @@ -1508,7 +1513,7 @@ def slug_path(self, name, lang):
Example:
links://slug/yellow-camaro => /posts/cars/awful/yellow-camaro/index.html
link://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:
Expand Down
27 changes: 24 additions & 3 deletions nikola/plugins/basic_import.py
Expand Up @@ -127,16 +127,37 @@ def transform_content(cls, content):
def write_content(cls, filename, content, rewrite_html=True):
"""Write content to file."""
if rewrite_html:
doc = html.document_fromstring(content)
doc.rewrite_links(replacer)
content = html.tostring(doc, encoding='utf8')
try:
doc = html.document_fromstring(content)
doc.rewrite_links(replacer)
content = html.tostring(doc, encoding='utf8')
except etree.ParserError:
content = content.encode('utf-8')
else:
content = content.encode('utf-8')

utils.makedirs(os.path.dirname(filename))
with open(filename, "wb+") as fd:
fd.write(content)

@classmethod
def write_post(cls, filename, content, headers, compiler, rewrite_html=True):
"""Ask the specified compiler to write the post to disk."""
if rewrite_html:
try:
doc = html.document_fromstring(content)
doc.rewrite_links(replacer)
content = html.tostring(doc, encoding='utf8')
except etree.ParserError:
pass
if isinstance(content, utils.bytes_str):
content = content.decode('utf-8')
compiler.create_post(
filename,
content=content,
onefile=True,
**headers)

@staticmethod
def write_metadata(filename, title, slug, post_date, description, tags, **kwargs):
"""Write metadata to meta file."""
Expand Down

0 comments on commit 2372fef

Please sign in to comment.