mirror of
https://github.com/jackyzha0/hugo-obsidian.git
synced 2024-06-14 11:42:35 +03:00
Merge pull request #13 from jackyzha0/draft-support
This commit is contained in:
commit
960ca0acc7
@ -3,13 +3,13 @@ Used by [Quartz](https://github.com/jackyzha0/quartz)
|
|||||||
|
|
||||||
This repository comes to you in two parts.
|
This repository comes to you in two parts.
|
||||||
|
|
||||||
1. GitHub Action (scrapes links into a `.yml` file)
|
1. GitHub Action (scrapes links into a `.json` file)
|
||||||
2. Hugo Partial (turns `.yml` file into graphs and tables)
|
2. Hugo Partial (turns `.json` file into graphs and tables)
|
||||||
|
|
||||||
## GitHub Action
|
## 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)
|
### 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
|
```shell
|
||||||
# Installation
|
# Installation
|
||||||
|
17
main.go
17
main.go
@ -19,21 +19,22 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Link struct {
|
type Link struct {
|
||||||
Source string
|
Source string `json:"source"`
|
||||||
Target string
|
Target string `json:"target"`
|
||||||
Text string
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LinkTable = map[string][]Link
|
type LinkTable = map[string][]Link
|
||||||
type Index struct {
|
type Index struct {
|
||||||
Links LinkTable
|
Links LinkTable `json:"links"`
|
||||||
Backlinks LinkTable
|
Backlinks LinkTable `json:"backlinks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Content struct {
|
type Content struct {
|
||||||
Title string
|
Title string `json:"title"`
|
||||||
Content string
|
Content string `json:"content"`
|
||||||
LastModified time.Time
|
LastModified time.Time `json:"lastmodified"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContentIndex = map[string]Content
|
type ContentIndex = map[string]Content
|
||||||
|
15
write.go
15
write.go
@ -1,38 +1,37 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/yaml.v3"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"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 {
|
func write(links []Link, contentIndex ContentIndex, toIndex bool, out string) error {
|
||||||
index := index(links)
|
index := index(links)
|
||||||
resStruct := struct {
|
resStruct := struct {
|
||||||
Index Index
|
Index Index `json:"index"`
|
||||||
Links []Link
|
Links []Link `json:"links"`
|
||||||
}{
|
}{
|
||||||
Index: index,
|
Index: index,
|
||||||
Links: links,
|
Links: links,
|
||||||
}
|
}
|
||||||
marshalledIndex, mErr := yaml.Marshal(&resStruct)
|
marshalledIndex, mErr := json.MarshalIndent(&resStruct, "", " ")
|
||||||
if mErr != nil {
|
if mErr != nil {
|
||||||
return mErr
|
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 {
|
if writeErr != nil {
|
||||||
return writeErr
|
return writeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if toIndex {
|
if toIndex {
|
||||||
marshalledContentIndex, mcErr := yaml.Marshal(&contentIndex)
|
marshalledContentIndex, mcErr := json.MarshalIndent(&contentIndex, "", " ")
|
||||||
if mcErr != nil {
|
if mcErr != nil {
|
||||||
return mcErr
|
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 {
|
if writeErr != nil {
|
||||||
return writeErr
|
return writeErr
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user