from ftplib import all_errors import functools from operator import index import os from time import time_ns from tkinter.messagebox import NO from turtle import ht import markdown import sys from datetime import datetime
defget_style(paths: list[str]): res = '' for path in paths: res += '<link rel="stylesheet" type="text/css" href="%s">\n' % path return res
defread_file(name:str): text = '' withopen(name, "r", encoding="utf-8") as input_file: text = input_file.read() return text
defwrite_file(path:str,conetent :str): withopen(path, 'w',encoding='utf-8') as f: f.write(conetent)
defcmp(a,b): ta = a['time'] tb = b['time'] if ta > tb: return -1 elif ta < tb: return1 return0
defprocess(input_path:str,output_path:str): all_files = os.listdir(input_path) markdown_files = [x for x in all_files if x.endswith('.md')] indexes = [] csses = ['styles.css','custom.css'] for file in markdown_files: name = file[:-3] markdown_path = input_path +'/'+file print(markdown_path) html,time = generate_html(read_file(markdown_path),['../style/' + x for x in csses]) write_file(output_path+'/posts/'+name+'.html',html) #index_markdown += '[%s] [%s](./posts/%s.html)\t\n' % (name,name) indexes.append({'time':time,'name': name })
index_markdown = "# AGNO3\n Welcome to hhhxiao's blog\n\n" for item in indexes: index_markdown += ' %s [%s](./posts/%s.html)<br>' % (item['time'],item['name'],item['name']) index_html,_ = generate_html(index_markdown,['style/'+x for x in csses]) write_file(output_path+'/index.html',index_html)