From 6155ce71dc1884e6caae18770e6e2c09eabe1482 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sat, 17 Jul 2021 11:39:53 -0400 Subject: [PATCH] fix parsing issues --- README.md | 13 ++++++++----- main.go | 13 +++++++++---- partials/graph_partial.html | 7 +++++++ partials/links_partial.html | 0 4 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 partials/graph_partial.html create mode 100644 partials/links_partial.html diff --git a/README.md b/README.md index 5d0e8b0..0342543 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,15 @@ # Obsidian Link Scrapper GitHub action and binary to scrape [Obsidian](http://obsidian.md/) vault for links and exposes them as a `.yml` file for easy consumption by [Hugo](https://gohugo.io/). -## Installation -`go install github.com/jackyzha0/hugo-obsidian` - -### Example Usage +## Example Usage (Binary) Read Markdown from the `/content` folder and place the resulting `linkIndex.yaml` into `/data` ```shell +# Installation +go install github.com/jackyzha0/hugo-obsidian + +# Run hugo-obsidian -input=content -output=data -``` \ No newline at end of file +``` + +## Example Usage (GitHub Action) diff --git a/main.go b/main.go index 679a690..90f4287 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,10 @@ func trim(source, prefix, suffix string) string { return strings.TrimPrefix(strings.TrimSuffix(source, suffix), prefix) } +func hugoPathTrim(source string) string { + return strings.TrimSuffix(strings.TrimSuffix(source, "/index"), "_index") +} + // parse single file for links func parse(dir, pathPrefix string) []Link { // read file @@ -42,8 +46,8 @@ func parse(dir, pathPrefix string) []Link { for text, target := range md.GetAllLinks(string(bytes)) { fmt.Printf(" %s\n", trim(target, pathPrefix, ".md")) links = append(links, Link{ - Source: trim(dir, pathPrefix, ".md"), - Target: target, + Source: hugoPathTrim(trim(dir, pathPrefix, ".md")), + Target: strings.Split(target, "#")[0], Text: text, }) } @@ -95,8 +99,9 @@ func index(links []Link) (index Index) { } // backlink (only if internal) - if val, ok := backlinkMap[l.Target]; ok { - val = append(val, bl) + + if _, ok := backlinkMap[l.Target]; ok { + backlinkMap[l.Target] = append(backlinkMap[l.Target], bl) } else { backlinkMap[l.Target] = []Link{bl} } diff --git a/partials/graph_partial.html b/partials/graph_partial.html new file mode 100644 index 0000000..c01c891 --- /dev/null +++ b/partials/graph_partial.html @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/partials/links_partial.html b/partials/links_partial.html new file mode 100644 index 0000000..e69de29