Browse Source

fix(ci): support path and children coexistence

Signed-off-by: Swilder-M <poxiaobbs@gmail.com>
Swilder-M 2 years ago
parent
commit
dfb03d5789
2 changed files with 10 additions and 11 deletions
  1. 7 8
      .github/scripts/directory_check.py
  2. 3 3
      .github/scripts/remove_unused.py

+ 7 - 8
.github/scripts/directory_check.py

@@ -16,7 +16,8 @@ def check_md_content(md_file):
         success = False
         return
 
-    md_content = open(md_file, 'r').read()
+    md_content = re.sub(r'<!--([\s\S]*?)-->', '', open(md_file, 'r').read())
+
     if 'ee' in directory_file:
         md_content = re.sub(r'{% emqxce %}([\s\S]*?){% endemqxce %}', '', md_content)
     else:
@@ -27,7 +28,7 @@ def check_md_content(md_file):
     for url in url_list:
         if url[0].endswith('!'):
             continue
-        if url[2].startswith(('http://', 'https://', '<', '#', 'mailto:')) or url[2].find('.md') == -1:
+        if url[2].startswith(('http://', 'https://', '<', '#', 'mailto:', 'tel:')):
             continue
         url_path = url[2].split('.md')[0]
         ref_md_path = os.path.join(f'{"/".join(md_file.split("/")[:-1])}/', f'{url_path}.md')
@@ -56,13 +57,8 @@ def get_md_files(dir_config, path):
     for i in dir_config:
         md_name = i.get('path')
         md_children = i.get('children')
-        if md_name and md_children:
-            print(f'{i.get("title")} has path and children')
-            success = False
 
-        if md_children:
-            md_list += get_md_files(md_children, path)
-        else:
+        if md_name:
             if md_name.startswith(('http://', 'https://')):
                 continue
             elif md_name == './':
@@ -70,6 +66,9 @@ def get_md_files(dir_config, path):
             else:
                 md_list.append(f'{docs_path}/{path}/{md_name}.md')
 
+        if md_children:
+            md_list += get_md_files(md_children, path)
+
     return list(set(md_list))
 
 

+ 3 - 3
.github/scripts/remove_unused.py

@@ -8,13 +8,13 @@ docs_path = sys.argv[1]
 def get_markdown_file(dir_config, base_path):
     current_files = []
     for row in dir_config:
-        if row.get('children'):
-            current_files += get_markdown_file(row['children'], base_path)
-        else:
+        if row.get('path'):
             current_files.append(
                 f'{base_path}/README.md' if row['path'] == './'
                 else f'{base_path}/{row["path"]}.md'
             )
+        if row.get('children'):
+            current_files += get_markdown_file(row['children'], base_path)
     return current_files