List future and expired dates in CSV format

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
This commit is contained in:
Daniel Compton 2019-02-21 14:34:32 +13:00 committed by Bjørn Erik Pedersen
parent 984a73af9e
commit 44f5c1c14c

View file

@ -14,7 +14,10 @@
package commands package commands
import ( import (
"encoding/csv"
"os"
"path/filepath" "path/filepath"
"time"
"github.com/gohugoio/hugo/hugolib" "github.com/gohugoio/hugo/hugolib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -101,11 +104,16 @@ posted in the future.`,
return newSystemError("Error Processing Source Content", err) return newSystemError("Error Processing Source Content", err)
} }
writer := csv.NewWriter(os.Stdout)
defer writer.Flush()
for _, p := range sites.Pages() { for _, p := range sites.Pages() {
if p.IsFuture() { 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 return nil
@ -137,11 +145,16 @@ expired.`,
return newSystemError("Error Processing Source Content", err) return newSystemError("Error Processing Source Content", err)
} }
writer := csv.NewWriter(os.Stdout)
defer writer.Flush()
for _, p := range sites.Pages() { for _, p := range sites.Pages() {
if p.IsExpired() { 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 return nil