Compare commits

...

2 Commits

Author SHA1 Message Date
8e30297639 优化 2023-04-14 20:39:29 +08:00
e10527c3d2 close body 2023-04-14 14:43:32 +08:00

View File

@ -23,6 +23,7 @@ func fetch(u string, fn ...func(s string) string) string {
if err != nil { if err != nil {
return "" return ""
} }
defer res.Body.Close()
html := string(s) html := string(s)
for _, f := range fn { for _, f := range fn {
html = f(html) html = f(html)
@ -30,12 +31,12 @@ func fetch(u string, fn ...func(s string) string) string {
return html return html
} }
func dayLimit(today, forwardDay int, s string) string { func dayLimit(today, forwardDay int, s, format string) string {
da := date.FindStringSubmatch(s) da := date.FindStringSubmatch(s)
if len(da) <= 1 { if len(da) <= 1 {
return s return s
} }
t, err := time.Parse(time.RFC1123Z, da[1]) t, err := time.Parse(format, da[1])
if err != nil { if err != nil {
return s return s
} }
@ -47,7 +48,7 @@ func dayLimit(today, forwardDay int, s string) string {
func filterItem(html string, today, recentDay int) string { func filterItem(html string, today, recentDay int) string {
return zhihuReg.ReplaceAllStringFunc(html, func(s string) string { return zhihuReg.ReplaceAllStringFunc(html, func(s string) string {
return dayLimit(today, recentDay, s) return dayLimit(today, recentDay, s, time.RFC1123Z)
}) })
} }