瀏覽代碼

210719 collection list editing

yukyo 3 年之前
父節點
當前提交
43bc47483b
共有 3 個文件被更改,包括 17 次插入6 次删除
  1. 14 3
      models/contents/routes.py
  2. 1 1
      models/store_locations/routes.py
  3. 2 2
      models/utils/__init__.py

+ 14 - 3
models/contents/routes.py

@@ -18,11 +18,20 @@ def _get_data(file_dir):
             data_field.remove('title:')
             s = line.split('"')
             result['title'] = s[1]
+        elif 'date:' in line:
+            #data_field.remove('date: ')
+            s = line.replace('date: ', '').strip()
+            result['date'] = s
+        elif 'draft:' in line:
+            #data_field.remove('draft: ')
+            s = line.replace('draft: ', '').strip()
+            result['draft'] = s
         elif 'url:' in line:
             data_field.remove('url:')
             s = line.split('"')
             result['url'] = s[1]
 
+
     data_field = list(DATA_FIELD)
     result = {}
     with open(file_dir, 'r', encoding="utf-8") as md:
@@ -179,9 +188,11 @@ def gen_content():
     dir_ = path.join(_search_content_dir(
         request.json.get('type'), request.json.get('categories')), name)
     if dir_:
-        mkdir(dir_)
-        mkdir(path.join(dir_, 'img'))
-        with open(path.join(dir_, 'index.md'), 'w') as md:
+        if not path.exists(dir_):
+            mkdir(dir_)
+        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}
 

+ 1 - 1
models/store_locations/routes.py

@@ -95,7 +95,7 @@ class StoreLocations(Resource):
                 parking=store_data.get('parking'))
             store_dir = get_store_dir()
             makedirs(store_dir, exist_ok=True)
-            with open(path.join(store_dir, 'index.md'), 'w') as md:
+            with open(path.join(store_dir, 'index.md'), 'w', encoding="utf-8") as md:
                 md.write(store_location_md)
             update_md.append(store_location_md)
         return update_md

+ 2 - 2
models/utils/__init__.py

@@ -4,12 +4,12 @@ from datetime import datetime, timezone, timedelta
 
 
 def write_md(f_dir, content):
-    with open(f_dir, 'w') as md:
+    with open(f_dir, 'w',encoding="utf-8") as md:
         md.write(content)
 
 
 def read_line_md(f_dir):
-    with open(f_dir, 'r') as md:
+    with open(f_dir, 'r',encoding="utf-8") as md:
         pre_content = md.readlines()
     return pre_content