mirror of
https://github.com/jackyzha0/hugo-obsidian.git
synced 2024-06-14 11:42:35 +03:00
basic dir walking + link parsing
This commit is contained in:
commit
68f688bbfe
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea
|
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2021 jackyzha0
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module github.com/jackyzha0/hugo-obsidian
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require github.com/nikitavoloboev/markdown-parser v0.0.0-20200626055436-f545e8dd85d3 // indirect
|
21
go.sum
Normal file
21
go.sum
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/golang-commonmark/html v0.0.0-20180910111043-7d7c804e1d46 h1:FeNEDxIy7XouGTJKiJ9Ze5vUbcAIW/FRhQbtKBNmEz8=
|
||||||
|
github.com/golang-commonmark/html v0.0.0-20180910111043-7d7c804e1d46/go.mod h1:LVbxopYhspqklDpfaS/qDc6HhWwkpF1ptTj3vMFRoSQ=
|
||||||
|
github.com/golang-commonmark/linkify v0.0.0-20180910111149-f05efb453a0e h1:TkuRzcq232K5ytXtQ+BPicsjYWZgt/lS6gJ5HqcUifQ=
|
||||||
|
github.com/golang-commonmark/linkify v0.0.0-20180910111149-f05efb453a0e/go.mod h1:LeGY+WmPag1dlC0xKy+xYXommuQLX0O9gGXOP8SdBmY=
|
||||||
|
github.com/golang-commonmark/markdown v0.0.0-20180910011815-a8f139058164 h1:YaQaotRjMcVth1VzHUEQlD2oeyQAglA7CXdxp9QLvKM=
|
||||||
|
github.com/golang-commonmark/markdown v0.0.0-20180910011815-a8f139058164/go.mod h1:TRHkBtRpQJqTtJnCqhNU5oPkZw5pMr8Ac6DHndXYd5k=
|
||||||
|
github.com/golang-commonmark/mdurl v0.0.0-20180910110917-8d018c6567d6 h1:XkgfhPs5AotQfcu3EfDEjyAUx91KdtjrxHXYGnZJhoU=
|
||||||
|
github.com/golang-commonmark/mdurl v0.0.0-20180910110917-8d018c6567d6/go.mod h1:J66ZGl/dC2mj4ElzGfrLUq0N90HvQoUbrYgYNJUjuMs=
|
||||||
|
github.com/golang-commonmark/puny v0.0.0-20180910110745-050be392d8b8 h1:DUgQdQmDg4sk4SfNR+qOkXcopGz36BL02vp/V7WbPQI=
|
||||||
|
github.com/golang-commonmark/puny v0.0.0-20180910110745-050be392d8b8/go.mod h1:/8a6mcbf/Hwg6MjnHHp5vqCWw0Bsves9HLPObHAj7XA=
|
||||||
|
github.com/gomarkdown/markdown v0.0.0-20210514010506-3b9f47219fe7 h1:oKYOfNR7Hp6XpZ4JqolL5u642Js5Z0n7psPVl+S5heo=
|
||||||
|
github.com/gomarkdown/markdown v0.0.0-20210514010506-3b9f47219fe7/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU=
|
||||||
|
github.com/nikitavoloboev/markdown-parser v0.0.0-20200626055436-f545e8dd85d3 h1:68qdIIXf2kCV7+LlIM78OtcdKh3TXO00nOqraFor+VI=
|
||||||
|
github.com/nikitavoloboev/markdown-parser v0.0.0-20200626055436-f545e8dd85d3/go.mod h1:cL/O6Dew5Lsfksx+WljXgEf4gZsRjBXSjI7SuibGcEY=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
52
main.go
Normal file
52
main.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
md "github.com/nikitavoloboev/markdown-parser"
|
||||||
|
"io/fs"
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Link struct {
|
||||||
|
Source string
|
||||||
|
Target string
|
||||||
|
Text string
|
||||||
|
}
|
||||||
|
|
||||||
|
func parse(dir string) []Link {
|
||||||
|
// read file
|
||||||
|
bytes, err := ioutil.ReadFile(dir)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse md
|
||||||
|
var links []Link
|
||||||
|
fmt.Printf("in %s \n", dir)
|
||||||
|
for text, target := range md.GetAllLinks(string(bytes)) {
|
||||||
|
fmt.Printf("found link: %s -> %s \n", text, target)
|
||||||
|
links = append(links, Link{
|
||||||
|
Source: dir,
|
||||||
|
Target: target,
|
||||||
|
Text: text,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return links
|
||||||
|
}
|
||||||
|
|
||||||
|
func find(root, ext string) {
|
||||||
|
filepath.WalkDir(root, func(s string, d fs.DirEntry, e error) error {
|
||||||
|
if e != nil {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
if filepath.Ext(d.Name()) == ext {
|
||||||
|
parse(s)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
find("../www/content", ".md")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user