implement configurable field drop from post header
This commit is contained in:
parent
da4f678ca6
commit
4618966f10
4 changed files with 18 additions and 11 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -8,4 +8,9 @@ converter_options:
|
|||
- source: "http://localhost/"
|
||||
target: "/"
|
||||
- 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
|
Loading…
Reference in a new issue