-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from gettypubs/search
Search
- Loading branch information
Showing
15 changed files
with
297 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: Search | ||
toc: false | ||
url: search | ||
menu: false | ||
type: search | ||
online: false | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,66 @@ | ||
{{/* | ||
Search Index Data template | ||
|
||
This template builds a single JSON file ("/search.json" by default) with data | ||
suitable for being fed into a client-side search tool such as Lunr.js. | ||
|
||
You can customize the output from this index as follows: | ||
|
||
* Define a variable for any page Type that should be included in the index. This | ||
can be done through the where function (https://gohugo.io/functions/where/) | ||
* Use the `union` function to combine these into a single collection, referred | ||
to here as `searchablePages`. | ||
* Use the `range` function to iterate over this collection and add a custom | ||
dictionary (Go's version of a data hash) to the `index` array in the Scratch | ||
area. | ||
* Output this data to JSON using the `jsonify` function. | ||
|
||
In order for Hugo to actually output this data as a static file, add an empty | ||
Markdown file somewhere in your main "content" folder that has the type of | ||
"data" and the layout of "search-index". Set the URL params to whatever you want | ||
the output file to be called. Ex: | ||
|
||
project_root/content/search-index.md | ||
|
||
--- | ||
type: data | ||
layout: search-index | ||
url: search.json | ||
--- | ||
|
||
NB: This solution makes use of **both** the standard $.Scratch register AND a | ||
block-scoped .Scratch inside the `range` loop. | ||
*/}} | ||
|
||
{{- $.Scratch.Add "index" slice -}} | ||
{{- $pages := where .Site.Pages "Type" "eq" "page" -}} | ||
{{- range $index, $page := $pages -}} | ||
{{- $.Scratch.Add "index" (dict "id" $index "title" $page.Title "url" $page.Permalink "type" $page.Type "content" $page.Plain) -}} | ||
|
||
{{- $pages := where .Site.RegularPages "Type" "page" -}} | ||
{{- $essays := where .Site.RegularPages "Type" "essay" -}} | ||
{{- $searchablePages := $pages | union $essays -}} | ||
|
||
{{- range $index, $page := $searchablePages -}} | ||
|
||
{{- .Scratch.Set "pageData" "" -}} | ||
{{- .Scratch.Set "searchContent" "" -}} | ||
{{- .Scratch.Set "pageURL" "" -}} | ||
{{- .Scratch.Set "parentSection" "" -}} | ||
{{- .Scratch.Set "pageType" "" -}} | ||
|
||
{{- if gt (len $page.Content) 0 -}} | ||
{{- .Scratch.Set "searchContent" $page.Plain -}} | ||
{{- .Scratch.Set "pageURL" $page.RelPermalink -}} | ||
{{- .Scratch.Set "pageType" $page.Type -}} | ||
|
||
{{- else -}} | ||
{{ .Scratch.Set "parentSection" ($page.Section) -}} | ||
{{ .Scratch.Add "parentSection" "/index.md" -}} | ||
{{ .Scratch.Set "searchContent" $page.Params.abstract -}} | ||
{{ .Scratch.Set "pageURL" (relref $page (.Scratch.Get "parentSection")) -}} | ||
{{- .Scratch.Set "pageType" "abstract" -}} | ||
|
||
{{- end -}} | ||
{{- .Scratch.Set "pageData" (dict "id" $index "title" $page.Title "url" (.Scratch.Get "pageURL") "type" (.Scratch.Get "pageType") "content" (.Scratch.Get "searchContent")) -}} | ||
|
||
{{- $.Scratch.Add "index" (.Scratch.Get "pageData") -}} | ||
{{- end -}} | ||
{{- $.Scratch.Get "index" | jsonify -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 27 additions & 9 deletions
36
themes/quire-base-theme/layouts/partials/search-results.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
<div id="js-search-results" class="quire-search-results"> | ||
<div class="quire-search-results__inner"> | ||
<ul id="js-search-results-list" class="quire-search-results__inner__list"> | ||
</ul> | ||
<script type="text/x-template" id="search-results-template"> | ||
<div> | ||
<input class="search-input" | ||
id="js-search-input" | ||
name="search" | ||
type="text" | ||
@input="update" | ||
value=""/> | ||
|
||
<div v-if="ready"> | ||
<div v-if="results.length > 0"> | ||
<h3 class="meta">Displaying ${results.length} results</h3> | ||
</div> | ||
<div class="quire-search-results__inner"> | ||
<ul class="quire-search-results__inner__list"> | ||
<li v-for="result in results" class="quire-search-results__inner__list__item"> | ||
<a class="quire-search-results__inner__list__item__link" :href="result.url"> | ||
<span v-html="result.title"></span> | ||
</a> | ||
<span class="quire-search-results__inner__list__item__type">${ result.type }</span> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div v-else> | ||
<h1>Loading...</h1> | ||
</div> | ||
<template id="js-search-results-template"> | ||
<li class="quire-search-results__inner__list__item"> | ||
<a class="quire-search-results__inner__list__item__link js-search-results-item-title" href=""></a> | ||
</li> | ||
</template> | ||
</div> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ define "main" }} | ||
<div class="quire-page"> | ||
<header class="quire-page__header"> | ||
<h1 class="quire-page__header__title">Search this Publication</h1> | ||
</header> | ||
<div class="quire-page__content"> | ||
<section class="quire-page__content__main"> | ||
<div id="js-search"> | ||
{{ partial "search-results.html" . }} | ||
</div> | ||
</section> | ||
</div> | ||
</div> | ||
|
||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,26 @@ | ||
.quire-nav { | ||
|
||
font-size: 1rem * $small-font-scale; | ||
font-weight: 400; | ||
|
||
ul { | ||
display: flex; | ||
justify-content: center; | ||
list-style-type: none; | ||
padding: 0; | ||
// border: 1px solid #000; | ||
margin: 0; | ||
padding: 0; | ||
|
||
li { | ||
margin: 1em; | ||
// border: 1px solid #fff000; | ||
} | ||
|
||
li { margin: 1em; } | ||
} | ||
|
||
svg { | ||
fill: $primary-color; | ||
height: 1em; | ||
width: 1em; | ||
fill: $primary-color; | ||
} | ||
|
||
&__section-link::before, | ||
&__current-page-link::before, { | ||
content: "›"; | ||
margin-right: $base-spacing; | ||
} | ||
|
||
} |
Oops, something went wrong.