Skip to content

Commit

Permalink
fix: build
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmaziyo committed Dec 28, 2024
1 parent 26a739d commit afe8b14
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import os
import httpx
import json
import re
import urllib.parse
import datetime

def fetch_ci_time(filePath):
entries = httpx.get("https://api.github.com/repos/tw93/weekly/commits?path=" + filePath + "&page=1&per_page=1")
ciTime= entries.json()[0]["commit"]["committer"]["date"].split("T")[0]
return ciTime
# return datetime.datetime.strptime(ciTime,"%Y-%m-%d")
def fetch_ci_time(file_path):
url = f"https://api.github.com/repos/Dmaziyo/Myzara/commits?path={file_path}&page=1&per_page=1"
response = httpx.get(url)
ci_time = response.json()[0]["commit"]["committer"]["date"].split("T")[0]
return ci_time

if __name__ == "__main__":
readmefile=open('README.md','w')
readmefile.write("# 潮流周刊\n\n> 记录工程师 Tw93 的不枯燥生活,欢迎订阅,也欢迎 [推荐](https://github.com/tw93/weekly/discussions/22) 你的好东西,Fork 自用可见 [开发文档](https://github.com/tw93/weekly/blob/main/Deploy.md),期待你玩得开心~\n\n")
recentfile=open('RECENT.md','w')
with open('README.md', 'w') as readme_file, open('RECENT.md', 'w') as recent_file, open('posts.json', 'w') as posts_file:
readme_file.write("# 摸鱼咋啦\n\n> 记录自己的%2,aka每周摸到的🐟(不定期更新~\n\n")

for root, dirs, filenames in os.walk('./src/pages/posts'):
filenames = sorted(filenames, key=lambda x:float(re.findall("(\d+)",x)[0]), reverse=True)
for root, dirs, filenames in os.walk('./src/pages/posts'):
filenames = sorted(filenames, key=lambda x: float(re.findall(r"(\d+)", x)[0]), reverse=True)

for index, name in enumerate(filenames):
if name.endswith('.md'):
filepath = urllib.parse.quote(name)
oldTitle = name.split('.md')[0]
url = 'https://weekly.tw93.fun/posts/' + oldTitle
title = '第 ' + oldTitle.split('-')[0] + ' 期 - ' + oldTitle.split('-')[1]
readmeMd= '* [{}]({})\n'.format(title, url)
dateList = ["2022-10-10","2022-09-26","2022-09-12","2022-09-05","2022-08-29"]
num = int(oldTitle.split('-')[0])
if index < 5 :
if num < 100 :
modified = dateList[99-num]
else :
modified = fetch_ci_time('/src/pages/posts/' + filepath)
posts = []
for index, name in enumerate(filenames):
if name.endswith('.md'):
file_path = urllib.parse.quote(name)
old_title = name.split('.md')[0]
num = int(old_title.split('-')[0])
short_title = old_title.split('-')[1]
url = f'https://dmaziyo.github.io/Myzara/posts/{old_title}'
title = f'第 {num} 期 - {short_title}'
readme_md = f'* [{title}]({url})\n'
posts.append({"num": num, "title": short_title, "url": url})

recentMd= '* [{}]({}) - {}\n'.format(title, url, modified)
recentfile.write(recentMd)
readmefile.write(readmeMd)
if index < 5:
modified = fetch_ci_time(f'/src/pages/posts/{file_path}')
recent_md = f'* [{title}]({url}) - {modified}\n'
recent_file.write(recent_md)

recentfile.close()
readmefile.close()
readme_file.write(readme_md)

json.dump(posts, posts_file, ensure_ascii=False, indent=2)

0 comments on commit afe8b14

Please sign in to comment.