mirror of
https://github.com/jackyzha0/hugo-obsidian.git
synced 2024-06-14 11:42:35 +03:00
update to write json instead of yaml
This commit is contained in:
parent
31b4ffca89
commit
4691c1c600
17
main.go
17
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
|
||||
|
15
write.go
15
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user