mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 01:35:56 +01:00
Fix deprecated getJSON usage
This commit is contained in:
parent
161c09e994
commit
24f13be010
2 changed files with 53 additions and 31 deletions
|
@ -72,7 +72,3 @@
|
|||
{{ partial "extra-head.html" . }}
|
||||
{{- end }}
|
||||
|
||||
<!-- Google Analytics internal template -->
|
||||
{{- if .Site.GoogleAnalytics }}
|
||||
{{ template "_internal/google_analytics.html" . }}
|
||||
{{- end}}
|
||||
|
|
|
@ -14,39 +14,65 @@
|
|||
|
||||
{{ if not $key }}
|
||||
{{ $query := (dict "type" "/type/edition" "isbn_13" $isbn) | jsonify }}
|
||||
{{ $thing := getJSON (printf "https://openlibrary.org/api/things?query=%s" ($query)) }}
|
||||
{{ if and (eq $thing.status "ok") (ge (len $thing.result) 1) }}
|
||||
{{ $key = index $thing.result 0 }}
|
||||
{{ with resources.GetRemote (printf "https://openlibrary.org/api/things?query=%s" ($query)) }}
|
||||
{{ with .Err }}
|
||||
{{ errorf "Error grabbing Thing from OpenLibrary: %v" . }}
|
||||
{{ else }}
|
||||
{{ $thing := .Content | transform.Unmarshal }}
|
||||
{{ if and (eq $thing.status "ok") (ge (len $thing.result) 1) }}
|
||||
{{ $key = index $thing.result 0 }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ warnf "Failed to fetch ISBN data from OpenLibrary: %s" $isbn }}
|
||||
{{ end }}
|
||||
{{ end}}
|
||||
|
||||
{{ if $key }}
|
||||
{{ $bookObj := getJSON (printf "https://openlibrary.org/api/get?key=%s" $key) }}
|
||||
{{ if eq $bookObj.status "ok" }}
|
||||
{{ $isbn = index $bookObj.result.isbn_13 0 }}
|
||||
{{ with resources.GetRemote (printf "https://openlibrary.org/api/get?key=%s" $key) }}
|
||||
{{ with .Err }}
|
||||
{{ errorf "Error grabbing Book data from OpenLibrary: %v" . }}
|
||||
{{ else }}
|
||||
{{ $bookObj := .Content | transform.Unmarshal }}
|
||||
{{ if eq $bookObj.status "ok" }}
|
||||
{{ $isbn = index $bookObj.result.isbn_13 0 }}
|
||||
|
||||
{{ $authors := slice }}
|
||||
{{ range $bookObj.result.authors }}
|
||||
{{ $authorObj := getJSON (printf "https://openlibrary.org/api/get?key=%s" .key) }}
|
||||
{{ if eq $authorObj.status "ok" }}
|
||||
{{ $authors = $authors | append (dict "name" $authorObj.result.name "url" (printf "https://openlibrary.org%s" $authorObj.result.key)) }}
|
||||
{{ $authors := slice }}
|
||||
{{ range $bookObj.result.authors }}
|
||||
{{ with resources.GetRemote (printf "https://openlibrary.org/api/get?key=%s" .key) }}
|
||||
{{ with .Err }}
|
||||
{{ errorf "Error grabbing Author data from OpenLibrary: %v" . }}
|
||||
{{ else }}
|
||||
{{ $authorObj := .Content | transform.Unmarshal }}
|
||||
{{ if eq $authorObj.status "ok" }}
|
||||
{{ $authors = $authors | append (dict "name" $authorObj.result.name "url" (printf "https://openlibrary.org%s" $authorObj.result.key)) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ warnf "Failed to fetch Author data from OpenLibrary: %s" .key }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ $coverURL := (printf "https://covers.openlibrary.org/b/isbn/%s-M.jpg" $isbn)}}
|
||||
{{ if not $isbn }}
|
||||
{{ $coverURL = printf "https://covers.openlibrary.org/b/id/%.0f-M.jpg" (index $bookObj.result.covers 0) }}
|
||||
{{ end }}
|
||||
|
||||
{{- $bookFilename := replaceRE `[^a-z]+` "-" (lower $bookObj.result.title) -}}
|
||||
{{- $coverPath := replaceRE `(\.md)?$` (printf "/%s.jpg" $bookFilename) $path -}}
|
||||
{{ $cover := "" }}
|
||||
{{ with resources.GetRemote $coverURL }}
|
||||
{{ with .Err }}
|
||||
{{ else }}
|
||||
{{ $cover = .Content | resources.FromString $coverPath }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ $book := dict "title" $bookObj.result.title "authors" $authors "url" (printf "https://openlibrary.org%s" $key) "cover" $cover }}
|
||||
{{ partial "book.html" $book }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ $coverURL := (printf "https://covers.openlibrary.org/b/isbn/%s-M.jpg" $isbn)}}
|
||||
{{ if not $isbn }}
|
||||
{{ $coverURL = printf "https://covers.openlibrary.org/b/id/%.0f-M.jpg" (index $bookObj.result.covers 0) }}
|
||||
{{ end }}
|
||||
|
||||
{{ $cover := "" }}
|
||||
{{ with resources.GetRemote $coverURL }}
|
||||
{{ with .Err }}
|
||||
{{ else }}
|
||||
{{ $cover = .Content | resources.FromString (replaceRE `\.md$` ".jpg" $path) }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ $book := dict "title" $bookObj.result.title "authors" $authors "url" (printf "https://openlibrary.org%s" $key) "cover" $cover }}
|
||||
{{ partial "book.html" $book }}
|
||||
{{ else }}
|
||||
{{ warnf "Failed to fetch Book data data from OpenLibrary: %s" $key }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in a new issue