implement configurable field drop from post header

This commit is contained in:
Denis-Cosmin Nutiu 2023-05-31 18:36:04 +03:00
parent da4f678ca6
commit 4618966f10
4 changed files with 18 additions and 11 deletions

View file

@ -23,10 +23,13 @@ class ConverterOptions(BaseModel):
Will rewrite the author to this value for all the posts. Will rewrite the author to this value for all the posts.
links_rewrite : list[dict] links_rewrite : list[dict]
Will rewrite the links to this value for all the posts. 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 author_rewrite: str
links_rewrite: list[dict] links_rewrite: list[dict]
header_fields_drop: list[str]
class Configurator(BaseSettings): class Configurator(BaseSettings):

View file

@ -39,14 +39,10 @@ class WordpressMarkdownConverter:
dict dict
The fixed header The fixed header
""" """
with key_error_silence(): for field in self.configurator.converter_options.header_fields_drop:
del header["restapi_import_id"] with key_error_silence():
with key_error_silence(): del header[field]
del header["original_post_id"] # rewrite header fields
with key_error_silence():
del header["timeline_notification"]
with key_error_silence():
del header["wordads_ufa"]
header["guid"] = header["guid"].replace("http://localhost", "") header["guid"] = header["guid"].replace("http://localhost", "")
header["author"] = self.configurator.converter_options.author_rewrite header["author"] = self.configurator.converter_options.author_rewrite
return header return header

View file

@ -1,7 +1,10 @@
import pytest import pytest
from app.utils import (guard_against_none, guard_against_none_or_empty_str, from app.utils import (
key_error_silence) guard_against_none,
guard_against_none_or_empty_str,
key_error_silence,
)
def test_key_error_silence(): def test_key_error_silence():

View file

@ -9,3 +9,8 @@ converter_options:
target: "/" target: "/"
- source: "https://nuculabs.wordpress.com/" - source: "https://nuculabs.wordpress.com/"
target: "https://nuculabs.dev/posts/" target: "https://nuculabs.dev/posts/"
header_fields_drop:
- restapi_import_id
- original_post_id
- timeline_notification
- wordads_ufa