Move posts to respective folder

This commit is contained in:
2022-05-10 15:42:01 +08:00
parent 878ded0459
commit 0b081675a1
66 changed files with 63 additions and 59 deletions

View File

Before

Width:  |  Height:  |  Size: 9.4 MiB

After

Width:  |  Height:  |  Size: 9.4 MiB

View File

Before

Width:  |  Height:  |  Size: 9.4 MiB

After

Width:  |  Height:  |  Size: 9.4 MiB

View File

Before

Width:  |  Height:  |  Size: 8.7 MiB

After

Width:  |  Height:  |  Size: 8.7 MiB

View File

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

Before

Width:  |  Height:  |  Size: 3.5 MiB

After

Width:  |  Height:  |  Size: 3.5 MiB

View File

Before

Width:  |  Height:  |  Size: 2.6 MiB

After

Width:  |  Height:  |  Size: 2.6 MiB

View File

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

Before

Width:  |  Height:  |  Size: 4.9 MiB

After

Width:  |  Height:  |  Size: 4.9 MiB

View File

Before

Width:  |  Height:  |  Size: 4.9 MiB

After

Width:  |  Height:  |  Size: 4.9 MiB

View File

Before

Width:  |  Height:  |  Size: 4.8 MiB

After

Width:  |  Height:  |  Size: 4.8 MiB

View File

Before

Width:  |  Height:  |  Size: 6.4 MiB

After

Width:  |  Height:  |  Size: 6.4 MiB

View File

Before

Width:  |  Height:  |  Size: 6.4 MiB

After

Width:  |  Height:  |  Size: 6.4 MiB

View File

Before

Width:  |  Height:  |  Size: 6.1 MiB

After

Width:  |  Height:  |  Size: 6.1 MiB

View File

Before

Width:  |  Height:  |  Size: 4.9 MiB

After

Width:  |  Height:  |  Size: 4.9 MiB

View File

Before

Width:  |  Height:  |  Size: 6.3 MiB

After

Width:  |  Height:  |  Size: 6.3 MiB

View File

Before

Width:  |  Height:  |  Size: 6.1 MiB

After

Width:  |  Height:  |  Size: 6.1 MiB

View File

Before

Width:  |  Height:  |  Size: 6.5 MiB

After

Width:  |  Height:  |  Size: 6.5 MiB

View File

Before

Width:  |  Height:  |  Size: 3.7 MiB

After

Width:  |  Height:  |  Size: 3.7 MiB

View File

Before

Width:  |  Height:  |  Size: 4.2 MiB

After

Width:  |  Height:  |  Size: 4.2 MiB

View File

Before

Width:  |  Height:  |  Size: 4.1 MiB

After

Width:  |  Height:  |  Size: 4.1 MiB

View File

Before

Width:  |  Height:  |  Size: 3.7 MiB

After

Width:  |  Height:  |  Size: 3.7 MiB

View File

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 8.6 MiB

After

Width:  |  Height:  |  Size: 8.6 MiB

View File

Before

Width:  |  Height:  |  Size: 8.6 MiB

After

Width:  |  Height:  |  Size: 8.6 MiB

View File

Before

Width:  |  Height:  |  Size: 8.8 MiB

After

Width:  |  Height:  |  Size: 8.8 MiB

View File

Before

Width:  |  Height:  |  Size: 6.9 MiB

After

Width:  |  Height:  |  Size: 6.9 MiB

View File

Before

Width:  |  Height:  |  Size: 6.5 MiB

After

Width:  |  Height:  |  Size: 6.5 MiB

View File

Before

Width:  |  Height:  |  Size: 6.7 MiB

After

Width:  |  Height:  |  Size: 6.7 MiB

View File

Before

Width:  |  Height:  |  Size: 6.5 MiB

After

Width:  |  Height:  |  Size: 6.5 MiB

View File

Before

Width:  |  Height:  |  Size: 5.7 MiB

After

Width:  |  Height:  |  Size: 5.7 MiB

View File

Before

Width:  |  Height:  |  Size: 9.0 MiB

After

Width:  |  Height:  |  Size: 9.0 MiB

View File

Before

Width:  |  Height:  |  Size: 7.2 MiB

After

Width:  |  Height:  |  Size: 7.2 MiB

View File

Before

Width:  |  Height:  |  Size: 7.4 MiB

After

Width:  |  Height:  |  Size: 7.4 MiB

View File

Before

Width:  |  Height:  |  Size: 8.2 MiB

After

Width:  |  Height:  |  Size: 8.2 MiB

View File

Before

Width:  |  Height:  |  Size: 9.0 MiB

After

Width:  |  Height:  |  Size: 9.0 MiB

View File

Before

Width:  |  Height:  |  Size: 7.9 MiB

After

Width:  |  Height:  |  Size: 7.9 MiB

View File

Before

Width:  |  Height:  |  Size: 10 MiB

After

Width:  |  Height:  |  Size: 10 MiB

View File

Before

Width:  |  Height:  |  Size: 9.3 MiB

After

Width:  |  Height:  |  Size: 9.3 MiB

View File

Before

Width:  |  Height:  |  Size: 7.9 MiB

After

Width:  |  Height:  |  Size: 7.9 MiB

View File

Before

Width:  |  Height:  |  Size: 9.2 MiB

After

Width:  |  Height:  |  Size: 9.2 MiB

View File

Before

Width:  |  Height:  |  Size: 10 MiB

After

Width:  |  Height:  |  Size: 10 MiB

View File

Before

Width:  |  Height:  |  Size: 9.6 MiB

After

Width:  |  Height:  |  Size: 9.6 MiB

View File

Before

Width:  |  Height:  |  Size: 7.4 MiB

After

