fixed relative paths for stylesheet
This commit is contained in:
parent
065c344c03
commit
93c0359df2
2 changed files with 16 additions and 7 deletions
|
@ -4,6 +4,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ficcdaf/zona/internal/util"
|
"github.com/ficcdaf/zona/internal/util"
|
||||||
|
@ -45,23 +47,31 @@ func processWithYaml(f []byte) (Metadata, []byte, error) {
|
||||||
return meta, []byte(split[2]), nil
|
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{}
|
p := &PageData{}
|
||||||
if title, ok := m["title"].(string); ok {
|
if title, ok := m["title"].(string); ok {
|
||||||
p.Title = util.WordsToTitle(title)
|
p.Title = util.WordsToTitle(title)
|
||||||
} else {
|
} else {
|
||||||
p.Title = util.PathToTitle(path)
|
p.Title = util.PathToTitle(in)
|
||||||
}
|
}
|
||||||
if icon, ok := m["icon"].(string); ok {
|
if icon, ok := m["icon"].(string); ok {
|
||||||
p.Icon = icon
|
p.Icon = icon
|
||||||
} else {
|
} else {
|
||||||
p.Icon = settings.IconName
|
p.Icon = settings.IconName
|
||||||
}
|
}
|
||||||
|
var stylePath string
|
||||||
if style, ok := m["style"].(string); ok {
|
if style, ok := m["style"].(string); ok {
|
||||||
p.Stylesheet = style
|
stylePath = style
|
||||||
} else {
|
} 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 {
|
if header, ok := m["header"].(string); ok {
|
||||||
p.HeaderName = header
|
p.HeaderName = header
|
||||||
// for now we use default anyways
|
// for now we use default anyways
|
||||||
|
@ -94,7 +104,7 @@ func ConvertFile(in string, out string, settings *Settings) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pd := buildPageData(metadata, in, settings)
|
pd := buildPageData(metadata, in, out, settings)
|
||||||
fmt.Println("Title: ", pd.Title)
|
fmt.Println("Title: ", pd.Title)
|
||||||
|
|
||||||
// build according to template here
|
// build according to template here
|
||||||
|
|
|
@ -94,8 +94,7 @@ func buildSettings(f []byte, outRoot string) (*Settings, error) {
|
||||||
|
|
||||||
if isDefaultStyle {
|
if isDefaultStyle {
|
||||||
stylePath := filepath.Join(outRoot, defaultNames["stylePath"])
|
stylePath := filepath.Join(outRoot, defaultNames["stylePath"])
|
||||||
// We convert the stylesheet path to its website root dir format and store it
|
s.StylePath = stylePath
|
||||||
s.StylePath = "/" + util.StripTopDir(stylePath)
|
|
||||||
err := util.CreateParents(stylePath)
|
err := util.CreateParents(stylePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, util.ErrorPrepend("Could not create default stylesheet directory: ", err)
|
return nil, util.ErrorPrepend("Could not create default stylesheet directory: ", err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue