Skip to content
Permalink
Browse files
Merge pull request #2725 from getnikola/fix-2724
Fix #2724
  • Loading branch information
Kwpolska committed Apr 19, 2017
2 parents 7113502 + 6bc5ddb commit 91ae0170a0574c0a33c2ae8049c4eb843528ec0f
Showing with 54 additions and 3 deletions.
  1. +5 −3 nikola/plugins/task/sections.py
  2. +49 −0 tests/test_integration.py
@@ -142,9 +142,11 @@ def postprocess_posts_per_classification(self, posts_per_section_per_language, f
def should_generate_classification_page(self, dirname, post_list, lang):
"""Only generates list of posts for classification if this function returns True."""
short_destination = dirname + '/' + self.site.config['INDEX_FILE']
for post in post_list:
# If there is an index.html pending to be created from a page, do not generate the section page.
# The section page would be useless anyways. (via Issue #2613)
# If there is an index.html pending to be created from a page, do not generate the section page.
# The section page would be useless anyways. (via Issue #2613)
for post in self.site.timeline:
if not self.site.config["SHOW_UNTRANSLATED_POSTS"] and not post.is_translation_available(lang):
continue
if post.destination_path(lang, sep='/') == short_destination:
return False
return True
@@ -545,6 +545,55 @@ def fill_site(self):
outf.write("foo")


class SectionPageCollisionTest(EmptyBuildTest):
"""Test if section indexes avoid pages."""

@classmethod
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""")

@classmethod
def fill_site(self):
"""Add subdirectories and create a post in section "sec1" and a page with the same URL as the section index."""
self.init_command.create_empty_site(self.target_dir)
self.init_command.create_configuration(self.target_dir)

pages = os.path.join(self.target_dir, "pages")
posts = os.path.join(self.target_dir, "posts")
sec1 = os.path.join(posts, "sec1")

nikola.utils.makedirs(pages)
nikola.utils.makedirs(sec1)

with io.open(os.path.join(pages, 'sec1.txt'), "w+", encoding="utf8") as outf:
outf.write(".. title: Page 0\n.. slug: sec1\n\nThis is Page 0.\n")

with io.open(os.path.join(sec1, 'foo.txt'), "w+", encoding="utf8") as outf:
outf.write(".. title: Post 0\n.. slug: post0\n.. date: 2013-03-06 19:08:15\n\nThis is Post 0.\n")

def _make_output_path(self, dir, name):
"""Make a file path to the output."""
return os.path.join(dir, name + '.html')

def test_section_index_avoidance(self):
"""Test section index."""
sec1 = os.path.join(self.target_dir, "output", "sec1")
foo = os.path.join(self.target_dir, "output", "sec1", "post0")

# Do all files exist?
self.assertTrue(os.path.isfile(self._make_output_path(sec1, 'index')))
self.assertTrue(os.path.isfile(self._make_output_path(foo, 'index')))

# Is it really a page?
with io.open(os.path.join(sec1, 'index.html'), 'r', encoding='utf-8') as fh:
page = fh.read()
self.assertTrue('This is Page 0' in page)
self.assertTrue('This is Post 0' not in page)


class PageIndexTest(EmptyBuildTest):
"""Test if PAGE_INDEX works, with PRETTY_URLS disabled."""

0 comments on commit 91ae017

Please sign in to comment.