|
@@ -33,7 +33,6 @@ def _get_data(file_dir):
|
|
|
s = line.split('"')
|
|
|
result['url'] = s[1]
|
|
|
|
|
|
-
|
|
|
data_field = list(DATA_FIELD)
|
|
|
result = {}
|
|
|
with open(file_dir, 'r', encoding="utf-8") as md:
|
|
@@ -136,10 +135,11 @@ class Content(Resource):
|
|
|
content_data = list(self._search_content())
|
|
|
file_dir = content_data[0].get('path')
|
|
|
if path.exists(file_dir):
|
|
|
- #remove(file_dir)
|
|
|
- shutil.rmtree(file_dir[0:file_dir.replace('\\','/').rfind('/')+1])
|
|
|
- #print(file_dir[0:file_dir.replace('\\','/').rfind('/')+1])
|
|
|
- logger.info('delete dir: {}'.format(file_dir[0:file_dir.replace('\\','/').rfind('/')+1]))
|
|
|
+ # remove(file_dir)
|
|
|
+ shutil.rmtree(file_dir[0:file_dir.replace('\\', '/').rfind('/')+1])
|
|
|
+ # print(file_dir[0:file_dir.replace('\\','/').rfind('/')+1])
|
|
|
+ logger.info('delete dir: {}'.format(
|
|
|
+ file_dir[0:file_dir.replace('\\', '/').rfind('/')+1]))
|
|
|
else:
|
|
|
logger.warning('delete fail with {} not exist'.format(file_dir))
|
|
|
|
|
@@ -191,26 +191,36 @@ def gen_content():
|
|
|
name = request.json.get('name', 'Undefind')
|
|
|
dir_ = path.join(_search_content_dir(
|
|
|
request.json.get('type'), request.json.get('categories')), name)
|
|
|
- #print(request.json.get('type') + ',' + request.json.get('categories'))
|
|
|
- if dir_:
|
|
|
+ if request.json.get('type') == "blog":
|
|
|
+ dir_ = CONTENT_DIR + "/"+request.json.get('type') + "/" + name
|
|
|
if not path.exists(dir_):
|
|
|
mkdir(dir_)
|
|
|
- else:
|
|
|
- return Response({},status=201)
|
|
|
if not path.exists(path.join(dir_, 'img')):
|
|
|
mkdir(path.join(dir_, 'img'))
|
|
|
with open(path.join(dir_, 'index.md'), 'w', encoding="utf-8") as md:
|
|
|
md.write(front_matter)
|
|
|
+ #print(front_matter)
|
|
|
+ else:
|
|
|
+ if dir_:
|
|
|
+ if not path.exists(dir_):
|
|
|
+ mkdir(dir_)
|
|
|
+ else:
|
|
|
+ return Response({}, status=201)
|
|
|
+ if not path.exists(path.join(dir_, 'img')):
|
|
|
+ mkdir(path.join(dir_, 'img'))
|
|
|
+ with open(path.join(dir_, 'index.md'), 'w', encoding="utf-8") as md:
|
|
|
+ md.write(front_matter)
|
|
|
+
|
|
|
return {'new_content': name}
|
|
|
|
|
|
|
|
|
-@contents_app.route('/api/get_cats', methods=['POST','GET'])
|
|
|
+@contents_app.route('/api/get_cats', methods=['POST', 'GET'])
|
|
|
def get_cats():
|
|
|
""" front_matter = request.json.get('frontMatter', '---\n---')
|
|
|
name = request.json.get('name', 'Undefind')
|
|
|
dir_ = path.join(_search_content_dir(
|
|
|
request.json.get('type'), request.json.get('categories')), name) """
|
|
|
- print(_search_content_dir('blog','home_inspection_knowledge'))
|
|
|
+ print(_search_content_dir('blog', 'home_inspection_knowledge'))
|
|
|
return {}
|
|
|
|
|
|
|
|
@@ -225,7 +235,7 @@ def gen_cat():
|
|
|
if not path.exists(dir_):
|
|
|
mkdir(dir_)
|
|
|
else:
|
|
|
- return Response({},status=201)
|
|
|
+ return Response({}, status=201)
|
|
|
if not path.exists(path.join(dir_, 'img')):
|
|
|
mkdir(path.join(dir_, 'img'))
|
|
|
with open(path.join(dir_, 'index.md'), 'w', encoding="utf-8") as md:
|