diff --git a/contentIndex.yaml b/contentIndex.yaml deleted file mode 100644 index b7ebcd8..0000000 --- a/contentIndex.yaml +++ /dev/null @@ -1,45 +0,0 @@ -# THIS FILE WAS GENERATED USING github.com/jackyzha0/hugo-obsidian -# DO NOT EDIT -README: - title: Untitled Page - content: | - # Obsidian Link Scrapper - 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) - - ## 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/). - ### 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` - - ```shell - # Installation - go install github.com/jackyzha0/hugo-obsidian - - # Run - hugo-obsidian -input=content -output=data -index=true - ``` - - ### Example Usage (GitHub Action) - - Add 'Build Link Index' as a build step in your workflow file (e.g. `.github/workflows/deploy.yaml`) - ```yaml - ... - - jobs: - deploy: - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - name: Build Link Index - uses: jackyzha0/hugo-obsidian@v2.1 - with: - input: content # input folder - output: data # output folder - index: true # whether to index content - ... - ``` diff --git a/linkIndex.yaml b/linkIndex.yaml index 5fc0945..1bfc6cc 100644 --- a/linkIndex.yaml +++ b/linkIndex.yaml @@ -1,6 +1,232 @@ # THIS FILE WAS GENERATED USING github.com/jackyzha0/hugo-obsidian # DO NOT EDIT index: - links: {} - backlinks: {} -links: [] + links: + /: + - source: / + target: /notes/setup + text: Setup your own digital garden using Quartz + - source: / + target: /moc/showcase + text: community digital gardens + - source: / + target: /notes/philosophy + text: why I made Quartz + - source: / + target: /notes + text: All Notes + - source: / + target: /tags/setup + text: Setup-related Notes + - source: / + target: /notes/troubleshooting + text: Troubleshooting and FAQ + /notes/Obsidian: + - source: /notes/Obsidian + target: /notes/setup + text: setup + /notes/config: + - source: /notes/config + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + /notes/editing: + - source: /notes/editing + target: /notes/ignore-notes + text: Excluding pages from being published + - source: /notes/editing + target: /notes/preview-changes + text: Preview Quartz Changes + - source: /notes/editing + target: /notes/hosting + text: Hosting Quartz online! + - source: /notes/editing + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + /notes/hosting: + - source: /notes/hosting + target: /notes/config + text: Customizing Quartz + - source: /notes/hosting + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + /notes/setup: + - source: /notes/setup + target: /notes/editing + text: Editing Notes in Quartz + - source: /notes/setup + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + /notes/troubleshooting: + - source: /notes/troubleshooting + target: /notes/ignore-notes + text: excluding pages from being published + - source: /notes/troubleshooting + target: /notes/hosting + text: hosting + - source: /notes/troubleshooting + target: /notes/Obsidian + text: Obsidian + - source: /notes/troubleshooting + target: /notes/editing + text: the 'how to edit' guide + - source: /notes/troubleshooting + target: /notes/hosting + text: the hosting guide + - source: /notes/troubleshooting + target: /notes/config + text: customization guide + - source: /notes/troubleshooting + target: /notes/editing + text: local editing + backlinks: + /moc/showcase: + - source: / + target: /moc/showcase + text: community digital gardens + /notes: + - source: / + target: /notes + text: All Notes + /notes/Obsidian: + - source: /notes/troubleshooting + target: /notes/Obsidian + text: Obsidian + /notes/config: + - source: /notes/hosting + target: /notes/config + text: Customizing Quartz + - source: /notes/troubleshooting + target: /notes/config + text: customization guide + /notes/editing: + - source: /notes/setup + target: /notes/editing + text: Editing Notes in Quartz + - source: /notes/troubleshooting + target: /notes/editing + text: the 'how to edit' guide + - source: /notes/troubleshooting + target: /notes/editing + text: local editing + /notes/hosting: + - source: /notes/editing + target: /notes/hosting + text: Hosting Quartz online! + - source: /notes/troubleshooting + target: /notes/hosting + text: hosting + - source: /notes/troubleshooting + target: /notes/hosting + text: the hosting guide + /notes/ignore-notes: + - source: /notes/editing + target: /notes/ignore-notes + text: Excluding pages from being published + - source: /notes/troubleshooting + target: /notes/ignore-notes + text: excluding pages from being published + /notes/philosophy: + - source: / + target: /notes/philosophy + text: why I made Quartz + /notes/preview-changes: + - source: /notes/editing + target: /notes/preview-changes + text: Preview Quartz Changes + /notes/setup: + - source: / + target: /notes/setup + text: Setup your own digital garden using Quartz + - source: /notes/Obsidian + target: /notes/setup + text: setup + /notes/troubleshooting: + - source: / + target: /notes/troubleshooting + text: Troubleshooting and FAQ + - source: /notes/config + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + - source: /notes/editing + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + - source: /notes/hosting + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + - source: /notes/setup + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + /tags/setup: + - source: / + target: /tags/setup + text: Setup-related Notes +links: + - source: / + target: /notes/setup + text: Setup your own digital garden using Quartz + - source: / + target: /moc/showcase + text: community digital gardens + - source: / + target: /notes/philosophy + text: why I made Quartz + - source: / + target: /notes + text: All Notes + - source: / + target: /tags/setup + text: Setup-related Notes + - source: / + target: /notes/troubleshooting + text: Troubleshooting and FAQ + - source: /notes/Obsidian + target: /notes/setup + text: setup + - source: /notes/config + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + - source: /notes/editing + target: /notes/ignore-notes + text: Excluding pages from being published + - source: /notes/editing + target: /notes/preview-changes + text: Preview Quartz Changes + - source: /notes/editing + target: /notes/hosting + text: Hosting Quartz online! + - source: /notes/editing + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + - source: /notes/hosting + target: /notes/config + text: Customizing Quartz + - source: /notes/hosting + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + - source: /notes/setup + target: /notes/editing + text: Editing Notes in Quartz + - source: /notes/setup + target: /notes/troubleshooting + text: FAQ and Troubleshooting guide + - source: /notes/troubleshooting + target: /notes/ignore-notes + text: excluding pages from being published + - source: /notes/troubleshooting + target: /notes/hosting + text: hosting + - source: /notes/troubleshooting + target: /notes/Obsidian + text: Obsidian + - source: /notes/troubleshooting + target: /notes/editing + text: the 'how to edit' guide + - source: /notes/troubleshooting + target: /notes/hosting + text: the hosting guide + - source: /notes/troubleshooting + target: /notes/config + text: customization guide + - source: /notes/troubleshooting + target: /notes/editing + text: local editing diff --git a/main.go b/main.go index f74f9e7..617ecaa 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,12 @@ package main import ( "flag" + "fmt" + "github.com/BurntSushi/toml" wikilink "github.com/abhinav/goldmark-wikilink" "github.com/yuin/goldmark" + "io/ioutil" + "path/filepath" ) var md goldmark.Markdown @@ -33,20 +37,43 @@ type Content struct { type ContentIndex = map[string]Content -type IgnoredFiles struct { - +type ConfigTOML struct { + IgnoredFiles []string `toml:"ignoreFiles"` } -func getIgnoredFiles() { +func getIgnoredFiles(base string) (res map[string]struct{}) { + res = make(map[string]struct{}) + source, err := ioutil.ReadFile(base + "/config.toml") + if err != nil { + return res + } + + var config ConfigTOML + if _, err := toml.Decode(string(source), &config); err != nil { + return res + } + + for _, glb := range config.IgnoredFiles { + matches, _ := filepath.Glob(base + glb) + for _, match := range matches { + res[match] = struct{}{} + } + } + + fmt.Printf("%v\n", res) + return res } func main() { in := flag.String("input", ".", "Input Directory") out := flag.String("output", ".", "Output Directory") + root := flag.String("root", "..", "Root Directory (for config parsing)") index := flag.Bool("index", false, "Whether to index the content") flag.Parse() - l, i := walk(*in, ".md", *index) + + ignoreBlobs := getIgnoredFiles(*root) + l, i := walk(*in, ".md", *index, ignoreBlobs) f := filter(l) err := write(f, i, *index, *out) if err != nil { diff --git a/walk.go b/walk.go index 96cb96f..c03232c 100644 --- a/walk.go +++ b/walk.go @@ -10,7 +10,7 @@ import ( ) // recursively walk directory and return all files with given extension -func walk(root, ext string, index bool) (res []Link, i ContentIndex) { +func walk(root, ext string, index bool, ignorePaths map[string]struct{}) (res []Link, i ContentIndex) { fmt.Printf("Scraping %s\n", root) i = make(ContentIndex) @@ -22,7 +22,9 @@ func walk(root, ext string, index bool) (res []Link, i ContentIndex) { if e != nil { return e } - if filepath.Ext(d.Name()) == ext { + if _, ignored := ignorePaths[s]; ignored { + fmt.Printf("[Ignored] %s\n", d.Name()) + } else if filepath.Ext(d.Name()) == ext { res = append(res, parse(s, root)...) if index { text := getText(s)