working on path normalizer
This commit is contained in:
parent
59ead0f26a
commit
bdd9e63fdf
3 changed files with 32 additions and 1 deletions
|
@ -59,7 +59,12 @@ func buildPageData(m Metadata, in string, out string, settings *Settings) *PageD
|
|||
p.Title = util.PathToTitle(in)
|
||||
}
|
||||
if icon, ok := m["icon"].(string); ok {
|
||||
p.Icon = icon
|
||||
i, err := util.NormalizePath(icon)
|
||||
if err != nil {
|
||||
p.Icon = settings.IconName
|
||||
} else {
|
||||
p.Icon = i
|
||||
}
|
||||
} else {
|
||||
p.Icon = settings.IconName
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package util
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
@ -108,3 +109,27 @@ func StripTopDir(path string) string {
|
|||
}
|
||||
return filepath.Join(components[1:]...)
|
||||
}
|
||||
|
||||
// we want to preserve a valid web-style path
|
||||
// and convert relative path to web-style
|
||||
// so we need to see
|
||||
// TODO; use Rel function to get abs path between
|
||||
// the file being analyzed's path, and what lil bro
|
||||
// is pointing to
|
||||
func NormalizePath(path string) (string, error) {
|
||||
// empty path is root
|
||||
if path == "" {
|
||||
return "/", nil
|
||||
}
|
||||
if path[0] == '.' {
|
||||
fmt.Println("Local path detected...")
|
||||
abs, err := filepath.Abs(path)
|
||||
fmt.Printf("abs: %s\n", abs)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Couldn't normalize path: %w", err)
|
||||
}
|
||||
return ReplaceRoot(abs, "/"), nil
|
||||
} else {
|
||||
return path, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
title: tiltetest
|
||||
icon: ../assets/pic.png
|
||||
---
|
||||
|
||||
# My amazing markdown file!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue