Skip to content

Commit

Permalink
Change layout of site generation
Browse files Browse the repository at this point in the history
  • Loading branch information
codemicro committed Apr 12, 2024
1 parent 4f2facd commit 32eee36
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.site
.vscode
_dist
34 changes: 28 additions & 6 deletions cli/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"bytes"
"embed"
_ "embed"
"fmt"
"io/fs"
"io/ioutil"
"os"
"sort"
Expand Down Expand Up @@ -162,11 +164,10 @@ func articleLinkComponent(url, title, description, date, hnURL string) g.Node {
)
}

func GenerateSite() error {

const outputDir = ".site"
//go:embed static
var staticSiteResources embed.FS

// read CSV file
func GenerateSite() error {
var entries []*readingListEntry

fcont, err := ioutil.ReadFile(readingListFile)
Expand Down Expand Up @@ -203,7 +204,28 @@ func GenerateSite() error {
return err
}

_ = os.Mkdir(outputDir, 0777)
if err := fs.WalkDir(fs.FS(staticSiteResources), "static", func(inputPath string, d fs.DirEntry, err error) error {
outputPath := siteOutputDir + inputPath[len("static"):]

fmt.Println(inputPath, outputPath)

if err != nil {
return err
}

if d.IsDir() {
return os.MkdirAll(outputPath, 0777)
}

data, err := staticSiteResources.ReadFile(inputPath)
if err != nil {
return err
}

return os.WriteFile(outputPath, data, 0644)
}); err != nil {
return err
}

return ioutil.WriteFile(outputDir+"/index.html", outputContent, 0644)
return ioutil.WriteFile(siteOutputDir+"/index.html", outputContent, 0644)
}
9 changes: 8 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import (
"time"
)

var readingListFile = "readingList.csv"
var (
readingListFile = "readingList.csv"
siteOutputDir = "_dist"
)

func init() {
if v := os.Getenv("RL_CSV_FILE"); v != "" {
readingListFile = v
}

if v := os.Getenv("RL_OUTPUT_DIR"); v != "" {
siteOutputDir = v
}
}

type readingListEntry struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes

0 comments on commit 32eee36

Please sign in to comment.