Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compound file extensions. Fix #2780 #2816

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: minor

Support matching compound file extensions for custom readers; e.g., `.md.html`
3 changes: 2 additions & 1 deletion pelican/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from functools import partial
from itertools import chain, groupby
from operator import attrgetter
from pathlib import Path

from jinja2 import (BaseLoader, ChoiceLoader, Environment, FileSystemLoader,
PrefixLoader, TemplateNotFound)
Expand Down Expand Up @@ -123,7 +124,7 @@ def _include_path(self, path, extensions=None):
if any(fnmatch.fnmatch(basename, ignore) for ignore in ignores):
return False

ext = os.path.splitext(basename)[1][1:]
ext = ''.join(Path(basename).suffixes)[1:]
if extensions is False or ext in extensions:
return True

Expand Down
11 changes: 11 additions & 0 deletions pelican/tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def test_include_path(self):
ignored_file = os.path.join(CUR_DIR, 'content', 'ignored1.rst')
self.assertFalse(include_path(ignored_file))

def test_include_path_handles_compound_extensions(self):
"""
Test that Generator._include_path properly handles
compound extensions such as .md.html
"""
filename = os.path.join(CUR_DIR, 'content', 'article.md.html')
include_path = self.generator._include_path
self.assertTrue(include_path(filename, extensions=('md.html',)))
self.assertFalse(include_path(filename, extensions=('md',)))
self.assertFalse(include_path(filename, extensions=('html',)))

def test_get_files_exclude(self):
"""Test that Generator.get_files() properly excludes directories.
"""
Expand Down