From 5ea362d449384df250c672e18fe31303768dd3b1 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sun, 18 Jul 2021 11:50:13 -0400 Subject: [PATCH] better path handling --- main.go | 9 ++++++++- partials/graph_partial.html | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 75a6fda..2027a57 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,13 @@ func hugoPathTrim(source string) string { return strings.TrimSuffix(strings.TrimSuffix(source, "/index"), "_index") } +func processTarget(source string) string { + if strings.HasPrefix(source, "/") { + return strings.TrimSuffix(source, ".md") + } + return "/" + strings.TrimSuffix(source, ".md") +} + // parse single file for links func parse(dir, pathPrefix string) []Link { // read file @@ -47,7 +54,7 @@ func parse(dir, pathPrefix string) []Link { fmt.Printf(" %s\n", trim(target, pathPrefix, ".md")) links = append(links, Link{ Source: hugoPathTrim(trim(dir, pathPrefix, ".md")), - Target: strings.Split(target, "#")[0], + Target: strings.Split(processTarget(target), "#")[0], Text: text, }) } diff --git a/partials/graph_partial.html b/partials/graph_partial.html index ea9cf1a..17910b8 100644 --- a/partials/graph_partial.html +++ b/partials/graph_partial.html @@ -23,7 +23,7 @@ } const color = (d) => { - if (d.id === curPage) { + if (d.id === curPage || (d.id === "/" && curPage === "")) { return "var(--g-node-active)" }