diff --git a/generate_index_html.py b/generate_index_html.py index 970fdeb..7aeb137 100644 --- a/generate_index_html.py +++ b/generate_index_html.py @@ -85,37 +85,41 @@ def generate_index_html(root_dir): ''' directory_html = '' + table_content = {} def generate_directory_html(directory, level=0): content = '' + first_directory = None for entry in sorted(os.listdir(directory)): if entry.startswith('.'): continue path = os.path.join(directory, entry) rel_path = os.path.relpath(path, root_dir) if os.path.isdir(path): + if first_directory is None: + first_directory = rel_path.replace("\\", "/") content += f''' - +
{generate_directory_html(path, level + 1)}
''' elif entry.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp', '.tiff')): - https_url = base_url + rel_path - cdn_url_complete = cdn_url + rel_path - table_content.append((entry, https_url, cdn_url_complete)) - return content + if rel_path.replace("\\", "/").rsplit("/", 1)[0] not in table_content: + table_content[rel_path.replace("\\", "/").rsplit("/", 1)[0]] = [] + https_url = base_url + rel_path.replace("\\", "/") + cdn_url_complete = cdn_url + rel_path.replace("\\", "/") + table_content[rel_path.replace("\\", "/").rsplit("/", 1)[0]].append((entry, https_url, cdn_url_complete)) + return content, first_directory - table_content = [] - - directory_html += generate_directory_html(root_dir) + directory_html, first_directory = generate_directory_html(root_dir) html_content += directory_html html_content += '''

图片信息

- +
@@ -123,23 +127,33 @@ def generate_directory_html(directory, level=0): ''' - for entry, https_url, cdn_url_complete in table_content: - html_content += f''' - - - - - - ''' - html_content += '''
缩略图 HTTPS 访问地址
{entry}{https_url}{cdn_url_complete}