|
@@ -57,15 +57,22 @@ def _search_dir(url):
|
|
|
return path.dirname(file_dir)
|
|
|
|
|
|
|
|
|
-def _search_type_dir(type_):
|
|
|
+def _search_content_dir(type_, categories=None):
|
|
|
+ target = categories or type_
|
|
|
+
|
|
|
def _get_file_front_matter_type():
|
|
|
with open(file_dir, 'r', encoding="utf-8") as md:
|
|
|
md_line_data = md.readlines()
|
|
|
for line in md_line_data:
|
|
|
- if 'type:' in line:
|
|
|
- return list(filter(None, re.split('"|\n', line)))[-1]
|
|
|
+ if categories:
|
|
|
+ if 'categories' in line:
|
|
|
+ return list(filter(None, re.split('"|\n|]', line)))[-1]
|
|
|
+ else:
|
|
|
+ if 'type:' in line:
|
|
|
+ return list(filter(None, re.split('"|\n', line)))[-1]
|
|
|
+
|
|
|
for file_dir in _gen_content_files():
|
|
|
- if type_ == _get_file_front_matter_type():
|
|
|
+ if target == _get_file_front_matter_type():
|
|
|
return path.dirname(file_dir)
|
|
|
|
|
|
|
|
@@ -169,7 +176,8 @@ def upload_static_img():
|
|
|
def gen_content():
|
|
|
front_matter = request.json.get('frontMatter', '---\n---')
|
|
|
name = request.json.get('name', 'Undefind')
|
|
|
- dir_ = path.join(_search_type_dir(request.json.get('type')), name)
|
|
|
+ dir_ = path.join(_search_content_dir(
|
|
|
+ request.json.get('type'), request.json.get('categories')), name)
|
|
|
if dir_:
|
|
|
mkdir(dir_)
|
|
|
mkdir(path.join(dir_, 'img'))
|