Skip to content

Commit

Permalink
metadata: use date instead of full timestamp
Browse files Browse the repository at this point in the history
index: make date monospace
  • Loading branch information
RaphaelPour committed Jan 15, 2024
1 parent 68bc5b1 commit 327d2d1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# For next release
* **Raphael Pour**
* metadata: render posts with date instead of full timestamp

*Not released yet*

# Minor Release v2.1.0 (2024-01-15)
* **Raphael Pour**
* templates:
Expand Down
2 changes: 1 addition & 1 deletion cmd/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
body { max-width: 80ch; margin-left: auto; margin-right: auto; font-family: "Roboto Slab", serif;}
h1 { margin:0px;}
pre { width:100%;overflow:auto}
.date { margin-top:10px;font-size: small; color: gray; }
.date { margin-top:10px;font-size: small; font-family: monospace; color: gray; }
.post { margin-top:10px;}
</style>
</head>
Expand Down
3 changes: 1 addition & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -67,7 +66,7 @@ var listCmd = &cobra.Command{
}

table.Append([]string{
time.Unix(metadata.CreatedAt, 0).String(),
metadata.Date(),
metadata.Status,
fmt.Sprintf("%t", metadata.Static),
metadata.Title,
Expand Down
5 changes: 2 additions & 3 deletions cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ var renderCmd = &cobra.Command{
}
}

timestamp := time.Unix(meta.CreatedAt, 0)
postFileName := fmt.Sprintf(
POST_FILE_TEMPLATE,
slugTitle,
Expand All @@ -167,8 +166,8 @@ var renderCmd = &cobra.Command{
Link: postFileName,
PermaLink: fmt.Sprintf("https://%s/%s.html", cfg.Domain, slugTitle),
HomeLink: INDEX_FILE,
Timestamp: timestamp.Unix(),
CreatedAt: timestamp.String(),
Timestamp: meta.CreatedAt,
CreatedAt: meta.Date(),
Content: renderedStr,
Rendered: template.HTML(renderedStr),
FeaturedImage: featuredImage,
Expand Down
5 changes: 5 additions & 0 deletions internal/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"
)

/**
Expand Down Expand Up @@ -60,3 +61,7 @@ func (m Metadata) Save(postPath string) error {

return nil
}

func (m Metadata) Date() string {
return time.Unix(m.CreatedAt, 0).Format(time.DateOnly)
}
1 change: 1 addition & 0 deletions internal/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestLoadMetadata(t *testing.T) {

require.Equal(t, title, meta.Title)
require.Equal(t, date, meta.CreatedAt)
require.Equal(t, "1970-01-01", meta.Date())
}

func TestNewInvalidMetadata(t *testing.T) {
Expand Down

0 comments on commit 327d2d1

Please sign in to comment.