main class wiring
This commit is contained in:
parent
aa00a107f0
commit
8c40577459
26
README.md
26
README.md
|
@ -4,6 +4,27 @@ A DokuWiki to Hugo file exporter to quickly migrate your existing PHP wiki to Hu
|
|||
|
||||
See https://www.dokuwiki.org/wiki:syntax
|
||||
|
||||
**How do I run this thing?**
|
||||
|
||||
Main wiring in `DokuWikiToHugo` - see the tests for an elaborate example.
|
||||
|
||||
```python
|
||||
DokuWikiToHugo().doku_to_hugo('some_dokuwiki_root_dir')
|
||||
```
|
||||
|
||||
This generates files in a new folder called 'output' with the same directory structure.
|
||||
|
||||
## TOML File headers
|
||||
|
||||
Every converted file contains a TOML header with:
|
||||
|
||||
* datestamp - looking at the file modified date (transfer from your FTP using 'keep timestamps' option)
|
||||
* draft automatically set to false
|
||||
* tags: every subfolder is a tag, including the name of the file
|
||||
* title: name of the file
|
||||
|
||||
See `test_hugo_file_config.py` for an example.
|
||||
|
||||
## Following Dokuwiki syntax converted:
|
||||
|
||||
### general
|
||||
|
@ -44,11 +65,6 @@ Simply add custom.html and link to the website of your choice. Use Hugo's `{{ in
|
|||
* emoticons
|
||||
* no formatting (nowiki, %%) - should this just be a pre?
|
||||
|
||||
### structure
|
||||
|
||||
* build file structure - wire everything together
|
||||
* build header TOML with timestamps, draft false etc
|
||||
|
||||
## Not supported and probably will never be
|
||||
|
||||
* embedding php - kill it with fire?
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import os
|
||||
import shutil
|
||||
|
||||
from src.hugo_file_config import HugoFileConfig
|
||||
from src.markdown_converter import MarkdownConverter
|
||||
|
||||
|
||||
class DokuWikiToHugo:
|
||||
|
||||
def __init__(self):
|
||||
self.header_converter = HugoFileConfig()
|
||||
pass
|
||||
|
||||
def create_output_dir(self):
|
||||
if os.path.exists('output'):
|
||||
print('output already exists, deleting old conversion stuff')
|
||||
shutil.rmtree('output')
|
||||
os.mkdir('output')
|
||||
|
||||
def doku_to_hugo(self, dir):
|
||||
self.create_output_dir()
|
||||
for root, subFolders, files in os.walk(dir):
|
||||
for file in files:
|
||||
self.process_file(root, file)
|
||||
|
||||
def process_file(self, root, file):
|
||||
destination_dir = 'output/' + root
|
||||
source_file = root + '/' + file
|
||||
print('generating ' + destination_dir + '/' + 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:
|
||||
text_file.write(header)
|
||||
text_file.write('\n')
|
||||
text_file.write(converted_text)
|
|
@ -0,0 +1,19 @@
|
|||
import shutil
|
||||
from unittest import TestCase
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from src.dokuwiki_to_hugo import DokuWikiToHugo
|
||||
|
||||
|
||||
class TestDokuWikiToHugo(TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree('output')
|
||||
`
|
||||
def test_convert_whole_dir(self):
|
||||
DokuWikiToHugo().doku_to_hugo('subdir')
|
||||
expected = Path("output/subdir/moar/dokuwiki_header_in_subdir.txt").read_text()
|
||||
|
||||
self.assertIn('+++', expected) # header is there, check
|
||||
self.assertIn('##### some header', expected) # some conversion done, check
|
Loading…
Reference in New Issue