diff options
| author | a73x <[email protected]> | 2024-08-27 20:29:39 +0100 |
|---|---|---|
| committer | a73x <[email protected]> | 2024-08-27 20:29:39 +0100 |
| commit | e4288632856f79952fc25b17ced4895a51f6aefd (patch) | |
| tree | 44a00497ea561158a74eba62fba4c29ad91fb9e8 | |
| parent | d38fc83df3824b840f0b3930e4cb7236bdab84b2 (diff) | |
chore(embed): refactor embed fs
| -rw-r--r-- | content/embed.go | 7 | ||||
| -rw-r--r-- | embed.go | 12 | ||||
| -rw-r--r-- | markdown/markdown.go | 14 | ||||
| -rw-r--r-- | pages/pages.go | 6 | ||||
| -rw-r--r-- | public/embed.go | 8 | ||||
| -rw-r--r-- | templates/embed.go | 7 | ||||
| -rw-r--r-- | web/web.go | 4 |
7 files changed, 34 insertions, 24 deletions
diff --git a/content/embed.go b/content/embed.go new file mode 100644 index 0000000..be34e02 --- /dev/null +++ b/content/embed.go @@ -0,0 +1,7 @@ +package content + +import "embed" + +//go:embed *.md +//go:embed posts/*.md +var FS embed.FS diff --git a/embed.go b/embed.go deleted file mode 100644 index e3e27c2..0000000 --- a/embed.go +++ /dev/null @@ -1,12 +0,0 @@ -package home - -import "embed" - -//go:embed public/static/*.svg -//go:embed public/static/*.woff2 -//go:embed templates/*.html -//go:embed templates/layouts/*.html -//go:embed content/*.md -//go:embed content/posts/*.md - -var Content embed.FS diff --git a/markdown/markdown.go b/markdown/markdown.go index 0924208..92db876 100644 --- a/markdown/markdown.go +++ b/markdown/markdown.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "git.sr.ht/~a73x/home" + "git.sr.ht/~a73x/home/content" "github.com/adrg/frontmatter" ) @@ -18,18 +18,18 @@ type Content struct { } func ParseContents() ([]Content, error) { - contentFS, err := fs.Sub(home.Content, "content") - if err != nil { - return nil, fmt.Errorf("no content found: %v", err) - } - contentFiles, err := glob(contentFS, ".", ".md") + // contentFS, err := fs.Sub(content.FS, "content") + // if err != nil { + // return nil, fmt.Errorf("no content found: %v", err) + // } + contentFiles, err := glob(content.FS, ".", ".md") if err != nil { return nil, fmt.Errorf("failed to glob: %v", err) } res := make([]Content, 0, len(contentFiles)) for _, contentFile := range contentFiles { - c, err := parseMarkdownFile(contentFS, contentFile) + c, err := parseMarkdownFile(content.FS, contentFile) if err != nil { return nil, fmt.Errorf("failed to read markdown file: %v", err) } diff --git a/pages/pages.go b/pages/pages.go index fbd179a..63c3432 100644 --- a/pages/pages.go +++ b/pages/pages.go @@ -5,9 +5,9 @@ import ( "fmt" "text/template" - "git.sr.ht/~a73x/home" "git.sr.ht/~a73x/home/html" "git.sr.ht/~a73x/home/markdown" + "git.sr.ht/~a73x/home/templates" ) type GlobalState struct { @@ -21,8 +21,8 @@ type ParserPair struct { func renderTemplate(config GlobalState, content markdown.Content) (string, error) { tmpl := content.Meta["template"] - chosenTemplate := fmt.Sprintf("templates/%s.html", tmpl) - t, err := template.ParseFS(home.Content, chosenTemplate, "templates/layouts/*.html") + chosenTemplate := fmt.Sprintf("%s.html", tmpl) + t, err := template.ParseFS(templates.FS, chosenTemplate, "layouts/*.html") if err != nil { return "", fmt.Errorf("failed to parse layouts: %v", err) } diff --git a/public/embed.go b/public/embed.go new file mode 100644 index 0000000..76fc18e --- /dev/null +++ b/public/embed.go @@ -0,0 +1,8 @@ +package public + +import "embed" + +//go:embed static/*.svg +//go:embed static/*.woff2 + +var FS embed.FS diff --git a/templates/embed.go b/templates/embed.go new file mode 100644 index 0000000..80f8511 --- /dev/null +++ b/templates/embed.go @@ -0,0 +1,7 @@ +package templates + +import "embed" + +//go:embed *.html +//go:embed layouts/*.html +var FS embed.FS @@ -6,8 +6,8 @@ import ( "net/http" "time" - "git.sr.ht/~a73x/home" "git.sr.ht/~a73x/home/pages" + "git.sr.ht/~a73x/home/public" "go.uber.org/zap" ) @@ -37,7 +37,7 @@ func New(logger *zap.Logger) (*http.Server, error) { }) } - staticFs, err := fs.Sub(home.Content, "public/static") + staticFs, err := fs.Sub(public.FS, "static") if err != nil { return nil, fmt.Errorf("failed to setup static handler: %v", err) } |
