-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
build.py
41 lines (35 loc) · 1.52 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import httpx
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")
if __name__ == "__main__":
readmefile=open('README.md','w')
readmefile.write("# 潮流周刊\n\n> 记录工程师 Tw93 的不枯燥生活,欢迎订阅~\n")
recentfile=open('RECENT.md','w')
for root, dirs, filenames in os.walk('./src/pages/posts'):
filenames.sort(key=lambda f: int(re.sub('\D', '', f)))
filenames.sort(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)
recentMd= '* [{}]({}) - {}\n'.format(title, url, modified)
recentfile.write(recentMd)
readmefile.write(readmeMd)
recentfile.close()
readmefile.close()