Only update metadata when deploying

This commit is contained in:
ekzyis 2025-10-18 22:36:59 +02:00
parent a3f9aed5d5
commit 818ca10962
2 changed files with 12 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"flag"
"fmt" "fmt"
"html/template" "html/template"
"io" "io"
@ -91,9 +92,13 @@ var (
), ),
) )
commit string commit string
updateMetadata bool
) )
func main() { func main() {
flag.BoolVar(&updateMetadata, "M", false, "Update metadata from Stacker News API")
flag.Parse()
output, err := exec.Command("git", "rev-parse", "--short", "HEAD").Output() output, err := exec.Command("git", "rev-parse", "--short", "HEAD").Output()
if err != nil { if err != nil {
fmt.Printf("error getting commit: %v\n", err) fmt.Printf("error getting commit: %v\n", err)
@ -192,13 +197,16 @@ func parsePost(path string) (*Post, error) {
// stacker news // stacker news
snId, _ := frontmatter["sn_id"].(int) snId, _ := frontmatter["sn_id"].(int)
var comments, sats int var comments, sats int
if snId > 0 { if updateMetadata && snId > 0 {
fmt.Printf("> updating metadata for %s\n", path)
fmt.Printf(">> fetching item %d from Stacker News\n", snId)
item, err := sn.NewClient().Item(snId) item, err := sn.NewClient().Item(snId)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get sn item %d: %v", snId, err) return nil, fmt.Errorf(">> failed to fetch item %d: %v", snId, err)
} }
comments = item.NComments comments = item.NComments
sats = item.Sats sats = item.Sats
fmt.Printf(">> new metadata: %d comments, %d sats\n", comments, sats)
} }
// url // url

2
deploy
View File

@ -11,7 +11,7 @@ log () {
log rm -r public/ log rm -r public/
log cp -r static/ public/ log cp -r static/ public/
log go run content.go log go run content.go -M
log tailwindcss -i input.css -o public/css/tailwind.css log tailwindcss -i input.css -o public/css/tailwind.css
log s3cmd sync $S3CMD_OPTS --dry-run public/ s3://www.ekzy.is log s3cmd sync $S3CMD_OPTS --dry-run public/ s3://www.ekzy.is