Created
March 6, 2025 10:26
-
-
Save gh640/6f5d9652745574167156bba375f77f08 to your computer and use it in GitHub Desktop.
Python: カレントディレクトリの HTML ファイル一覧を表示する HTML ファイルを生成するスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""カレントディレクトリの HTML ファイル一覧を表示する HTML ファイルを生成するスクリプト""" | |
import html | |
from pathlib import Path | |
def main(): | |
html_files = sorted(p.name for p in Path(".").glob("*.html")) | |
html_files = (html.escape(x) for x in html_files) | |
file_list = [f'<li><a href="{x}">{x}</a></li>' for x in html_files] | |
html_content = "\n".join( | |
[ | |
"<!DOCTYPE html>", | |
"<html lang='ja'>", | |
"<head>", | |
"<meta charset='UTF-8'>", | |
"<title>HTML ファイル一覧</title>", | |
"</head>", | |
"<body>", | |
"<h1>HTML ファイル一覧</h1>", | |
"<ul>", | |
"{}", | |
"</ul>", | |
"</body>", | |
"</html>", | |
] | |
) | |
print(html_content.format("\n".join(file_list))) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment