tangled
alpha
login
or
join now
voigt.tngl.sh
/
hugo-digital-garden
0
fork
atom
wip
0
fork
atom
overview
issues
pulls
pipelines
add main
voigt.tngl.sh
2 months ago
474c2fcd
e9ce91e5
+127
4 changed files
expand all
collapse all
unified
split
go.mod
go.sum
main.go
option.go
+12
go.mod
reviewed
···
1
1
+
module github.com/voigt/hugo-digital-garden
2
2
+
3
3
+
go 1.25.0
4
4
+
5
5
+
require (
6
6
+
github.com/BurntSushi/toml v1.5.0 // indirect
7
7
+
github.com/google/uuid v1.6.0 // indirect
8
8
+
github.com/yuin/goldmark v1.7.13 // indirect
9
9
+
go.abhg.dev/goldmark/frontmatter v0.3.0 // indirect
10
10
+
go.abhg.dev/goldmark/wikilink v0.6.0 // indirect
11
11
+
gopkg.in/yaml.v3 v3.0.1 // indirect
12
12
+
)
+13
go.sum
reviewed
···
1
1
+
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
2
2
+
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
3
3
+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4
4
+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5
5
+
github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
6
6
+
github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
7
7
+
go.abhg.dev/goldmark/frontmatter v0.3.0 h1:ZOrMkeyyYzhlbenFNmOXyGFx1dFE8TgBWAgZfs9D5RA=
8
8
+
go.abhg.dev/goldmark/frontmatter v0.3.0/go.mod h1:W3KXvVveKKxU1FIFZ7fgFFQrlkcolnDcOVmu19cCO9U=
9
9
+
go.abhg.dev/goldmark/wikilink v0.6.0 h1:SKZANgMD7GMbaU0kBKTh52Ea9k3A3Y5ZifHoEPC1fuo=
10
10
+
go.abhg.dev/goldmark/wikilink v0.6.0/go.mod h1:Sfaovp00aAVJ5khqIeDTTgkIfZrcurmJGlbntCJUbJY=
11
11
+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12
12
+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
13
13
+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+95
main.go
reviewed
···
1
1
+
package main
2
2
+
3
3
+
import (
4
4
+
"fmt"
5
5
+
"os"
6
6
+
"path/filepath"
7
7
+
"time"
8
8
+
)
9
9
+
10
10
+
var o = Option{
11
11
+
ObsidianVaultDirectory: "/Users/c.voigt/tmp/kepano-obsidian-main",
12
12
+
HugoContentDirectory: "/Users/c.voigt/tmp/hugotest/content",
13
13
+
Debug: false,
14
14
+
}
15
15
+
16
16
+
func main() {
17
17
+
// o := Option{
18
18
+
// ObsidianVaultDirectory: "/Users/c.voigt/tmp/kepano-obsidian-main",
19
19
+
// HugoContentDirectory: "",
20
20
+
// Debug: false,
21
21
+
// }
22
22
+
23
23
+
// Get all Files in Obsidian Vault
24
24
+
obsidianVaultGraph, err := GetFilesFromObsidian(o.ObsidianVaultDirectory)
25
25
+
if err != nil {
26
26
+
fmt.Println(err)
27
27
+
return
28
28
+
}
29
29
+
30
30
+
b, err := obsidianVaultGraph.MarshalObsidianVaultGraph()
31
31
+
if err != nil {
32
32
+
fmt.Println(err)
33
33
+
return
34
34
+
}
35
35
+
36
36
+
fmt.Println(string(b))
37
37
+
// fmt.Printf("Files %d\n", obsidianVaultGraph.Nodes.Len())
38
38
+
}
39
39
+
40
40
+
func GetFilesFromObsidian(dir string) (ObsidianVaultGraph, error) {
41
41
+
g := InitObsidianVaultGraph()
42
42
+
43
43
+
// get all files form obsidian vault
44
44
+
_, err := ReadFilesRecursively(dir, &g)
45
45
+
if err != nil {
46
46
+
fmt.Println(err)
47
47
+
return ObsidianVaultGraph{}, err
48
48
+
}
49
49
+
50
50
+
return g, nil
51
51
+
}
52
52
+
53
53
+
func ReadFilesRecursively(dir string, graph *ObsidianVaultGraph) ([]string, error) {
54
54
+
entries, err := os.ReadDir(dir)
55
55
+
if err != nil {
56
56
+
return nil, err
57
57
+
}
58
58
+
59
59
+
var result []string
60
60
+
for _, entry := range entries {
61
61
+
if o.Debug {
62
62
+
fmt.Printf("%s... ", filepath.Join(dir, entry.Name()))
63
63
+
}
64
64
+
if entry.IsDir() {
65
65
+
subFiles, err := ReadFilesRecursively(filepath.Join(dir, entry.Name()), graph)
66
66
+
if err != nil {
67
67
+
return nil, err
68
68
+
}
69
69
+
result = append(result, subFiles...)
70
70
+
} else {
71
71
+
file := InitNewFile(entry.Name(), filepath.Join(dir, entry.Name()), o.HugoContentDirectory)
72
72
+
if file.Type == "Markdown" {
73
73
+
file.ReadObsidianFile()
74
74
+
75
75
+
// Extract all links from the file content
76
76
+
file.Links = extractLinks(file.RawContent)
77
77
+
78
78
+
d := file.HugoMarkdown.OwnerDocument().Meta()
79
79
+
_ = d
80
80
+
// Normalize links to match file paths (e.g., add ".md" extension if missing)
81
81
+
if len(file.Links) > 0 {
82
82
+
graph.Edges[file.ObsidianPath] = file.Links
83
83
+
}
84
84
+
}
85
85
+
graph.Nodes = append(graph.Nodes, file)
86
86
+
}
87
87
+
if o.Debug {
88
88
+
time.Sleep(100 * time.Millisecond)
89
89
+
fmt.Printf("done - (len: %d)\n", graph.Nodes.Len())
90
90
+
// fmt.Scanln()
91
91
+
}
92
92
+
}
93
93
+
94
94
+
return result, nil
95
95
+
}
+7
option.go
reviewed
···
1
1
+
package main
2
2
+
3
3
+
type Option struct {
4
4
+
ObsidianVaultDirectory string
5
5
+
HugoContentDirectory string
6
6
+
Debug bool
7
7
+
}