Skip to content

Commit

Permalink
Merge pull request #47 from blackfyre/artwork-search
Browse files Browse the repository at this point in the history
Artwork search
  • Loading branch information
blackfyre authored Oct 30, 2023
2 parents 4be09e6 + 876e05d commit 2edc855
Show file tree
Hide file tree
Showing 37 changed files with 964 additions and 159 deletions.
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}",
"args": [
"serve"
]
}
]
}
33 changes: 33 additions & 0 deletions assets/internals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package assets
import (
"bytes"
"embed"
"errors"
"html/template"
"log"
"strings"

"blackfyre.ninja/wga/utils"
"github.com/pocketbase/pocketbase/apis"
Expand All @@ -13,6 +15,13 @@ import (
//go:embed "reference/*" "views/*"
var InternalFiles embed.FS

type Renderable struct {
IsHtmx bool
Page string
Block string
Data map[string]any
}

// renderPage renders the given template with the provided data and returns the resulting HTML string.
// The template is parsed from the views directory using the provided template name and the layout.html file.
// If the template cannot be parsed or there is an error rendering it, an error is returned.
Expand Down Expand Up @@ -83,3 +92,27 @@ func renderHtml(patterns []string, name string, data map[string]any) (string, er

return html.String(), nil
}

// Render renders a Renderable object and returns the resulting HTML string.
// If the Renderable object is marked as htmx, it renders the block using RenderBlock.
// Otherwise, it renders the page using RenderPage.
func Render(r Renderable) (string, error) {

if r.IsHtmx {
return RenderBlock(r.Block, r.Data)
}

page := ""

if r.Page != "" {
page = r.Page
} else {
page = strings.Split(r.Block, ":")[0]
}

if page == "" {
return "", errors.New("Renderable " + page + " not found")
}

return RenderPage(page, r.Data)
}
2 changes: 1 addition & 1 deletion assets/reference/artworks_stage_2_0.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/reference/artworks_stage_2_13217.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/reference/artworks_stage_2_26434.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/reference/artworks_stage_2_39651.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions assets/views/pages/artist.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h1 class="title is-size-1">

<div class="columns is-multiline works-listing" data-viewer>
{{range .Works}}
{{ block "artist:work" .}}
<div class="column is-one-third-tablet is-one-quarter-desktop">
<section class="card is-art-card">
<div class="card-image">
Expand Down Expand Up @@ -73,6 +74,7 @@ <h3 class="title is-size-3">{{ .Title}}</h3>
</script>
</section>
</div>
{{end}}
{{ else }}

{{end}}
Expand Down
8 changes: 3 additions & 5 deletions assets/views/pages/contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
{{block "contributors:content" .}}
<section class="section">
<div class="container">
<div class="box">
<h1 class="title is-size-1">
Code Contributors
</h1>
</div>
<h1 class="title is-size-1">
Code Contributors
</h1>
<div class="columns is-mobile">
{{range .Contributors}}
<div class="column is-half-mobile is-one-quarter-desktop">
Expand Down
130 changes: 130 additions & 0 deletions assets/views/pages/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{{define "title"}}
Artwork search - Web Gallery of Art
{{end}}

{{define "body"}}
{{block "search:content" .}}
<section class="section">
<h1 class="title is-size-1">Artwork search</h1>
<div class="columns">
<div class="column is-one-quarter">
<div class="box">
<form action="/search" hx-get="/search" hx-target="#artwork-search-results">
<div class="field">
<label class="label">Artforms</label>
<div class="control">
<div class="select">
<select name="art_form">
{{range $k, $v := .ArtFormOptions}}
<option value="{{$k}}" {{if eq $.ActiveFilterValues.ArtFormString
$k}}selected{{end}}>{{$v}}</option>
{{end}}
</select>
</div>
</div>
</div>
<div class="field">
<label class="label">Art types</label>
<div class="control">
<div class="select">
<select name="art_type">
{{range $k, $v := .ArtTypeOptions}}
<option value="{{$k}}" {{if eq $.ActiveFilterValues.ArtTypeString
$k}}selected{{end}}>{{$v}}</option>
{{end}}
</select>
</div>
</div>
</div>
<div class="field">
<label class="label">Art shool</label>
<div class="control">
<div class="select">
<select name="art_school">
{{range $k, $v := .ArtSchoolOptions}}
<option value="{{$k}}" {{if eq $.ActiveFilterValues.SchoolString
$k}}selected{{end}}>{{$v}}</option>
{{end}}
</select>
</div>
</div>
</div>
<div class="field">
<label class="label">Title</label>
<p class="control">
<input class="input" type="search" name="title" placeholder="Artwork title"
value="{{.ActiveFilterValues.Title}}">
</p>
</div>
<div class="field">
<label class="label">Artist</label>
<p class="control">
<input class="input" list="artist_list" type="search" name="artist"
placeholder="Artist name" value="{{.ActiveFilterValues.ArtistString}}">
<datalist id="artist_list">
{{range .ArtistNameList}}
<option value="{{.}}"></option>
{{end}}
</datalist>
</p>
</div>

<div class="field"><button type="submit" class="button is-primary">Search</button></div>
</form>
</div>
</div>
<div class="column" id="artwork-search-results">
{{block "search:search-results" .}}
<div class="columns is-multiline works-listing" data-viewer>
{{range .Artworks}}
<div class="column is-one-third-tablet is-one-quarter-desktop">
<section class="card is-art-card">
<div class="card-image">
<figure class="image is-4by3 hidden-caption">
<picture>
<source media="(max-width: 768px)" srcset="{{.Thumb}}">
<source media="(min-width: 769px)" srcset="{{.Thumb}}">
<source media="(min-width: 1024px)" srcset="{{.Thumb}}">
<img src="{{.Image}}" alt="{{ .Title}}" loading="lazy">
</picture>
<figcaption>{{.Title}} - {{ .Technique }}</figcaption>
</figure>
</div>
<div class="card-content">
<div>
<h3 class="title is-size-3">{{ .Title}}</h3>
<p class="subtitle">{{ .Technique }}</p>
<div class="line-clamp-3 content">
{{safeHTML .Comment}}
</div>
</div>
</div>
<footer class="card-footer">
<a class="card-footer-item" href="/artists/{{.ArtistSlug}}/{{.Id}}"
hx-get="/artists/{{.ArtistSlug}}/{{.Id}}" hx-target="#mc-area">Learn More</a>
<a href="#" hx-on="click: document.getElementById('d').showModal();"
hx-get="/postcard/send?awid={{.Id}}" hx-target="#d" class="card-footer-item">Send
Postcard</a>
</footer>
<script type="application/ld+json">
{{marshalJSON .Jsonld}}
</script>
</section>
</div>
{{else}}
<div class="column">
<div class="notification is-warning">
Sorry, no matching artworks found.
</div>
</div>
{{end}}
</div>
{{end}}
<nav class="pagination" role="navigation" aria-label="pagination">
{{.Pagination}}
</nav>
</div>
</div>
</section>
{{end}}
{{end}}
4 changes: 4 additions & 0 deletions assets/views/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
Please send your comments, sign our guestbook and send a postcard.
© Web Gallery of Art, created by Emil Krén and Daniel Marx.
</p>
<p>
v2 was made possible by our <a href="/contributors" hx-get="/contributors"
hx-target="#mc-area">contributors</a>!
</p>
</div>
<div class="column has-text-right">
<p>
Expand Down
8 changes: 5 additions & 3 deletions assets/views/partials/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
Artists
</a>

<a class="navbar-item" href="/search">
Search
</a>

<a class="navbar-item" href="/guestbook" hx-get="/guestbook" hx-target="#mc-area">
Guestbook
</a>
<!-- <a class="navbar-item" href="/search">
Search
</a>
<!--
<a class="navbar-item">
Tours
</a>
Expand Down
Loading

0 comments on commit 2edc855

Please sign in to comment.