Skip to content

Instantly share code, notes, and snippets.

@kevindoran
Last active January 24, 2023 09:57
Show Gist options
  • Save kevindoran/d4e587b4e0beb0537b3057f7600f117b to your computer and use it in GitHub Desktop.
Save kevindoran/d4e587b4e0beb0537b3057f7600f117b to your computer and use it in GitHub Desktop.
Hugo single page template for Anki cards
{{ define "head" }}
<link rel="stylesheet" href="{{ "css/anki.css" | relURL }}">
<script>
function toggleCard() {
btn = document.getElementById("toggle-card-btn")
if(btn.textContent == "Show Answer") {
document.getElementsByClassName("anki-front")[0].style.display = "none";
document.getElementsByClassName("anki-back")[0].style.display = "block";
btn.textContent = "Hide Answer";
} else {
document.getElementsByClassName("anki-front")[0].style.display = "block";
document.getElementsByClassName("anki-back")[0].style.display = "none";
btn.textContent = "Show Answer";
}
}
</script>
{{ end }}
{{ define "main" }}
<main>
<article>
{{ partial "breadcrumbs.html" .}}
<button id="toggle-card-btn" onclick="toggleCard()">Show Answer</button>
<div class="anki-body nightMode">
{{ .Content }}
</div>
{{ with .Params.tags }}
<div>
<ul id="tags">
{{ range . }}
<li><a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a></li>
{{ end }}
</ul>
</div>
{{ end }}
<time>{{ .Date.Format "02.01.2006" }}</time>
</article>
</main>
<nav class="prev-next">
{{ if .PrevPage }}
<a class="prev-link" href="{{ .PrevPage.Permalink }}?ref=footer">« {{ .PrevPage.Title | truncate 30 "..."}}</a>
{{ else }}
<a />
{{ end }}
</div>
<div class="next-link">
{{ if .NextPage }}
<a class="next-link" href="{{ .NextPage.Permalink }}?ref=footer">{{ .NextPage.Title | truncate 30 "..." }} »</a>
{{ else }}
<a />
{{ end }}
</div>
</nav>
{{ end }}
@y1450
Copy link

y1450 commented Jan 24, 2023

Hi @kevindoran do you have repository or demo for publishing anki deck to hugo?

@kevindoran
Copy link
Author

Blog repo is at https://github.com/kevindoran/www, and the main Anki entry point is the script: https://github.com/kevindoran/www/blob/main/scripts/anki_gen.py

@y1450
Copy link

y1450 commented Jan 24, 2023

thanks both links redirect to page not found. Maybe it is a private repo?

@kevindoran
Copy link
Author

Sorry. Made it public now.

@y1450
Copy link

y1450 commented Jan 24, 2023

Thanks alot. I like your anki notes(decks). Maybe if you can add a link of your blog to profile info, It would be easy to locate the blog.

@kevindoran
Copy link
Author

Yea, I can add it. The Anki root ended up here: https://blog.kdoran.com/anki/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment