diff --git a/app/config.py b/app/config.py index 1ca1586..dd1d678 100644 --- a/app/config.py +++ b/app/config.py @@ -23,10 +23,13 @@ class ConverterOptions(BaseModel): Will rewrite the author to this value for all the posts. links_rewrite : list[dict] Will rewrite the links to this value for all the posts. + header_fields_drop : list[str] + Will drop the specified header fields from the posts. """ author_rewrite: str links_rewrite: list[dict] + header_fields_drop: list[str] class Configurator(BaseSettings): diff --git a/app/converter/wordpress_markdown.py b/app/converter/wordpress_markdown.py index 42e5915..2f9e875 100644 --- a/app/converter/wordpress_markdown.py +++ b/app/converter/wordpress_markdown.py @@ -39,14 +39,10 @@ class WordpressMarkdownConverter: dict The fixed header """ - with key_error_silence(): - del header["restapi_import_id"] - with key_error_silence(): - del header["original_post_id"] - with key_error_silence(): - del header["timeline_notification"] - with key_error_silence(): - del header["wordads_ufa"] + for field in self.configurator.converter_options.header_fields_drop: + with key_error_silence(): + del header[field] + # rewrite header fields header["guid"] = header["guid"].replace("http://localhost", "") header["author"] = self.configurator.converter_options.author_rewrite return header diff --git a/app/tests/utils_test.py b/app/tests/utils_test.py index 420360c..a1fc872 100644 --- a/app/tests/utils_test.py +++ b/app/tests/utils_test.py @@ -1,7 +1,10 @@ import pytest -from app.utils import (guard_against_none, guard_against_none_or_empty_str, - key_error_silence) +from app.utils import ( + guard_against_none, + guard_against_none_or_empty_str, + key_error_silence, +) def test_key_error_silence(): diff --git a/config.yaml b/config.yaml index fb4731d..dd8be8b 100644 --- a/config.yaml +++ b/config.yaml @@ -8,4 +8,9 @@ converter_options: - source: "http://localhost/" target: "/" - source: "https://nuculabs.wordpress.com/" - target: "https://nuculabs.dev/posts/" \ No newline at end of file + target: "https://nuculabs.dev/posts/" + header_fields_drop: + - restapi_import_id + - original_post_id + - timeline_notification + - wordads_ufa \ No newline at end of file