jekyll-to-hugo/app/converter/converter.py

51 lines
1.4 KiB
Python
Raw Normal View History

2023-05-29 18:58:32 +00:00
import logging
2023-05-29 18:35:38 +00:00
import os
from pathlib import Path
from app import utils
2023-05-29 18:58:32 +00:00
from app.config import Configurator
2023-05-29 18:35:38 +00:00
from app.converter.wordpress_markdown import WordpressMarkdownConverter
class Converter:
"""
Convert Jekyll posts to Hugo posts
"""
2023-05-29 18:58:32 +00:00
def __init__(self, configurator: Configurator):
2023-05-29 18:35:38 +00:00
"""
Initializes the converter
Parameters
----------
2023-05-29 18:58:32 +00:00
configurator : Configurator
The configurator instance.
2023-05-29 18:35:38 +00:00
"""
2023-05-29 18:58:32 +00:00
utils.guard_against_none(configurator, "configurator")
2023-05-29 18:35:38 +00:00
2023-05-29 18:58:32 +00:00
self._logger = logging.getLogger(__name__)
self._jekyll_posts_path = configurator.source_path
self._hugo_posts_path = configurator.output_path
self._logger.info(
f"Using source: {self._jekyll_posts_path} output: {self._hugo_posts_path}"
)
2023-05-29 18:35:38 +00:00
# The converter that converts the markdown
2023-05-29 18:58:32 +00:00
self.markdown_converter = WordpressMarkdownConverter(configurator)
2023-05-29 18:35:38 +00:00
def convert(self):
"""
Converts the Jekyll posts to Hugo posts
"""
source_path = self._jekyll_posts_path
output_path = Path(self._hugo_posts_path)
_, _, files = next(os.walk(source_path))
for file in files:
source_abs_path = source_path / Path(file)
self.markdown_converter.convert_jekyll_to_hugo(
source_abs_path,
output_path,
)