Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* `Jonathon Anderson <https://github.com/anderbubble>`_
`Jonathan Hartley <https://github.com/tartley>`_
* `Joshua Barratt <https://github.com/jbarratt>`_
* `Joshua Wise <https://github.com/jwise>`_
* `Juan Pedro Fisanotti <https://github.com/fisadev>`_
* `Juanjo Conti <https://github.com/jjconti>`_
* `James C. McPherson <https://github.com/jmcp>`_
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Adds ``STRIP_EXTENSIONS`` config option (Issue #3865)

Bugfixes
--------

Expand Down
7 changes: 7 additions & 0 deletions nikola/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,13 @@ COMMENT_SYSTEM_ID = ${COMMENT_SYSTEM_ID}
# it will instead /foo/default.html => /foo)
STRIP_INDEXES = ${STRIP_INDEXES}

# If a link ends in .html, drop the .html part only. (Works with Apache
# when configured with `Options MultiViews`, or nginx when configured with
# `try_files`.)
#
# http://mysite/foo/bar.html => http://mysite/foo/bar
STRIP_EXTENSIONS = ${STRIP_EXTENSIONS}

# List of files relative to the server root (!) that will be asked to be excluded
# from indexing and other robotic spidering. * is supported. Will only be effective
# if SITE_URL points to server root. The list is used to exclude resources from
Expand Down
4 changes: 4 additions & 0 deletions nikola/nikola.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ def __init__(self, **config) -> None:
'SITE_URL': 'https://example.com/',
'PAGE_INDEX': False,
'SECTION_PATH': '',
'STRIP_EXTENSIONS': False,
'STRIP_INDEXES': True,
'TAG_PATH': 'categories',
'TAG_PAGES_ARE_INDEXES': False,
Expand Down Expand Up @@ -1924,6 +1925,9 @@ def path(self, kind, name, lang=None, is_link=False, **kwargs):
if self.config['STRIP_INDEXES'] and \
link[-(1 + index_len):] == '/' + self.config['INDEX_FILE']:
return link[:-index_len]
elif self.config['STRIP_EXTENSIONS'] and \
link[-5:] == '.html':
return link[:-5]
else:
return link
else:
Expand Down
1 change: 1 addition & 0 deletions nikola/plugins/command/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'BLOG_DESCRIPTION': "This is a demo site for Nikola.",
'PRETTY_URLS': True,
'STRIP_INDEXES': True,
'STRIP_EXTENSIONS': False,
'DEFAULT_LANG': "en",
'TRANSLATIONS': """{
DEFAULT_LANG: "",
Expand Down
3 changes: 3 additions & 0 deletions nikola/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def _load_config(self, config):
self.current_time = current_time(self.config['__tzinfo__'])
self.base_url = self.config['BASE_URL']
self.strip_indexes = self.config['STRIP_INDEXES']
self.strip_extensions = self.config['STRIP_EXTENSIONS']
self.index_file = self.config['INDEX_FILE']
self.pretty_urls = self.config['PRETTY_URLS']
self.default_lang = self.config['DEFAULT_LANG']
Expand Down Expand Up @@ -1069,6 +1070,8 @@ def permalink(self, lang=None, absolute=False, extension='.html', query=None):
index_len = len(self.index_file)
if self.strip_indexes and link[-(1 + index_len):] == '/' + self.index_file:
link = link[:-index_len]
if self.strip_extensions and link[-len(extension):] == extension:
link = link[:-len(extension)]
if query:
link = link + "?" + query
link = utils.encodelink(link)
Expand Down