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:
Stories have a 4 part structure that teaches us an essential lesson.
- Characters (are they like me)
- Conflict (what issue they faced)
- Struggle (what did they do)
- Resolution (did they solve it)
We _tell_ stories because it's the way we share
how to solve problems.
We _listen_ to stories because they're the best way to learn how somebody else solved a problem.
> Stories have a 4 part structure that teaches us an essential lesson.
>
> - Characters (are they like me)
> - Conflict (what issue they faced)
> - Struggle (what did they do)
> - Resolution (did they solve it)
>
> We _tell_ stories because it's the way we share how to solve problems.
> 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.

View file

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

View file

@ -1,81 +1,79 @@
{{ $path := .Page.Path }}
{{ $isbn := "" }}
{{ $key := "" }}
{{ $showCover := ne (.Get 1) false }}
{{- $path := .Page.Path -}}
{{- $isbn := "" -}}
{{- $key := "" -}}
{{- $showCover := ne (.Get 1) false -}}
{{ with .Get 0 }}
{{ if eq (len .) 13 }}
{{ $isbn = . }}
{{ else }}
{{ $key = . }}
{{ end }}
{{ end }}
{{- with .Get 0 -}}
{{- if eq (len .) 13 -}}
{{- $isbn = . -}}
{{- else -}}
{{- $key = . -}}
{{- 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 }}
{{ $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 $key -}}
{{- 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 -}}
{{ if $key }}
{{ 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 -}}
{{- 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 -}}
{{ $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 }}
{{ $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 }}
{{- $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) -}}
{{- $coverPath := replaceRE `(\.md)?$` (printf "/%s.jpg" $bookFilename) $path -}}
{{ with resources.GetRemote $coverURL }}
{{ with .Err }}
{{ else }}
{{ $cover = .Content | resources.FromString $coverPath }}
{{ end }}
{{ end }}
{{ end }}
{{- with resources.GetRemote $coverURL -}}
{{- with .Err -}}
{{- else -}}
{{- $cover = .Content | resources.FromString $coverPath -}}
{{- end -}}
{{- 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 }}
{{ else }}
{{ warnf "Failed to fetch Book data data from OpenLibrary: %s" $key }}
{{ 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 -}}
{{- else -}}
{{- warnf "Failed to fetch Book data data from OpenLibrary: %s" $key -}}
{{- end -}}
{{- end -}}