Added custom configs.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
- type: custom-api
|
||||
title: 💡 On This Day
|
||||
cache: 6h
|
||||
url: https://api.github.com/rate_limit
|
||||
template: |
|
||||
{{/* Top-level URL is a cheap dummy JSON; the real work is done inside the template via newRequest so we can compute today's date. Wikipedia's REST API requires a descriptive User-Agent per their policy (https://meta.wikimedia.org/wiki/User-Agent_policy) — an unset UA returns 403. */}}
|
||||
{{ $month := now | formatTime "01" }}
|
||||
{{ $day := now | formatTime "02" }}
|
||||
{{ $url := concat "https://en.wikipedia.org/api/rest_v1/feed/onthisday/events/" $month "/" $day }}
|
||||
{{
|
||||
$resp := newRequest $url
|
||||
| withHeader "Accept" "application/json"
|
||||
| withHeader "User-Agent" "glance-dashboard/1.0 (+https://github.com/glanceapp/glance)"
|
||||
| getResponse
|
||||
}}
|
||||
|
||||
{{ if ne $resp.Response.StatusCode 200 }}
|
||||
<p class="color-negative">Failed to load Wikipedia events ({{ $resp.Response.Status }})</p>
|
||||
{{ else }}
|
||||
{{ $events := $resp.JSON.Array "events" }}
|
||||
{{ if eq (len $events) 0 }}
|
||||
<p class="color-subdue">No events found for today.</p>
|
||||
{{ else }}
|
||||
<ul class="list list-gap-14 collapsible-container" data-collapse-after="5">
|
||||
{{ range $events }}
|
||||
{{ $year := .Int "year" }}
|
||||
{{ $text := .String "text" }}
|
||||
{{ $pages := .Array "pages" }}
|
||||
{{ $link := "" }}
|
||||
{{ if gt (len $pages) 0 }}
|
||||
{{ $firstPage := index $pages 0 }}
|
||||
{{ $link = $firstPage.String "content_urls.desktop.page" }}
|
||||
{{ end }}
|
||||
<li>
|
||||
<div class="flex items-baseline" style="gap: 0.6rem;">
|
||||
<span class="color-primary size-h4" style="flex: 0 0 auto; min-width: 3rem;">{{ $year }}</span>
|
||||
<span class="size-h5" style="flex: 1 1 auto;">
|
||||
{{ if ne $link "" }}
|
||||
<a href="{{ $link }}" target="_blank" rel="noreferrer" class="color-highlight">{{ $text }}</a>
|
||||
{{ else }}
|
||||
{{ $text }}
|
||||
{{ end }}
|
||||
</span>
|
||||
</div>
|
||||
</li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user