From 4691c1c600d0e3e6b715afebecbe41bb09ad4229 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Tue, 15 Feb 2022 19:36:14 -0500 Subject: [PATCH 1/2] update to write json instead of yaml --- main.go | 17 +++++++++-------- write.go | 15 +++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index a6dafea..5fa7cda 100644 --- a/main.go +++ b/main.go @@ -19,21 +19,22 @@ func init() { } type Link struct { - Source string - Target string - Text string + Source string `json:"source"` + Target string `json:"target"` + Text string `json:"text"` } type LinkTable = map[string][]Link type Index struct { - Links LinkTable - Backlinks LinkTable + Links LinkTable `json:"links"` + Backlinks LinkTable `json:"backlinks"` } type Content struct { - Title string - Content string - LastModified time.Time + Title string `json:"title"` + Content string `json:"content"` + LastModified time.Time `json:"lastmodified"` + Tags []string `json:"tags"` } type ContentIndex = map[string]Content diff --git a/write.go b/write.go index 6f166b3..e199e0a 100644 --- a/write.go +++ b/write.go @@ -1,38 +1,37 @@ package main import ( - "gopkg.in/yaml.v3" + "encoding/json" "io/ioutil" "path" ) -const message = "# THIS FILE WAS GENERATED USING github.com/jackyzha0/hugo-obsidian\n# DO NOT EDIT\n" func write(links []Link, contentIndex ContentIndex, toIndex bool, out string) error { index := index(links) resStruct := struct { - Index Index - Links []Link + Index Index `json:"index"` + Links []Link `json:"links"` }{ Index: index, Links: links, } - marshalledIndex, mErr := yaml.Marshal(&resStruct) + marshalledIndex, mErr := json.MarshalIndent(&resStruct, "", " ") if mErr != nil { return mErr } - writeErr := ioutil.WriteFile(path.Join(out, "linkIndex.yaml"), append([]byte(message), marshalledIndex...), 0644) + writeErr := ioutil.WriteFile(path.Join(out, "linkIndex.json"), marshalledIndex, 0644) if writeErr != nil { return writeErr } if toIndex { - marshalledContentIndex, mcErr := yaml.Marshal(&contentIndex) + marshalledContentIndex, mcErr := json.MarshalIndent(&contentIndex, "", " ") if mcErr != nil { return mcErr } - writeErr = ioutil.WriteFile(path.Join(out, "contentIndex.yaml"), append([]byte(message), marshalledContentIndex...), 0644) + writeErr = ioutil.WriteFile(path.Join(out, "contentIndex.json"), marshalledContentIndex, 0644) if writeErr != nil { return writeErr } From 479a7a215ed66344ffda3b740d71e47f0ceb376f Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Tue, 15 Feb 2022 19:37:02 -0500 Subject: [PATCH 2/2] update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ac6392a..52cdeb4 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ Used by [Quartz](https://github.com/jackyzha0/quartz) This repository comes to you in two parts. -1. GitHub Action (scrapes links into a `.yml` file) -2. Hugo Partial (turns `.yml` file into graphs and tables) +1. GitHub Action (scrapes links into a `.json` file) +2. Hugo Partial (turns `.json` file into graphs and tables) ## GitHub Action -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/). +GitHub action and binary to scrape [Obsidian](http://obsidian.md/) vault for links and exposes them as a `.json` file for easy consumption by [Hugo](https://gohugo.io/). ### Example Usage (Binary) -Read Markdown from the `/content` folder and place the resulting `linkIndex.yaml` (and `contentIndex.yaml` if the `index` flag is enabled) into `/data` +Read Markdown from the `/content` folder and place the resulting `linkIndex.json` (and `contentIndex.yaml` if the `index` flag is enabled) into `/data` ```shell # Installation