aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/command/init.py
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2015-08-26 07:57:04 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2015-08-26 07:57:04 -0300
commit8041475aab2b8efad7d2857027331bd626d26312 (patch)
tree3980e1763c067079a4cebb425d642ca9eac834bf /nikola/plugins/command/init.py
parentb0b24795b24ee6809397fbbadf42f31f310a219f (diff)
Imported Upstream version 7.6.4
Diffstat (limited to 'nikola/plugins/command/init.py')
-rw-r--r--nikola/plugins/command/init.py43
1 files changed, 29 insertions, 14 deletions
diff --git a/nikola/plugins/command/init.py b/nikola/plugins/command/init.py
index 7a36894..91ccdb4 100644
--- a/nikola/plugins/command/init.py
+++ b/nikola/plugins/command/init.py
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""Create a new site."""
+
from __future__ import print_function, unicode_literals
import os
import shutil
@@ -54,6 +56,7 @@ SAMPLE_CONF = {
'BLOG_EMAIL': "joe@demo.site",
'BLOG_DESCRIPTION': "This is a demo site for Nikola.",
'PRETTY_URLS': False,
+ 'STRIP_INDEXES': False,
'DEFAULT_LANG': "en",
'TRANSLATIONS': """{
DEFAULT_LANG: "",
@@ -64,6 +67,8 @@ SAMPLE_CONF = {
'TIMEZONE': 'UTC',
'COMMENT_SYSTEM': 'disqus',
'COMMENT_SYSTEM_ID': 'nikolademo',
+ 'CATEGORY_ALLOW_HIERARCHIES': False,
+ 'CATEGORY_OUTPUT_FLAT_HIERARCHY': False,
'TRANSLATIONS_PATTERN': DEFAULT_TRANSLATIONS_PATTERN,
'INDEX_READ_MORE_LINK': DEFAULT_INDEX_READ_MORE_LINK,
'RSS_READ_MORE_LINK': DEFAULT_RSS_READ_MORE_LINK,
@@ -103,6 +108,7 @@ SAMPLE_CONF = {
'REDIRECTIONS': [],
}
+
# Generate a list of supported languages here.
# Ugly code follows.
_suplang = {}
@@ -154,8 +160,7 @@ SAMPLE_CONF['_SUPPORTED_COMMENT_SYSTEMS'] = '\n'.join(textwrap.wrap(
def format_default_translations_config(additional_languages):
- """Return the string to configure the TRANSLATIONS config variable to
- make each additional language visible on the generated site."""
+ """Adapt TRANSLATIONS setting for all additional languages."""
if not additional_languages:
return SAMPLE_CONF["TRANSLATIONS"]
lang_paths = [' DEFAULT_LANG: "",']
@@ -164,12 +169,12 @@ def format_default_translations_config(additional_languages):
return "{{\n{0}\n}}".format("\n".join(lang_paths))
-def format_navigation_links(additional_languages, default_lang, messages):
+def format_navigation_links(additional_languages, default_lang, messages, strip_indexes=False):
"""Return the string to configure NAVIGATION_LINKS."""
f = u"""\
{0}: (
("{1}/archive.html", "{2[Archive]}"),
- ("{1}/categories/index.html", "{2[Tags]}"),
+ ("{1}/categories/{3}", "{2[Tags]}"),
("{1}/rss.xml", "{2[RSS feed]}"),
),"""
@@ -185,27 +190,32 @@ def format_navigation_links(additional_languages, default_lang, messages):
fmsg[i] = i
return fmsg
+ if strip_indexes:
+ index_html = ''
+ else:
+ index_html = 'index.html'
+
# handle the default language
- pairs.append(f.format('DEFAULT_LANG', '', get_msg(default_lang)))
+ pairs.append(f.format('DEFAULT_LANG', '', get_msg(default_lang), index_html))
for l in additional_languages:
- pairs.append(f.format(json.dumps(l, ensure_ascii=False), '/' + l, get_msg(l)))
+ pairs.append(f.format(json.dumps(l, ensure_ascii=False), '/' + l, get_msg(l), index_html))
return u'{{\n{0}\n}}'.format('\n\n'.join(pairs))
-# In order to ensure proper escaping, all variables but the three
-# pre-formatted ones are handled by json.dumps().
+# In order to ensure proper escaping, all variables but the pre-formatted ones
+# are handled by json.dumps().
def prepare_config(config):
"""Parse sample config with JSON."""
p = config.copy()
- p.update(dict((k, json.dumps(v, ensure_ascii=False)) for k, v in p.items()
- if k not in ('POSTS', 'PAGES', 'COMPILERS', 'TRANSLATIONS', 'NAVIGATION_LINKS', '_SUPPORTED_LANGUAGES', '_SUPPORTED_COMMENT_SYSTEMS', 'INDEX_READ_MORE_LINK', 'RSS_READ_MORE_LINK', 'PRETTY_URLS')))
+ p.update({k: json.dumps(v, ensure_ascii=False) for k, v in p.items()
+ if k not in ('POSTS', 'PAGES', 'COMPILERS', 'TRANSLATIONS', 'NAVIGATION_LINKS', '_SUPPORTED_LANGUAGES', '_SUPPORTED_COMMENT_SYSTEMS', 'INDEX_READ_MORE_LINK', 'RSS_READ_MORE_LINK')})
# READ_MORE_LINKs require some special treatment.
p['INDEX_READ_MORE_LINK'] = "'" + p['INDEX_READ_MORE_LINK'].replace("'", "\\'") + "'"
p['RSS_READ_MORE_LINK'] = "'" + p['RSS_READ_MORE_LINK'].replace("'", "\\'") + "'"
- # json would make that `true` instead of `True`
- p['PRETTY_URLS'] = str(p['PRETTY_URLS'])
+ # fix booleans and None
+ p.update({k: str(v) for k, v in config.items() if isinstance(v, bool) or v is None})
return p
@@ -239,11 +249,13 @@ class CommandInit(Command):
@classmethod
def copy_sample_site(cls, target):
+ """Copy sample site data to target directory."""
src = resource_filename('nikola', os.path.join('data', 'samplesite'))
shutil.copytree(src, target)
@staticmethod
def create_configuration(target):
+ """Create configuration file."""
template_path = resource_filename('nikola', 'conf.py.in')
conf_template = Template(filename=template_path)
conf_path = os.path.join(target, 'conf.py')
@@ -252,12 +264,14 @@ class CommandInit(Command):
@staticmethod
def create_configuration_to_string():
+ """Return configuration file as a string."""
template_path = resource_filename('nikola', 'conf.py.in')
conf_template = Template(filename=template_path)
return conf_template.render(**prepare_config(SAMPLE_CONF))
@classmethod
def create_empty_site(cls, target):
+ """Create an empty site with directories only."""
for folder in ('files', 'galleries', 'listings', 'posts', 'stories'):
makedirs(os.path.join(target, folder))
@@ -295,7 +309,8 @@ class CommandInit(Command):
SAMPLE_CONF['SITE_URL'] = answer
def prettyhandler(default, toconf):
- SAMPLE_CONF['PRETTY_URLS'] = ask_yesno('Enable pretty URLs (/page/ instead of /page.html) that don’t need web server configuration?', default=True)
+ SAMPLE_CONF['PRETTY_URLS'] = ask_yesno('Enable pretty URLs (/page/ instead of /page.html) that don\'t need web server configuration?', default=True)
+ SAMPLE_CONF['STRIP_INDEXES'] = SAMPLE_CONF['PRETTY_URLS']
def lhandler(default, toconf, show_header=True):
if show_header:
@@ -333,7 +348,7 @@ class CommandInit(Command):
# not inherit from anywhere.
try:
messages = load_messages(['base'], tr, default)
- SAMPLE_CONF['NAVIGATION_LINKS'] = format_navigation_links(langs, default, messages)
+ SAMPLE_CONF['NAVIGATION_LINKS'] = format_navigation_links(langs, default, messages, SAMPLE_CONF['STRIP_INDEXES'])
except nikola.utils.LanguageNotFoundError as e:
print(" ERROR: the language '{0}' is not supported.".format(e.lang))
print(" Are you sure you spelled the name correctly? Names are case-sensitive and need to be reproduced as-is (complete with the country specifier, if any).")