diff --git a/src/dokuwiki_to_hugo.py b/src/dokuwiki_to_hugo.py index b8de66c..0f6a72c 100644 --- a/src/dokuwiki_to_hugo.py +++ b/src/dokuwiki_to_hugo.py @@ -26,14 +26,17 @@ class DokuWikiToHugo: def process_file(self, root, file): destination_dir = 'output/' + root 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): os.makedirs(destination_dir) header = self.header_converter.create(source_file) 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('\n') text_file.write(converted_text) diff --git a/src/markdown_converter.py b/src/markdown_converter.py index 2ec3a25..7eae7dd 100644 --- a/src/markdown_converter.py +++ b/src/markdown_converter.py @@ -13,7 +13,6 @@ class MarkdownConverter: def convert(self): text = Path(self.file).read_text() - # TODO solve this functional-style instead of mutating text for converter in MarkdownConverter.converters: text = converter.convert(text) return text \ No newline at end of file diff --git a/test/subdir/home.txt b/test/subdir/home.txt new file mode 100644 index 0000000..2b40f7d --- /dev/null +++ b/test/subdir/home.txt @@ -0,0 +1 @@ +subdir index \ No newline at end of file diff --git a/test/test_dokuwiki_to_hugo.py b/test/test_dokuwiki_to_hugo.py index 4226924..e65cf1b 100644 --- a/test/test_dokuwiki_to_hugo.py +++ b/test/test_dokuwiki_to_hugo.py @@ -11,9 +11,15 @@ class TestDokuWikiToHugo(TestCase): def tearDown(self): 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): 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('##### some header', expected) # some conversion done, check \ No newline at end of file