Skip to content

Commit 0f4b1e2

Browse files
committedJul 9, 2015
Fix navigation links with PRETTY_URL/STRIP_INDEXES
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent 894c44f commit 0f4b1e2

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed
 

‎nikola/conf.py.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,7 @@ COMMENT_SYSTEM_ID = ${COMMENT_SYSTEM_ID}
655655
# (Uses the INDEX_FILE setting, so if that is, say, default.html,
656656
# it will instead /foo/default.html => /foo)
657657
# (Note: This was briefly STRIP_INDEX_HTML in v 5.4.3 and 5.4.4)
658-
# Default = False
659-
# STRIP_INDEXES = False
658+
STRIP_INDEXES = ${STRIP_INDEXES}
660659

661660
# Should the sitemap list directories which only include other directories
662661
# and no files.

‎nikola/plugins/command/init.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
'BLOG_EMAIL': "joe@demo.site",
5555
'BLOG_DESCRIPTION': "This is a demo site for Nikola.",
5656
'PRETTY_URLS': False,
57+
'STRIP_INDEXES': False,
5758
'DEFAULT_LANG': "en",
5859
'TRANSLATIONS': """{
5960
DEFAULT_LANG: "",
@@ -103,6 +104,7 @@
103104
'REDIRECTIONS': [],
104105
}
105106

107+
106108
# Generate a list of supported languages here.
107109
# Ugly code follows.
108110
_suplang = {}
@@ -164,12 +166,12 @@ def format_default_translations_config(additional_languages):
164166
return "{{\n{0}\n}}".format("\n".join(lang_paths))
165167

166168

167-
def format_navigation_links(additional_languages, default_lang, messages):
169+
def format_navigation_links(additional_languages, default_lang, messages, strip_indexes=False):
168170
"""Return the string to configure NAVIGATION_LINKS."""
169171
f = u"""\
170172
{0}: (
171173
("{1}/archive.html", "{2[Archive]}"),
172-
("{1}/categories/index.html", "{2[Tags]}"),
174+
("{1}/categories/{3}", "{2[Tags]}"),
173175
("{1}/rss.xml", "{2[RSS feed]}"),
174176
),"""
175177

@@ -185,11 +187,16 @@ def get_msg(lang):
185187
fmsg[i] = i
186188
return fmsg
187189

190+
if strip_indexes:
191+
index_html = ''
192+
else:
193+
index_html = 'index.html'
194+
188195
# handle the default language
189-
pairs.append(f.format('DEFAULT_LANG', '', get_msg(default_lang)))
196+
pairs.append(f.format('DEFAULT_LANG', '', get_msg(default_lang), index_html))
190197

191198
for l in additional_languages:
192-
pairs.append(f.format(json.dumps(l, ensure_ascii=False), '/' + l, get_msg(l)))
199+
pairs.append(f.format(json.dumps(l, ensure_ascii=False), '/' + l, get_msg(l), index_html))
193200

194201
return u'{{\n{0}\n}}'.format('\n\n'.join(pairs))
195202

@@ -200,12 +207,13 @@ def prepare_config(config):
200207
"""Parse sample config with JSON."""
201208
p = config.copy()
202209
p.update(dict((k, json.dumps(v, ensure_ascii=False)) for k, v in p.items()
203-
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')))
210+
if k not in ('POSTS', 'PAGES', 'COMPILERS', 'TRANSLATIONS', 'NAVIGATION_LINKS', '_SUPPORTED_LANGUAGES', '_SUPPORTED_COMMENT_SYSTEMS', 'INDEX_READ_MORE_LINK', 'RSS_READ_MORE_LINK', 'STRIP_INDEXES', 'PRETTY_URLS')))
204211
# READ_MORE_LINKs require some special treatment.
205212
p['INDEX_READ_MORE_LINK'] = "'" + p['INDEX_READ_MORE_LINK'].replace("'", "\\'") + "'"
206213
p['RSS_READ_MORE_LINK'] = "'" + p['RSS_READ_MORE_LINK'].replace("'", "\\'") + "'"
207214
# json would make that `true` instead of `True`
208215
p['PRETTY_URLS'] = str(p['PRETTY_URLS'])
216+
p['STRIP_INDEXES'] = str(p['STRIP_INDEXES'])
209217
return p
210218

211219

@@ -296,6 +304,7 @@ def urlhandler(default, toconf):
296304

297305
def prettyhandler(default, toconf):
298306
SAMPLE_CONF['PRETTY_URLS'] = ask_yesno('Enable pretty URLs (/page/ instead of /page.html) that don’t need web server configuration?', default=True)
307+
SAMPLE_CONF['STRIP_INDEXES'] = SAMPLE_CONF['PRETTY_URLS']
299308

300309
def lhandler(default, toconf, show_header=True):
301310
if show_header:
@@ -333,7 +342,7 @@ def lhandler(default, toconf, show_header=True):
333342
# not inherit from anywhere.
334343
try:
335344
messages = load_messages(['base'], tr, default)
336-
SAMPLE_CONF['NAVIGATION_LINKS'] = format_navigation_links(langs, default, messages)
345+
SAMPLE_CONF['NAVIGATION_LINKS'] = format_navigation_links(langs, default, messages, SAMPLE_CONF['STRIP_INDEXES'])
337346
except nikola.utils.LanguageNotFoundError as e:
338347
print(" ERROR: the language '{0}' is not supported.".format(e.lang))
339348
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).")

0 commit comments

Comments
 (0)
Please sign in to comment.