Browse Source

Add an API

master
bake 3 weeks ago
parent
commit
0accba924e

+ 7
- 1
config.toml View File

@@ -12,6 +12,7 @@ enableGitInfo = true

[outputs]
page = ["html", "json"]
section = ["html", "json"]

[menu]
[[menu.meta]]
@@ -19,8 +20,13 @@ enableGitInfo = true
name = "Start"
url = "/"
weight = 10
[[menu.meta]]
identifier = "api"
name = "API"
url = "/mate/index.json"
weight = 20
[[menu.meta]]
identifier = "git"
name = "Git"
url = "https://git.192k.pw/bake/fussel.space"
weight = 20
weight = 30

+ 3
- 0
content/_index.md View File

@@ -6,4 +6,7 @@ _fussel.space_ ist eine kleine Sammlung an Matehaltigen Eistees. Sie ist open
source, liegt auf einem [Gitea](https://git.192k.pw/bake/fussel.space)-Server
und als Mirror auf [GitHub](https://github.com/bake/fussel.space).

Metadaten zu den Maten, wie den Koffeingehalt oder Bilder, gibt es auch über
[eine kleine API](/mate/index.json).

Alles hier ist meine persönliche Meinung. Oder gelogen. Im Zweifelsfall gelogen.

+ 1
- 0
themes/fussel.theme/layouts/_default/baseof.json View File

@@ -0,0 +1 @@
{{ block "response" .}}{{ end }}

+ 7
- 0
themes/fussel.theme/layouts/mate/list.json View File

@@ -0,0 +1,7 @@
{{ define "response" }}
[
{{ range $index, $e := .Data.Pages }}
{{ if $index }}, {{ end }}{{ .Render "single" }}
{{ end }}
]
{{ end }}

+ 37
- 1
themes/fussel.theme/layouts/mate/single.json View File

@@ -1 +1,37 @@
{{ .Params | jsonify }}
{{ define "response" }}
{
"name": {{ .Title | jsonify }}
{{ if .Params.Caffeine }}
,"caffeine": {
"content": {{ .Params.Caffeine | jsonify }}
,"unit": "mg/100ml"
{{ if .Params.Caffeine_Source }}
,"source": {{ .Params.Caffeine_Source | jsonify}}
{{ end }}
}
{{ end }}
,"images": [
{{ range $i, $_ := .Params.Images }}
{{ if $i }}, {{ end }}
{
{{ with $.OutputFormats.Get "html" }}
"url": "{{ .RelPermalink | absURL }}{{ index $.Params.Images $i }}"
{{ end }}
,"caption": {{ index $.Params.Captions $i | markdownify | plainify | jsonify }}
}
{{ end }}
]
,"links": {
{{ with $.OutputFormats.Get "html" }}
"html": {{ .Permalink | jsonify }}
{{ end }}
{{ with $.OutputFormats.Get "json" }}
,"json": {{ .Permalink | jsonify }}
{{ end }}
{{ if .Params.Website }}
,"website": {{ .Params.Website | jsonify}}
{{ end }}
},
"lastmod": {{ .Lastmod | jsonify }}
}
{{ end }}

Loading…
Cancel
Save