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.
|
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):
|
||||||
|
|
|
@ -39,14 +39,10 @@ class WordpressMarkdownConverter:
|
||||||
dict
|
dict
|
||||||
The fixed header
|
The fixed header
|
||||||
"""
|
"""
|
||||||
|
for field in self.configurator.converter_options.header_fields_drop:
|
||||||
with key_error_silence():
|
with key_error_silence():
|
||||||
del header["restapi_import_id"]
|
del header[field]
|
||||||
with key_error_silence():
|
# rewrite header fields
|
||||||
del header["original_post_id"]
|
|
||||||
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
|
||||||
|
|
|
@ -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():
|
||||||
|
|
|
@ -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
|
Loading…
Reference in a new issue