Width:  |  Height:  |  Size: 7.4 MiB

View File

Before

Width:  |  Height:  |  Size: 7.4 MiB

After

Width:  |  Height:  |  Size: 7.4 MiB

View File

Before

Width:  |  Height:  |  Size: 9.3 MiB

After

Width:  |  Height:  |  Size: 9.3 MiB

View File

Before

Width:  |  Height:  |  Size: 10 MiB

After

Width:  |  Height:  |  Size: 10 MiB

View File

Before

Width:  |  Height:  |  Size: 11 MiB

After

Width:  |  Height:  |  Size: 11 MiB

View File

Before

Width:  |  Height:  |  Size: 8.9 MiB

After

Width:  |  Height:  |  Size: 8.9 MiB

View File

Before

Width:  |  Height:  |  Size: 5.5 MiB

After

Width:  |  Height:  |  Size: 5.5 MiB

View File

Before

Width:  |  Height:  |  Size: 5.5 MiB

After

Width:  |  Height:  |  Size: 5.5 MiB

View File

Before

Width:  |  Height:  |  Size: 4.9 MiB

After

Width:  |  Height:  |  Size: 4.9 MiB

View File

Before

Width:  |  Height:  |  Size: 7.4 MiB

After

Width:  |  Height:  |  Size: 7.4 MiB

View File

@@ -1,88 +1,92 @@
#!python
import os
import argparse
import os, sys
import datetime
import traceback
DEFAULT_FRONT_MATTER = {
'slug': '',
'title': '',
'description': '',
'toc': True,
'authors': [],
'tags': [],
'categories': [],
'series': [],
'date': '',
'lastmod': '',
'featuredVideo': '',
'featuredImage': '',
'draft': False,
'enableComment': True
'slug': '',
'title': '',
'description': '',
'toc': True,
'authors': [],
'tags': [],
'categories': [],
'series': [],
'date': '',
'lastmod': '',
'featuredVideo': '',
'featuredImage': '',
'draft': False,
'enableComment': True
}
def standard_time(time_str):
dt = datetime.datetime.strptime(time_str, "%Y-%m-%d")
return dt.isoformat()
dt = datetime.datetime.strptime(time_str, "%Y-%m-%d")
return dt.isoformat()
def get_year(time_str):
dt = datetime.datetime.strptime(time_str, "%Y-%m-%d")
return dt.year
def create_post(filepath, args):
with open(filepath, 'w') as f:
f.write('---\n');
with open(filepath, 'w') as f:
f.write('---\n')
for key in DEFAULT_FRONT_MATTER.keys():
if key in ('title', 'slug'):
f.write(f'{key}: {args.posttitle}\n')
elif key in ('date', 'lastmod'):
if args.postdate is not None:
f.write(f'{key}: {standard_time(args.postdate)}\n')
else:
f.write(f'{key}: {datetime.datetime.now().isoformat()}\n')
else:
if type(DEFAULT_FRONT_MATTER[key]) is str:
if DEFAULT_FRONT_MATTER[key] == '':
f.write(f'{key}: \n')
else:
f.write(f'{key}: {DEFAULT_FRONT_MATTER[key]}\n')
elif type(DEFAULT_FRONT_MATTER[key]) is bool:
f.write(f'{key}: {"true" if DEFAULT_FRONT_MATTER[key] else "false"}\n')
else:
f.write(f'{key}: {DEFAULT_FRONT_MATTER[key]}\n')
for key in DEFAULT_FRONT_MATTER.keys():
if key in ('title', 'slug'):
f.write(f'{key}: {args.posttitle}\n')
elif key in ('date', 'lastmod'):
if args.postdate is not None:
f.write(f'{key}: {standard_time(args.postdate)}\n')
else:
f.write(f'{key}: {datetime.datetime.now().isoformat()}\n')
else:
if type(DEFAULT_FRONT_MATTER[key]) is str:
if DEFAULT_FRONT_MATTER[key] == '':
f.write(f'{key}: \n')
else:
f.write(f'{key}: {DEFAULT_FRONT_MATTER[key]}\n')
elif type(DEFAULT_FRONT_MATTER[key]) is bool:
f.write(f'{key}: {"true" if DEFAULT_FRONT_MATTER[key] else "false"}\n')
else:
f.write(f'{key}: {DEFAULT_FRONT_MATTER[key]}\n')
f.write('---\n\n');
f.write('---\n\n')
def mkdir(dirpath):
if os.path.isdir(dirpath) is False:
os.mkdir(dirpath)
if os.path.isdir(dirpath) is False:
os.makedirs(dirpath)
def main(args):
if args.posttitle is None:
print("Need a title!")
return
os.chdir('content/posts')
try:
mkdir(args.posttitle)
mkdir(os.path.join(args.posttitle, 'images'))
except:
print(traceback.format_exc())
print(f"Cannot create folder: {args.posttitle}")
os.chdir(args.posttitle)
create_post('index.md', args)
if args.posttitle is None:
print("Need a title!")
return
os.chdir('content/posts')
dir_name = os.path.join(str(get_year(args.postdate)), args.posttitle)
try:
mkdir(dir_name)
mkdir(os.path.join(dir_name, 'images'))
os.chdir(dir_name)
create_post('index.md', args)
except:
print(traceback.format_exc())
print(f"Cannot create folder: {dir_name}")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--posttitle", default=None, help="The title of post.")
parser.add_argument("-d", "--postdate", default=None, help="The date of post.")
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--posttitle", default=None, help="The title of post.")
parser.add_argument("-d", "--postdate", default=datetime.datetime.now().strftime('%Y-%m-%d'), help="The date of post.")
args = parser.parse_args()
main(args)
args = parser.parse_args()
main(args)