Skip to content

Commit

Permalink
Move http_cache.yml to ./assets/data/cache.yml
Browse files Browse the repository at this point in the history
Was in ./internal/http_cache.yml, difficult to choose a convential
location. It is data that's used in the build. But it's also modified by
the build.
  • Loading branch information
marcuswhybrow committed Apr 27, 2024
1 parent 7e34b4e commit 7a2abeb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 102 deletions.
2 changes: 2 additions & 0 deletions internal/blog/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blog

import (
"context"
"fmt"
"path/filepath"
"strings"

Expand All @@ -11,6 +12,7 @@ import (

func Write(catalog *rprCatalog.Catalog) ([]*BlogPost, error) {
postPaths := utils.Files(".", "assets/blog", func(filePath string) (*string, error) {
fmt.Println("Post Path:", filePath)
ext := filepath.Ext(filePath)
if strings.ToLower(ext) != ".md" {
return nil, nil
Expand Down
2 changes: 2 additions & 0 deletions internal/catalog/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type AssetFrontMatter struct {
}

func NewAsset(assetPath string, markdownParser goldmark.Markdown, httpCache *cache.HTTPCache, avatarPaths *AvatarPaths) (*Asset, error) {
fmt.Println("new asset: " + assetPath)
fileName := filepath.Base(assetPath)
fileStem := strings.TrimSuffix(fileName, filepath.Ext(assetPath))

Expand All @@ -122,6 +123,7 @@ func NewAsset(assetPath string, markdownParser goldmark.Markdown, httpCache *cac

// 🔗 Details

fmt.Println("File stem: ", fileStem)
id := fileStem[11:]
urlAbsPath := "/" + id
editPermalink := global.GITHUB_LINK + path.Join("/edit/main", assetPath)
Expand Down
2 changes: 1 addition & 1 deletion internal/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewCatalog(assetsPath string) *Catalog {

// 📶 Get HTTP Cache from file

cacheData, err := cache.DataFromYAMLFile("./internal/http_cache.yml")
cacheData, err := cache.DataFromYAMLFile(global.CACHE_PATH)
if err != nil {
log.Panicf("Failed to read cache file '%v': %v", global.CACHE_PATH, err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

const BUILD_OUTPUT = "./build"
const ASSETS = "./assets"
const CACHE_PATH = "./internal/http_cache.yml"
const CACHE_PATH = "./assets/data/cache.yml"

const GITHUB_LINK = "https://github.com/marcuswhybrow/ray-peat-rodeo"
const SPONSOR_LINK = "https://github.com/sponsors/marcuswhybrow"
Expand Down
82 changes: 0 additions & 82 deletions internal/http_cache.yml

This file was deleted.

32 changes: 14 additions & 18 deletions internal/utils/filesystem.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package utils

import (
"fmt"
"io/fs"
"log"
"os"
Expand All @@ -16,27 +15,24 @@ import (
func Files[Result any](pwd, scope string, f func(filePath string) (*Result, error)) []Result {
results := []Result{}

err := fs.WalkDir(os.DirFS(pwd), scope, func(filePath string, entry fs.DirEntry, err error) error {
if err != nil {
return fmt.Errorf("Failed to walk dir: %v", err)
}

if !entry.IsDir() {
result, err := f(filePath)
if err != nil {
return err
}
entries, err := fs.ReadDir(os.DirFS(pwd), scope)
if err != nil {
log.Fatalf("Failed to read directory '%v': %v\n", path.Join(pwd, scope), err)
}

if result != nil {
results = append(results, *result)
}
for _, entry := range entries {
if entry.IsDir() {
continue
}

return nil
})
result, err := f(path.Join(scope, entry.Name()))
if err != nil {
log.Fatal("Failed to convert file entry to Result:", err)
}

if err != nil {
log.Panicf("Failed to read directory '%v': %v", path.Join(pwd, scope), err)
if result != nil {
results = append(results, *result)
}
}

return results
Expand Down

0 comments on commit 7a2abeb

Please sign in to comment.