tags and path thinks
This commit is contained in:
parent
dfe159bd53
commit
9d522c6b54
1 changed files with 10 additions and 3 deletions
13
convert2.py
13
convert2.py
|
@ -6,7 +6,6 @@ import click
|
|||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def migrate_header_img_and_return_new_path_for_post(img_path, img_new_path):
|
||||
is_http = re.compile(r'https?://')
|
||||
if is_http.match(img_path):
|
||||
|
@ -14,9 +13,9 @@ def migrate_header_img_and_return_new_path_for_post(img_path, img_new_path):
|
|||
img_pathlib = Path(img_path)
|
||||
output_path = Path(img_new_path)
|
||||
if re.compile(r'/').match(img_path):
|
||||
old = 'source' + img_path
|
||||
old = str(Path(g_input).parent) + img_path
|
||||
else:
|
||||
old = 'source/posts/' + str(output_path.parent.name) + '/' + str(output_path.name) + '/' + img_path
|
||||
old = g_input + str(output_path.parent.name) + '/' + str(output_path.name) + '/' + img_path
|
||||
new = img_new_path + '/' + img_pathlib.name
|
||||
shutil.copyfile(old, new)
|
||||
return new.replace(new.split('/')[0], '/blog')
|
||||
|
@ -45,7 +44,11 @@ def convert_m2h(input_file: str, output_dir: str):
|
|||
del data['tags']
|
||||
else:
|
||||
if not isinstance(data['tags'], list):
|
||||
tag_list = list()
|
||||
data['tags'] = data['tags'].split()
|
||||
for t in data.get('tags'):
|
||||
tag_list.append(t.strip(','))
|
||||
data['tags'] = tag_list
|
||||
|
||||
if 'ws' in data:
|
||||
data['categories'] = 'event'
|
||||
|
@ -143,6 +146,10 @@ def handle_list_conversion(input_dir, output_dir):
|
|||
@click.option("--input", help="Input Path.")
|
||||
@click.option("--output", help="Output Path")
|
||||
def click_cli(input, output):
|
||||
global g_input
|
||||
global g_output
|
||||
g_input = input
|
||||
g_output = output
|
||||
handle_list_conversion(input, output)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue