From be42354bb47019ac451e0f15ad56b60dff4005fd Mon Sep 17 00:00:00 2001 From: Martijn Saelens Date: Thu, 5 Dec 2024 15:35:01 +0100 Subject: [PATCH] Added utf-8 --- src/mkslides/markupgenerator.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/mkslides/markupgenerator.py b/src/mkslides/markupgenerator.py index 29f7b4c..ec4b2b2 100644 --- a/src/mkslides/markupgenerator.py +++ b/src/mkslides/markupgenerator.py @@ -209,7 +209,7 @@ def __process_markdown_file( revealjs_config=OmegaConf.to_container(revealjs_config), plugins=plugins, ) - self.__create_file(output_markup_path, markup) + self.__create_or_overwrite_file(output_markup_path, markup) # Copy local files @@ -268,7 +268,7 @@ def __process_markdown_directory(self, md_root_path: Path) -> None: slideshows=slideshows, build_datetime=datetime.datetime.now(tz=datetime.timezone.utc), ) - self.__create_file(index_path, content) + self.__create_or_overwrite_file(index_path, content) def __copy_local_files( self, @@ -350,14 +350,14 @@ def __copy_favicon(self, file_using_favicon_path: Path, favicon: str) -> Path | ################################################################################ - def __create_file(self, destination_path: Path, content: Any) -> None: - if destination_path.exists(): - destination_path.write_text(content) - logger.debug(f"Overwritten: '{destination_path}'") - else: - destination_path.parent.mkdir(parents=True, exist_ok=True) - destination_path.write_text(content) - logger.debug(f"Created file '{destination_path}'") + def __create_or_overwrite_file(self, destination_path: Path, content: Any) -> None: + is_overwrite = destination_path.exists() + + destination_path.parent.mkdir(parents=True, exist_ok=True) + destination_path.write_text(content, encoding="utf-8") + + action = "Overwritten" if is_overwrite else "Created" + logger.debug(f"{action} file '{destination_path}'") def __copy_to_output(self, source_path: Path, destination_path: Path) -> Path: self.__copy(source_path, destination_path)