Skip to content
Permalink
Browse files

Merge branch 'master' into fix-2771

  • Loading branch information
ralsina committed May 18, 2017
2 parents 1f144c3 + 30e4461 commit c5904c4171e520525179843dd7d08ea36e98a83f
@@ -5,12 +5,18 @@ Features
--------

* Better error handling when posts can't be parsed (Issue #2771)
* Use ``.theme`` files to store theme metadata (Issue #2758)
* New ``add_header_permalinks`` filter, for Sphinx-style header links
(Issue #2636)
* Added alternate links for gallery translations (Issue #993)

Bugfixes
--------

* Ignore files ending wih "bak" (Issue #2740)
* Use page.tmpl by default, which is inherited from story.tmpl (Issue
#1891)

New in v7.8.5
=============

@@ -123,8 +123,8 @@ THEME_COLOR = '#5670d4'
# Finally, note that destination can be translated, i.e. you can
# specify a different translation folder per language. Example:
# PAGES = (
# ("pages/*.rst", {"en": "pages", "de": "seiten"}, "story.tmpl"),
# ("pages/*.md", {"en": "pages", "de": "seiten"}, "story.tmpl"),
# ("pages/*.rst", {"en": "pages", "de": "seiten"}, "page.tmpl"),
# ("pages/*.md", {"en": "pages", "de": "seiten"}, "page.tmpl"),
# )

POSTS = ${POSTS}
@@ -0,0 +1,10 @@
[Theme]
engine = jinja
parent = base
author = The Nikola Contributors
author_url = https://getnikola.com/
license = MIT

[Family]
family = base
mako_version = base

This file was deleted.

This file was deleted.

@@ -0,0 +1,9 @@
[Theme]
engine = mako
author = The Nikola Contributors
author_url = https://getnikola.com/
license = MIT

[Family]
family = base
jinja_version = base-jinja

This file was deleted.

@@ -37,5 +37,12 @@

<%block name="extra_head">
${parent.extra_head()}
%if len(translations) > 1:
%for langname in translations.keys():
%if langname != lang:
<link rel="alternate" hreflang="${langname}" href="${_link('gallery', gallery_path, langname)}">
%endif
%endfor
%endif
<link rel="alternate" type="application/rss+xml" title="RSS" href="rss.xml">
</%block>
@@ -0,0 +1 @@
<%inherit file="story.tmpl"/>
@@ -0,0 +1,16 @@
[Theme]
engine = jinja
parent = base-jinja
author = The Nikola Contributors
author_url = https://getnikola.com/
based_on = Bootstrap 3 <http://getbootstrap.com/>
license = MIT
tags = bootstrap

[Family]
family = bootstrap3
mako_version = bootstrap3
variants = bootstrap3-gradients, bootstrap3-gradients-jinja

[Nikola]
bootswatch = True

This file was deleted.

This file was deleted.

@@ -0,0 +1,16 @@
[Theme]
engine = mako
parent = base
author = The Nikola Contributors
author_url = https://getnikola.com/
based_on = Bootstrap 3 <http://getbootstrap.com/>
license = MIT
tags = bootstrap

[Family]
family = bootstrap3
jinja_version = bootstrap3-jinja
variants = bootstrap3-gradients, bootstrap3-gradients-jinja

[Nikola]
bootswatch = True

This file was deleted.

This file was deleted.

@@ -49,6 +49,13 @@ ${parent.extra_head()}
width: 100%;
}
</style>
%if len(translations) > 1:
%for langname in translations.keys():
%if langname != lang:
<link rel="alternate" hreflang="${langname}" href="${_link('gallery', gallery_path, langname)}">
%endif
%endfor
%endif
</%block>


@@ -2270,6 +2270,9 @@ def generic_page_renderer(self, lang, post, filters, context=None):
deps = post.deps(lang)
uptodate_deps = post.deps_uptodate(lang)
deps.extend(utils.get_asset_path(x, self.THEMES) for x in ('bundles', 'parent', 'engine'))
_theme_ini = utils.get_asset_path(self.config['THEME'] + '.theme', self.THEMES)
if _theme_ini:
deps.append(_theme_ini)

context = copy(context) if context else {}
context['post'] = post
@@ -270,8 +270,8 @@ def do_rebuild(self, event):
if (fname.endswith('~') or
fname.startswith('.') or
'__pycache__' in event_path or
event_path.endswith(('.pyc', '.pyo', '.pyd')) or
os.path.isdir(event_path)): # Skip on folders, these are usually duplicates
event_path.endswith(('.pyc', '.pyo', '.pyd', '_bak')) or
event.is_directory): # Skip on folders, these are usually duplicates
return
self.logger.info('REBUILDING SITE (from {0})'.format(event_path))
p = subprocess.Popen(self.cmd_arguments, stderr=subprocess.PIPE)
@@ -78,9 +78,9 @@
("posts/*.html", "posts", "post.tmpl"),
)""",
'PAGES': """(
("pages/*.rst", "pages", "story.tmpl"),
("pages/*.txt", "pages", "story.tmpl"),
("pages/*.html", "pages", "story.tmpl"),
("pages/*.rst", "pages", "page.tmpl"),
("pages/*.txt", "pages", "page.tmpl"),
("pages/*.html", "pages", "page.tmpl"),
)""",
'COMPILERS': """{
"rest": ('.rst', '.txt'),
@@ -32,6 +32,7 @@
import shutil
import time
import requests
import configparser

import pygments
from pygments.lexers import PythonLexer
@@ -131,6 +132,13 @@ class CommandTheme(Command):
'default': 'base',
'help': 'Parent to use for new theme (default: base)',
},
{
'name': 'new_legacy_meta',
'long': 'legacy-meta',
'type': bool,
'default': False,
'help': 'Create legacy meta files for new theme',
},
]

def _execute(self, options, args):
@@ -147,6 +155,7 @@ def _execute(self, options, args):
new = options.get('new')
new_engine = options.get('new_engine')
new_parent = options.get('new_parent')
new_legacy_meta = options.get('new_legacy_meta')
command_count = [bool(x) for x in (
install,
uninstall,
@@ -172,7 +181,7 @@ def _execute(self, options, args):
elif copy_template:
return self.copy_template(copy_template)
elif new:
return self.new_theme(new, new_engine, new_parent)
return self.new_theme(new, new_engine, new_parent, new_legacy_meta)

def do_install_deps(self, url, name):
"""Install themes and their dependencies."""
@@ -316,7 +325,7 @@ def copy_template(self, template):
LOGGER.error("This file already exists in your templates directory ({0}).".format(base))
return 3

def new_theme(self, name, engine, parent):
def new_theme(self, name, engine, parent, create_legacy_meta=False):
"""Create a new theme."""
base = 'themes'
themedir = os.path.join(base, name)
@@ -326,9 +335,7 @@ def new_theme(self, name, engine, parent):
LOGGER.info("Created directory {0}".format(base))

# Check if engine and parent match
engine_file = utils.get_asset_path('engine', utils.get_theme_chain(parent, self.site.themes_dirs))
with io.open(engine_file, 'r', encoding='utf-8') as fh:
parent_engine = fh.read().strip()
parent_engine = utils.get_template_engine(utils.get_theme_chain(parent, self.site.themes_dirs))

if parent_engine != engine:
LOGGER.error("Cannot use engine {0} because parent theme '{1}' uses {2}".format(engine, parent, parent_engine))
@@ -342,12 +349,24 @@ def new_theme(self, name, engine, parent):
LOGGER.error("Theme already exists")
return 2

with io.open(os.path.join(themedir, 'parent'), 'w', encoding='utf-8') as fh:
fh.write(parent + '\n')
LOGGER.info("Created file {0}".format(os.path.join(themedir, 'parent')))
with io.open(os.path.join(themedir, 'engine'), 'w', encoding='utf-8') as fh:
fh.write(engine + '\n')
LOGGER.info("Created file {0}".format(os.path.join(themedir, 'engine')))
cp = configparser.ConfigParser()
cp['Theme'] = {
'engine': engine,
'parent': parent
}

theme_meta_path = os.path.join(themedir, name + '.theme')
with io.open(theme_meta_path, 'w', encoding='utf-8') as fh:
cp.write(fh)
LOGGER.info("Created file {0}".format(theme_meta_path))

if create_legacy_meta:
with io.open(os.path.join(themedir, 'parent'), 'w', encoding='utf-8') as fh:
fh.write(parent + '\n')
LOGGER.info("Created file {0}".format(os.path.join(themedir, 'parent')))
with io.open(os.path.join(themedir, 'engine'), 'w', encoding='utf-8') as fh:
fh.write(engine + '\n')
LOGGER.info("Created file {0}".format(os.path.join(themedir, 'engine')))

LOGGER.info("Theme {0} created successfully.".format(themedir))
LOGGER.notice('Remember to set THEME="{0}" in conf.py to use this theme.'.format(name))
@@ -258,6 +258,7 @@ def gen_tasks(self):
folder += '/'
folders.append((folder, ft))

context["gallery_path"] = gallery
context["folders"] = natsort.natsorted(
folders, alg=natsort.ns.F | natsort.ns.IC)
context["crumbs"] = utils.get_crumbs(gallery, index_folder=self, lang=lang)
@@ -28,6 +28,7 @@

from __future__ import print_function, unicode_literals, absolute_import
import calendar
import configparser
import datetime
import dateutil.tz
import hashlib
@@ -607,27 +608,52 @@ def get_theme_path(theme):
return theme


def parse_theme_meta(theme_dir):
"""Parse a .theme meta file."""
cp = configparser.ConfigParser()
# The `or` case is in case theme_dir ends with a trailing slash
theme_name = os.path.basename(theme_dir) or os.path.basename(os.path.dirname(theme_dir))
theme_meta_path = os.path.join(theme_dir, theme_name + '.theme')
cp.read(theme_meta_path)
return cp if cp.has_section('Theme') else None


def get_template_engine(themes):
"""Get template engine used by a given theme."""
for theme_name in themes:
engine_path = os.path.join(theme_name, 'engine')
if os.path.isfile(engine_path):
with open(engine_path) as fd:
return fd.readlines()[0].strip()
# default
return 'mako'
meta = parse_theme_meta(theme_name)
if meta:
e = meta.get('Theme', 'engine', fallback=None)
if e:
return e
else:
# Theme still uses old-style parent/engine files
engine_path = os.path.join(theme_name, 'engine')
if os.path.isfile(engine_path):
with open(engine_path) as fd:
return fd.readlines()[0].strip()
# default
return 'mako'


def get_parent_theme_name(theme_name, themes_dirs=None):
"""Get name of parent theme."""
parent_path = os.path.join(theme_name, 'parent')
if os.path.isfile(parent_path):
with open(parent_path) as fd:
parent = fd.readlines()[0].strip()
if themes_dirs:
meta = parse_theme_meta(theme_name)
if meta:
parent = meta.get('Theme', 'parent', fallback=None)
if themes_dirs and parent:
return get_theme_path_real(parent, themes_dirs)
return parent
return None
else:
# Theme still uses old-style parent/engine files
parent_path = os.path.join(theme_name, 'parent')
if os.path.isfile(parent_path):
with open(parent_path) as fd:
parent = fd.readlines()[0].strip()
if themes_dirs:
return get_theme_path_real(parent, themes_dirs)
return parent
return None


def get_theme_chain(theme, themes_dirs):
@@ -392,10 +392,10 @@ def patch_site(self):
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "r", encoding="utf-8") as inf:
data = inf.read()
data = data.replace('("pages/*.txt", "pages", "story.tmpl"),',
'("pages/*.txt", "", "story.tmpl"),')
data = data.replace('("pages/*.rst", "pages", "story.tmpl"),',
'("pages/*.rst", "", "story.tmpl"),')
data = data.replace('("pages/*.txt", "pages", "page.tmpl"),',
'("pages/*.txt", "", "page.tmpl"),')
data = data.replace('("pages/*.rst", "pages", "page.tmpl"),',
'("pages/*.rst", "", "page.tmpl"),')
data = data.replace('# INDEX_PATH = ""',
'INDEX_PATH = "blog"')
with io.open(conf_path, "w+", encoding="utf8") as outf:
@@ -553,7 +553,7 @@ def patch_site(self):
"""Enable post sections."""
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "a", encoding="utf8") as outf:
outf.write("""\n\nPOSTS_SECTIONS = True\nPOSTS_SECTIONS_ARE_INDEXES = True\nPRETTY_URLS = True\nPOSTS = (('posts/*.txt', '', 'post.tmpl'),)\nPAGES = (('pages/*.txt', '', 'story.tmpl'),)\n\n""")
outf.write("""\n\nPOSTS_SECTIONS = True\nPOSTS_SECTIONS_ARE_INDEXES = True\nPRETTY_URLS = True\nPOSTS = (('posts/*.txt', '', 'post.tmpl'),)\nPAGES = (('pages/*.txt', '', 'page.tmpl'),)\n\n""")

@classmethod
def fill_site(self):
@@ -602,7 +602,7 @@ def patch_site(self):
"""Enable PAGE_INDEX."""
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "a", encoding="utf8") as outf:
outf.write("""\n\nPAGE_INDEX = True\nPRETTY_URLS = False\nPAGES = PAGES + (('pages/*.php', 'pages', 'story.tmpl'),)\n\n""")
outf.write("""\n\nPAGE_INDEX = True\nPRETTY_URLS = False\nPAGES = PAGES + (('pages/*.php', 'pages', 'page.tmpl'),)\n\n""")

@classmethod
def fill_site(self):
@@ -707,7 +707,7 @@ def patch_site(self):
"""Enable PAGE_INDEX."""
conf_path = os.path.join(self.target_dir, "conf.py")
with io.open(conf_path, "a", encoding="utf8") as outf:
outf.write("""\n\nPAGE_INDEX = True\nPRETTY_URLS = True\nPAGES = PAGES + (('pages/*.php', 'pages', 'story.tmpl'),)\n\n""")
outf.write("""\n\nPAGE_INDEX = True\nPRETTY_URLS = True\nPAGES = PAGES + (('pages/*.php', 'pages', 'page.tmpl'),)\n\n""")

def _make_output_path(self, dir, name):
"""Make a file path to the output."""

0 comments on commit c5904c4

Please sign in to comment.
You can’t perform that action at this time.