From 72eed38a3c077ae3fbf2eccac9c9c8e21369c5d1 Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Tue, 5 Mar 2024 17:54:56 +0000 Subject: [PATCH] Remove unnecessary spaces --- content/bookmarks/a-primer-on-dopamine.md | 19 ++- layouts/partials/book.html | 2 +- layouts/shortcodes/openlibrary.html | 142 +++++++++++----------- 3 files changed, 80 insertions(+), 83 deletions(-) diff --git a/content/bookmarks/a-primer-on-dopamine.md b/content/bookmarks/a-primer-on-dopamine.md index 4bd041c8..7ccb0da2 100644 --- a/content/bookmarks/a-primer-on-dopamine.md +++ b/content/bookmarks/a-primer-on-dopamine.md @@ -136,16 +136,15 @@ I’ve 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. I’m 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. diff --git a/layouts/partials/book.html b/layouts/partials/book.html index b17d31e6..3e66cafa 100644 --- a/layouts/partials/book.html +++ b/layouts/partials/book.html @@ -2,7 +2,7 @@ {{- $authors := . -}} {{- if and (ne $authors nil) (gt (len $authors) 0) -}} - {{ " by " }} + {{- " by " -}} {{- range $i, $a := $authors -}} {{- if and (ne $i 0) (eq (add $i 1) (len $authors)) -}}and {{ end -}} {{ $a.name }} diff --git a/layouts/shortcodes/openlibrary.html b/layouts/shortcodes/openlibrary.html index b76f3934..a82bd16e 100644 --- a/layouts/shortcodes/openlibrary.html +++ b/layouts/shortcodes/openlibrary.html @@ -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 -}}