home.txt is actually _index.md

This commit is contained in:
Wouter Groeneveld 2017-01-16 16:37:58 +01:00
parent 17625d6f1d
commit f65a8b0b59
4 changed files with 13 additions and 4 deletions

View File

@ -26,14 +26,17 @@ class DokuWikiToHugo:
def process_file(self, root, file): def process_file(self, root, file):
destination_dir = 'output/' + root destination_dir = 'output/' + root
source_file = root + '/' + file source_file = root + '/' + file
print('generating ' + destination_dir + '/' + file + '\n') destination_file = '_index.md' if file == 'home.txt' else os.path.splitext(file)[0] + '.md'
print('generating ' + destination_dir + '/' + destination_file + '\n')
if not os.path.exists(destination_dir): if not os.path.exists(destination_dir):
os.makedirs(destination_dir) os.makedirs(destination_dir)
header = self.header_converter.create(source_file) header = self.header_converter.create(source_file)
converted_text = MarkdownConverter(source_file).convert() converted_text = MarkdownConverter(source_file).convert()
with open(destination_dir + '/' + file, "w") as text_file:
with open(destination_dir + '/' + destination_file, "w") as text_file:
text_file.write(header) text_file.write(header)
text_file.write('\n') text_file.write('\n')
text_file.write(converted_text) text_file.write(converted_text)

View File

@ -13,7 +13,6 @@ class MarkdownConverter:
def convert(self): def convert(self):
text = Path(self.file).read_text() text = Path(self.file).read_text()
# TODO solve this functional-style instead of mutating text
for converter in MarkdownConverter.converters: for converter in MarkdownConverter.converters:
text = converter.convert(text) text = converter.convert(text)
return text return text

1
test/subdir/home.txt Normal file
View File

@ -0,0 +1 @@
subdir index

View File

@ -11,9 +11,15 @@ class TestDokuWikiToHugo(TestCase):
def tearDown(self): def tearDown(self):
shutil.rmtree('output') shutil.rmtree('output')
def test_doku_to_hugo_converts_home_to_index_markdown_files(self):
DokuWikiToHugo().doku_to_hugo('subdir')
expected = Path("output/subdir/_index.md").read_text()
self.assertIn('subdir index', expected)
def test_convert_whole_dir(self): def test_convert_whole_dir(self):
DokuWikiToHugo().doku_to_hugo('subdir') DokuWikiToHugo().doku_to_hugo('subdir')
expected = Path("output/subdir/moar/dokuwiki_header_in_subdir.txt").read_text() expected = Path("output/subdir/moar/dokuwiki_header_in_subdir.md").read_text()
self.assertIn('+++', expected) # header is there, check self.assertIn('+++', expected) # header is there, check
self.assertIn('##### some header', expected) # some conversion done, check self.assertIn('##### some header', expected) # some conversion done, check