內容目錄

之前沒用過 PanDOC 套件, 直接寫了個 python 來生成網站…

#!/usr/bin/env python3
import os
import re

head='''\  {name} ''' #.format(name=chapter_name)

def make_index(novel,max_ch,url,info):
    # make index html
    link='''{p}【{ind:0>4d}】 '''
    inf=info.replace("\n","

") with open(f"index_{novel}.html", 'w', encoding='utf-8') as output_file: output_file.write(head.format(name=novel)) output_file.write(f'''{inf}''') output_file.write(add_button_info(novel,max_ch,url,max_ch//2)) for i in range(1, max_ch): output_file.write(link.format(url=url,ind=i,name=novel,p="\n

" if i %10 ==1 else "\t")) def add_button_info(novel,max_ch,url,ind): link='''{emoji} ''' mi1= ind-1 if ind>1 else 1 mi100= ind-100 if ind>100 else 1 pl1= ind+1 if ind ''' def make_novel_html(fname,url): novel, ext = os.path.splitext(fname) os.system("mkdir -p {}".format(novel)) with open(fname, 'r', encoding='utf-8') as file: content = file.read() # 假设章节名格式为 "第X章" 或 "Chapter X" chapters = re.split(r'(第\d+章|Chapter \d+)', content) split_len = len(chapters) max_ch = split_len//2 # make index html of novel make_index(novel,max_ch,url,chapters[0]) for i in range(1, split_len, 2): chapter_name = chapters[i].strip() chapter_content = chapters[i + 1].strip() numbers = re.findall(r'\d+', chapter_name) num=int(numbers[0]) chapter_file = f"{novel}/{num:0>4d}.html" with open(chapter_file, 'w', encoding='utf-8') as output_file: output_file.write(head.format(name=chapter_name)) output_file.write(add_button_info(novel,max_ch,url,num)) output_file.write(chapter_name + " ") output_file.write(chapter_content.replace("\t","

")) output_file.write(add_button_info(novel,max_ch,url,num)) #print(num) # main url="https://davtw.go2see.me/info/小说" #url="file://wsl.localhost/Ubuntu/home/cyue/x" # WSL PATH TEST make_novel_html('一世独尊.md',url)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *