]> Sergey Matveev's repositories - feeder.git/commitdiff
Latest post time should be the directory mtime
authorSergey Matveev <stargrave@stargrave.org>
Fri, 18 Feb 2022 16:35:16 +0000 (19:35 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 18 Feb 2022 16:35:18 +0000 (19:35 +0300)
Because some feeds has older feed's datetime than its posts ones.

cmd/feed2mdir/main.go

index 5e538ba703e8245171dd2768ff598f689914aa0f..2699d6cc6e01aa6c2cfbac407eef2e0f39450e6a 100644 (file)
@@ -58,6 +58,7 @@ func main() {
        news := 0
        var when *time.Time
        now := time.Now()
        news := 0
        var when *time.Time
        now := time.Now()
+       latest := &time.Time{}
        for n, item := range feed.Items {
                if n == int(*maxEntries) {
                        break
        for n, item := range feed.Items {
                if n == int(*maxEntries) {
                        break
@@ -70,6 +71,9 @@ func main() {
                } else {
                        when = &now
                }
                } else {
                        when = &now
                }
+               if latest.Before(*when) {
+                       latest = when
+               }
                var what string
                if len(item.Content) == 0 {
                        what = item.Description
                var what string
                if len(item.Content) == 0 {
                        what = item.Description
@@ -143,17 +147,9 @@ func main() {
                }
                news++
        }
                }
                news++
        }
-       when = nil
-       if feed.PublishedParsed != nil {
-               when = feed.PublishedParsed
-       } else if feed.UpdatedParsed != nil {
-               when = feed.UpdatedParsed
-       }
-       if when != nil {
-               for _, d := range []string{"cur", "new"} {
-                       if err = os.Chtimes(path.Join(mdir, d), *when, *when); err != nil {
-                               log.Fatalln(err)
-                       }
+       for _, d := range []string{"cur", "new"} {
+               if err = os.Chtimes(path.Join(mdir, d), *latest, *latest); err != nil {
+                       log.Fatalln(err)
                }
        }
        fmt.Println(feed.Title)
                }
        }
        fmt.Println(feed.Title)