From 93c0359df20cde33348a9c02302f16651d6f9938 Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Thu, 28 Nov 2024 19:05:24 -0500 Subject: [PATCH] fixed relative paths for stylesheet --- internal/builder/build_page.go | 20 +++++++++++++++----- internal/builder/config.go | 3 +-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/internal/builder/build_page.go b/internal/builder/build_page.go index c5fac75..e222f3e 100644 --- a/internal/builder/build_page.go +++ b/internal/builder/build_page.go @@ -4,6 +4,8 @@ import ( "bytes" "fmt" "html/template" + "log" + "path/filepath" "strings" "github.com/ficcdaf/zona/internal/util" @@ -45,23 +47,31 @@ func processWithYaml(f []byte) (Metadata, []byte, error) { return meta, []byte(split[2]), nil } -func buildPageData(m Metadata, path string, settings *Settings) *PageData { +func buildPageData(m Metadata, in string, out string, settings *Settings) *PageData { p := &PageData{} if title, ok := m["title"].(string); ok { p.Title = util.WordsToTitle(title) } else { - p.Title = util.PathToTitle(path) + p.Title = util.PathToTitle(in) } if icon, ok := m["icon"].(string); ok { p.Icon = icon } else { p.Icon = settings.IconName } + var stylePath string if style, ok := m["style"].(string); ok { - p.Stylesheet = style + stylePath = style } else { - p.Stylesheet = settings.StylePath + stylePath = settings.StylePath } + curDir := filepath.Dir(out) + relPath, err := filepath.Rel(curDir, stylePath) + // fmt.Printf("fp: %s, sp: %s, rp: %s\n", curDir, stylePath, relPath) + if err != nil { + log.Fatalln("Error calculating stylesheet path: ", err) + } + p.Stylesheet = relPath if header, ok := m["header"].(string); ok { p.HeaderName = header // for now we use default anyways @@ -94,7 +104,7 @@ func ConvertFile(in string, out string, settings *Settings) error { if err != nil { return err } - pd := buildPageData(metadata, in, settings) + pd := buildPageData(metadata, in, out, settings) fmt.Println("Title: ", pd.Title) // build according to template here diff --git a/internal/builder/config.go b/internal/builder/config.go index de88646..5f96c41 100644 --- a/internal/builder/config.go +++ b/internal/builder/config.go @@ -94,8 +94,7 @@ func buildSettings(f []byte, outRoot string) (*Settings, error) { if isDefaultStyle { stylePath := filepath.Join(outRoot, defaultNames["stylePath"]) - // We convert the stylesheet path to its website root dir format and store it - s.StylePath = "/" + util.StripTopDir(stylePath) + s.StylePath = stylePath err := util.CreateParents(stylePath) if err != nil { return nil, util.ErrorPrepend("Could not create default stylesheet directory: ", err)