mirror of
https://github.com/jackyzha0/hugo-obsidian.git
synced 2024-06-14 11:42:35 +03:00
fix parsing issues
This commit is contained in:
parent
5879c08972
commit
6155ce71dc
11
README.md
11
README.md
@ -1,12 +1,15 @@
|
|||||||
# Obsidian Link Scrapper
|
# Obsidian Link Scrapper
|
||||||
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 `.yml` file for easy consumption by [Hugo](https://gohugo.io/).
|
||||||
|
|
||||||
## Installation
|
## Example Usage (Binary)
|
||||||
`go install github.com/jackyzha0/hugo-obsidian`
|
|
||||||
|
|
||||||
### Example Usage
|
|
||||||
Read Markdown from the `/content` folder and place the resulting `linkIndex.yaml` into `/data`
|
Read Markdown from the `/content` folder and place the resulting `linkIndex.yaml` into `/data`
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
# Installation
|
||||||
|
go install github.com/jackyzha0/hugo-obsidian
|
||||||
|
|
||||||
|
# Run
|
||||||
hugo-obsidian -input=content -output=data
|
hugo-obsidian -input=content -output=data
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Example Usage (GitHub Action)
|
||||||
|
13
main.go
13
main.go
@ -28,6 +28,10 @@ func trim(source, prefix, suffix string) string {
|
|||||||
return strings.TrimPrefix(strings.TrimSuffix(source, suffix), prefix)
|
return strings.TrimPrefix(strings.TrimSuffix(source, suffix), prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hugoPathTrim(source string) string {
|
||||||
|
return strings.TrimSuffix(strings.TrimSuffix(source, "/index"), "_index")
|
||||||
|
}
|
||||||
|
|
||||||
// parse single file for links
|
// parse single file for links
|
||||||
func parse(dir, pathPrefix string) []Link {
|
func parse(dir, pathPrefix string) []Link {
|
||||||
// read file
|
// read file
|
||||||
@ -42,8 +46,8 @@ func parse(dir, pathPrefix string) []Link {
|
|||||||
for text, target := range md.GetAllLinks(string(bytes)) {
|
for text, target := range md.GetAllLinks(string(bytes)) {
|
||||||
fmt.Printf(" %s\n", trim(target, pathPrefix, ".md"))
|
fmt.Printf(" %s\n", trim(target, pathPrefix, ".md"))
|
||||||
links = append(links, Link{
|
links = append(links, Link{
|
||||||
Source: trim(dir, pathPrefix, ".md"),
|
Source: hugoPathTrim(trim(dir, pathPrefix, ".md")),
|
||||||
Target: target,
|
Target: strings.Split(target, "#")[0],
|
||||||
Text: text,
|
Text: text,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -95,8 +99,9 @@ func index(links []Link) (index Index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// backlink (only if internal)
|
// backlink (only if internal)
|
||||||
if val, ok := backlinkMap[l.Target]; ok {
|
|
||||||
val = append(val, bl)
|
if _, ok := backlinkMap[l.Target]; ok {
|
||||||
|
backlinkMap[l.Target] = append(backlinkMap[l.Target], bl)
|
||||||
} else {
|
} else {
|
||||||
backlinkMap[l.Target] = []Link{bl}
|
backlinkMap[l.Target] = []Link{bl}
|
||||||
}
|
}
|
||||||
|
7
partials/graph_partial.html
Normal file
7
partials/graph_partial.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
const links = [
|
||||||
|
{{- range $.Site.Data.linkIndex.links -}}
|
||||||
|
{}
|
||||||
|
{{- end -}}
|
||||||
|
]
|
||||||
|
</script>
|
0
partials/links_partial.html
Normal file
0
partials/links_partial.html
Normal file
Loading…
Reference in New Issue
Block a user