Skip to content

Commit

Permalink
feat: dynamically fetch indices
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyzha0 committed Feb 16, 2022
1 parent 4587b13 commit fcd5d28
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2

- name: Build Link Index
uses: jackyzha0/hugo-obsidian@v2.7
uses: jackyzha0/hugo-obsidian@v2.8
with:
index: true
input: content
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ public
resources
.idea
content/.obsidian
data/linkIndex.yaml
data/contentIndex.yaml
static/linkIndex.json
static/contentIndex.json
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ help: ## Show all Makefile targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

serve: ## serve
hugo-obsidian -input=content -output=data -index -root=. && hugo server
hugo-obsidian -input=content -output=static -index -root=. && hugo server
2 changes: 1 addition & 1 deletion content/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 🪴 Quartz 3
title: 🪴 Quartz 3.1
---
Host your second brain and [digital garden](https://jzhao.xyz/posts/digital-gardening) for free. Quartz features
1. Extremely fast full-text search by pressing `/`
Expand Down
2 changes: 1 addition & 1 deletion data/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description:
Here is the page description. This is an example Quartz site that details installation,
setup, customization, and troubleshooting for Quartz itself.
page_title:
"🪴 Quartz 3"
"🪴 Quartz 3.1"
links:
- link_name: Twitter
link: https://twitter.com/_jzhao
Expand Down
5 changes: 3 additions & 2 deletions layouts/partials/backlinks.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ <h3>Backlinks</h3>
{{$url := urls.Parse .Site.BaseURL }}
{{$host := strings.TrimRight "/" $url.Path }}
{{$curPage := strings.TrimPrefix $host (strings.TrimRight "/" .Page.RelPermalink) }}
{{$inbound := index $.Site.Data.linkIndex.index.backlinks $curPage}}
{{$contentTable := $.Site.Data.contentIndex}}
{{$linkIndex := getJSON "/static/linkIndex.json"}}
{{$inbound := index $linkIndex.index.backlinks $curPage}}
{{$contentTable := getJSON "/static/contentIndex.json"}}
{{if $inbound}}
{{$cleanedInbound := apply (apply $inbound "index" "." "source") "replace" "." " " "-"}}
{{- range $cleanedInbound | uniq -}}
Expand Down
11 changes: 8 additions & 3 deletions layouts/partials/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ <h3>Interactive Graph</h3>
}
</style>
<script>
async function run() {
const { index, links, content } = await fetchData()
const curPage = {{ strings.TrimRight "/" .Page.Permalink }}.replace({{strings.TrimRight "/" .Site.BaseURL }}, "")
const pathColors = {{$.Site.Data.graphConfig.paths}}
let depth = {{$.Site.Data.graphConfig.depth}}
Expand Down Expand Up @@ -225,12 +227,15 @@ <h3>Interactive Graph</h3>
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
.attr("y2", d => d.target.y)
node
.attr("cx", d => d.x)
.attr("cy", d => d.y);
.attr("cy", d => d.y)
labels
.attr("x", d => d.x)
.attr("y", d => d.y);
.attr("y", d => d.y)
});
}

run()
</script>
23 changes: 19 additions & 4 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- CSS Stylesheets and Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Source+Sans+Pro:wght@400;600;700&family=Fira+Code:wght@400;700&display=swap" rel="stylesheet">
{{ $css := slice "base.scss" "darkmode.scss" "syntax.scss" "custom.scss"}}
{{$css := slice "base.scss" "darkmode.scss" "syntax.scss" "custom.scss"}}
{{range $css}}
{{$sass := resources.Get . | resources.ToCSS }}
{{with $sass | minify}}
Expand All @@ -26,9 +26,24 @@

<!-- Preload page vars -->
<script>
const content = {{$.Site.Data.contentIndex}}
const index = {{$.Site.Data.linkIndex.index}}
const links = {{$.Site.Data.linkIndex.links}}
const fetchData = async () => {
const promises = [
fetch("/linkIndex.json")
.then(data => data.json())
.then(data => ({
index: data.index,
links: data.links,
})),
fetch("/contentIndex.json")
.then(data => data.json()),
]
const [{index, links}, content] = await Promise.all(promises)
return ({
index,
links,
content,
})
}
</script>
</head>
{{ template "_internal/google_analytics.html" . }}
Expand Down
6 changes: 5 additions & 1 deletion layouts/partials/popover.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{if $.Site.Data.config.enableLinkPreview}}
<script>
async function run() {
const {content} = await fetchData()
function htmlToElement(html) {
const template = document.createElement('template')
html = html.trim()
Expand All @@ -11,7 +13,6 @@
document.addEventListener("DOMContentLoaded", () => {
[...document.getElementsByClassName("internal-link")]
.forEach(li => {
console.log(li.dataset.src.replace(pathRegex, ''))
const linkDest = content[li.dataset.src.replace(pathRegex, '')]
if (linkDest) {
const popoverElement = `<div class="popover">
Expand All @@ -29,5 +30,8 @@ <h3>${linkDest.title}</h3>
}
})
})
}

run()
</script>
{{end}}
Loading

0 comments on commit fcd5d28

Please sign in to comment.