List future and expired dates in CSV format
authorDaniel Compton <desk@danielcompton.net>
Thu, 21 Feb 2019 01:34:32 +0000 (14:34 +1300)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 18 Mar 2019 23:33:02 +0000 (00:33 +0100)
It is useful to see the date that a post will be published, or the date
that it has expired, to build tooling around it. This commit writes
posts and their publish/expired date as CSV.

Fixes #5610

commands/list.go

index 9922e957df893ff00ba6f2d1eee101ad0a7c08d1..f49726b62fbc53989406d560a628200272d9f928 100644 (file)
 package commands
 
 import (
+       "encoding/csv"
+       "os"
        "path/filepath"
+       "time"
 
        "github.com/gohugoio/hugo/hugolib"
        "github.com/spf13/cobra"
@@ -101,11 +104,16 @@ posted in the future.`,
                                        return newSystemError("Error Processing Source Content", err)
                                }
 
+                               writer := csv.NewWriter(os.Stdout)
+                               defer writer.Flush()
+
                                for _, p := range sites.Pages() {
                                        if p.IsFuture() {
-                                               jww.FEEDBACK.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
+                                               err := writer.Write([]string{filepath.Join(p.File.Dir(), p.File.LogicalName()), p.PublishDate.Format(time.RFC3339)})
+                                               if err != nil {
+                                                       return newSystemError("Error writing future posts to stdout", err)
+                                               }
                                        }
-
                                }
 
                                return nil
@@ -137,11 +145,16 @@ expired.`,
                                        return newSystemError("Error Processing Source Content", err)
                                }
 
+                               writer := csv.NewWriter(os.Stdout)
+                               defer writer.Flush()
+
                                for _, p := range sites.Pages() {
                                        if p.IsExpired() {
-                                               jww.FEEDBACK.Println(filepath.Join(p.File.Dir(), p.File.LogicalName()))
+                                               err := writer.Write([]string{filepath.Join(p.File.Dir(), p.File.LogicalName()), p.ExpiryDate.Format(time.RFC3339)})
+                                               if err != nil {
+                                                       return newSystemError("Error writing expired posts to stdout", err)
+                                               }
                                        }
-
                                }
 
                                return nil