Remove unnecessary spaces

This commit is contained in:
JP Hastings-Spital 2024-03-05 17:54:56 +00:00
parent 679aa7890f
commit 72eed38a3c
3 changed files with 80 additions and 83 deletions

View file

@ -136,16 +136,15 @@ Ive been (ha!) pleasantly surprised by how this article pulls lots of differe
From the associated tweet: From the associated tweet:
Stories have a 4 part structure that teaches us an essential lesson. > Stories have a 4 part structure that teaches us an essential lesson.
>
- Characters (are they like me) > - Characters (are they like me)
- Conflict (what issue they faced) > - Conflict (what issue they faced)
- Struggle (what did they do) > - Struggle (what did they do)
- Resolution (did they solve it) > - Resolution (did they solve it)
>
We _tell_ stories because it's the way we share > We _tell_ stories because it's the way we share how to solve problems.
how to solve problems. > We _listen_ to stories because they're the best way to learn how somebody else solved a problem.
We _listen_ to stories because they're the best way to learn how somebody else solved a problem.
Im not sure I agree that this is _all_ that stories are, but to the extent that it can be fun and engaging to connect with a story, I think these are the angles that make sense. Im not sure I agree that this is _all_ that stories are, but to the extent that it can be fun and engaging to connect with a story, I think these are the angles that make sense.

View file

@ -2,7 +2,7 @@
{{- $authors := . -}} {{- $authors := . -}}
{{- if and (ne $authors nil) (gt (len $authors) 0) -}} {{- if and (ne $authors nil) (gt (len $authors) 0) -}}
<span class="authors list"> <span class="authors list">
{{ " by " }} {{- " by " -}}
{{- range $i, $a := $authors -}} {{- range $i, $a := $authors -}}
{{- if and (ne $i 0) (eq (add $i 1) (len $authors)) -}}and {{ end -}} {{- if and (ne $i 0) (eq (add $i 1) (len $authors)) -}}and {{ end -}}
<a href="{{ $a.url }}" target="_blank">{{ $a.name }}</a> <a href="{{ $a.url }}" target="_blank">{{ $a.name }}</a>

View file

@ -1,81 +1,79 @@
{{ $path := .Page.Path }} {{- $path := .Page.Path -}}
{{ $isbn := "" }} {{- $isbn := "" -}}
{{ $key := "" }} {{- $key := "" -}}
{{ $showCover := ne (.Get 1) false }} {{- $showCover := ne (.Get 1) false -}}
{{ with .Get 0 }} {{- with .Get 0 -}}
{{ if eq (len .) 13 }} {{- if eq (len .) 13 -}}
{{ $isbn = . }} {{- $isbn = . -}}
{{ else }} {{- else -}}
{{ $key = . }} {{- $key = . -}}
{{ end }} {{- end -}}
{{ end }} {{- end -}}
{{ $isbn := .Get 0 }} {{- if not $key -}}
{{- $query := (dict "type" "/type/edition" "isbn_13" $isbn) | jsonify -}}
{{- 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 not $key }} {{- if $key -}}
{{ $query := (dict "type" "/type/edition" "isbn_13" $isbn) | jsonify }} {{- with resources.GetRemote (printf "https://openlibrary.org/api/get?key=%s" $key) -}}
{{ with resources.GetRemote (printf "https://openlibrary.org/api/things?query=%s" ($query)) }} {{- with .Err -}}
{{ with .Err }} {{- errorf "Error grabbing Book data from OpenLibrary: %v" . -}}
{{ errorf "Error grabbing Thing from OpenLibrary: %v" . }} {{- else -}}
{{ else }} {{- $bookObj := .Content | transform.Unmarshal -}}
{{ $thing := .Content | transform.Unmarshal }} {{- if eq $bookObj.status "ok" -}}
{{ if and (eq $thing.status "ok") (ge (len $thing.result) 1) }} {{- $isbn = index $bookObj.result.isbn_13 0 -}}
{{ $key = index $thing.result 0 }}
{{ end }}
{{ end }}
{{ else }}
{{ warnf "Failed to fetch ISBN data from OpenLibrary: %s" $isbn }}
{{ end }}
{{ end}}
{{ if $key }} {{- $authors := slice -}}
{{ with resources.GetRemote (printf "https://openlibrary.org/api/get?key=%s" $key) }} {{- range $bookObj.result.authors -}}
{{ with .Err }} {{- with resources.GetRemote (printf "https://openlibrary.org/api/get?key=%s" .key) -}}
{{ errorf "Error grabbing Book data from OpenLibrary: %v" . }} {{- with .Err -}}
{{ else }} {{- errorf "Error grabbing Author data from OpenLibrary: %v" . -}}
{{ $bookObj := .Content | transform.Unmarshal }} {{- else -}}
{{ if eq $bookObj.status "ok" }} {{- $authorObj := .Content | transform.Unmarshal -}}
{{ $isbn = index $bookObj.result.isbn_13 0 }} {{- 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 -}}
{{ $authors := slice }} {{- $cover := "" -}}
{{ range $bookObj.result.authors }} {{- if $showCover -}}
{{ with resources.GetRemote (printf "https://openlibrary.org/api/get?key=%s" .key) }} {{- $coverURL := (printf "https://covers.openlibrary.org/b/isbn/%s-M.jpg" $isbn) -}}
{{ with .Err }} {{- if not $isbn -}}
{{ errorf "Error grabbing Author data from OpenLibrary: %v" . }} {{- $coverURL = printf "https://covers.openlibrary.org/b/id/%.0f-M.jpg" (index $bookObj.result.covers 0) -}}
{{ else }} {{- end -}}
{{ $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 }}
{{ $cover := "" }}
{{ if $showCover }}
{{ $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) -}} {{- $bookFilename := replaceRE `[^a-z]+` "-" (lower $bookObj.result.title) -}}
{{- $coverPath := replaceRE `(\.md)?$` (printf "/%s.jpg" $bookFilename) $path -}} {{- $coverPath := replaceRE `(\.md)?$` (printf "/%s.jpg" $bookFilename) $path -}}
{{ with resources.GetRemote $coverURL }} {{- with resources.GetRemote $coverURL -}}
{{ with .Err }} {{- with .Err -}}
{{ else }} {{- else -}}
{{ $cover = .Content | resources.FromString $coverPath }} {{- $cover = .Content | resources.FromString $coverPath -}}
{{ end }} {{- end -}}
{{ end }} {{- end -}}
{{ end }} {{- end -}}
{{ $book := dict "title" $bookObj.result.title "authors" $authors "url" (printf "https://openlibrary.org%s" $key) "cover" $cover }} {{- $book := dict "title" $bookObj.result.title "authors" $authors "url" (printf "https://openlibrary.org%s" $key) "cover" $cover -}}
{{ partial "book.html" $book }} {{- partial "book.html" $book -}}
{{ end }} {{- end -}}
{{ end }} {{- end -}}
{{ else }} {{- else -}}
{{ warnf "Failed to fetch Book data data from OpenLibrary: %s" $key }} {{- warnf "Failed to fetch Book data data from OpenLibrary: %s" $key -}}
{{ end }} {{- end -}}
{{ end }} {{- end -}}