Skip to content

Commit

Permalink
List future and expired dates in CSV format
Browse files Browse the repository at this point in the history
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
  • Loading branch information
danielcompton authored and bep committed Mar 18, 2019
1 parent 984a73a commit 44f5c1c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
package commands

import (
"encoding/csv"
"os"
"path/filepath"
"time"

"github.com/gohugoio/hugo/hugolib"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 44f5c1c

Please sign in to comment.