feat: random subtitle via external api

This commit is contained in:
zaaarf 2024-01-20 17:28:18 +01:00
parent a7b25ca5cc
commit 361d2c712e
No known key found for this signature in database
GPG key ID: 102E445F4C3F829B
2 changed files with 23 additions and 1 deletions

View file

@ -78,6 +78,12 @@ subtitle_suffixes = [
", random!"
]
# You can fetch the subtitles from an API instead, setting these two parameters:
# random_api = "api.url" # url of the API
# random_api_param = "name" # parameter within the JSON to look at for
# I recommend https://git.alemi.dev/mood/ for this, in that case "mood" would the random_api_param,
# and the url would be wherever you set the endpoint to be.
# Social icons, list here: https://github.com/rhazdon/hugo-theme-hello-friend-ng/blob/master/layouts/partials/svg.html
social_icons = [
{ name = "github", at = "https://github.com/zaaarf" },

View file

@ -17,7 +17,23 @@
{{ svg::draw_icons(icons=config.extra.home.social_icons) }}
{% endif %}
</div></div>
{% if config.extra.home.subtitle_suffixes %}
{% if config.extra.home.random_api and config.extra.home.random_api_param %}
<script>
async function fetchSubtitle() {
let element = document.getElementById("subtitle-rand")
try {
let res = await fetch("{{ config.extra.home.random_api | safe }}");
let doc = await res.json();
element.innerHTML = `${doc.{{ config.extra.home.random_api_param }}}`;
} catch (e) {
console.log(e);
element.textContent = ", seemingly incapable to configure nginx";
}
}
fetchSubtitle();
</script>
{% elif config.extra.home.subtitle_suffixes %}
<script> //random subtitle logic
const suffixes = [
{% for s in config.extra.home.subtitle_suffixes %}