#!/usr/bin/python
import os
from os.path import join
from tools import read_file_into_list, read_txt_file
html_tpl = """
道阻且长,行则将至
最新文章:
联系:
Github
"""
# 读取 .top 文件中最新发表的20篇文章
# 每行格式为:202210241024.txt:::fuzzing
cur_dir = os.path.dirname(__file__)
top_file_list = read_file_into_list(join(cur_dir, ".top"))
top_file_list.sort(reverse=True)
top_temp = top_file_list[:20]
# 生成 top 文章列表
top = "\n"
for line in top_temp:
filepath = line.split(":::")
txt = read_txt_file(join(filepath[1], filepath[0]))
top += '{create_time} [{category}] {title}\n'.format(**txt)
# 生成 html 文件
html_file_path = join(cur_dir, "index.html")
with open(html_file_path, "w") as html_file:
print(html_tpl.format(top=top), file=html_file)
print("[+] Successful build html file: {}".format(html_file_path))