-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Algolia search; replace vendor libraries with CDN; add GTM tag to…
… settings/env
- Loading branch information
Showing
22 changed files
with
168 additions
and
80 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
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,17 @@ | ||
from typing import Any | ||
|
||
from django.conf import settings | ||
from django.http import HttpRequest | ||
|
||
|
||
def google_tag_manager(_: HttpRequest) -> dict[str, Any]: | ||
"""Add the Google Tag Manager ID to the context.""" | ||
return {"GOOGLE_GTM_TAG": settings.GOOGLE_GTM_TAG} | ||
|
||
|
||
def algolia_search_key(_: HttpRequest) -> dict[str, Any]: | ||
"""Add the Algolia search key to the context.""" | ||
return { | ||
"ALGOLIA_APPLICATION_ID": settings.ALGOLIA_APPLICATION_ID, | ||
"ALGOLIA_SEARCH_KEY": settings.ALGOLIA_SEARCH_KEY, | ||
} |
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,29 @@ | ||
from algoliasearch_django import AlgoliaIndex | ||
from algoliasearch_django.decorators import register | ||
|
||
from .models import Incident | ||
|
||
|
||
@register(Incident) | ||
class IncidentIndex(AlgoliaIndex): | ||
fields = ( | ||
"date", | ||
"cave", | ||
"get_state_display", | ||
"county", | ||
"get_country_display", | ||
"incident_report", | ||
"incident_analysis", | ||
"incident_summary", | ||
) | ||
|
||
settings = { | ||
"searchableAttributes": [ | ||
"cave", | ||
"get_state_display", | ||
"county", | ||
"get_country_display", | ||
"incident_report", | ||
"incident_analysis", | ||
], | ||
} |
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,49 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block main_content_class %}smaller-container{% endblock %} | ||
|
||
{% block header_scripts %} | ||
<!--suppress JSUnresolvedReference --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js" integrity="sha256-1QNshz86RqXe/qsCBldsUu13eAX6n/O98uubKQs87UI=" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.production.min.js" integrity="sha256-TW7D3X/i/W+RUgEeDppEnFT2ixv5lzplKH0c58D92dY=" crossorigin="anonymous"></script> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/satellite-min.css" integrity="sha256-p/rGN4RGy6EDumyxF9t7LKxWGg6/MZfGhJM/asKkqvA=" crossorigin="anonymous"> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1 class="page-header">Search</h1> | ||
|
||
<div class="mt-4 ais-InstantSearch"> | ||
<div id="searchbox"></div> | ||
<div id="hits"></div> | ||
<div id="pagination"></div> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
const searchClient = algoliasearch('{{ ALGOLIA_APPLICATION_ID }}', '{{ ALGOLIA_SEARCH_KEY }}'); | ||
|
||
const search = instantsearch({ | ||
indexName: 'Incident', | ||
searchClient, | ||
}); | ||
|
||
search.addWidgets([ | ||
instantsearch.widgets.searchBox({ | ||
container: '#searchbox', | ||
}), | ||
|
||
instantsearch.widgets.hits({ | ||
container: '#hits', | ||
templates: { | ||
item: (hit, { html, components }) => html` | ||
<div> | ||
<h1>${components.Highlight({hit, attribute: "cave"})}</h1> | ||
<p>${components.Highlight({hit, attribute: "incident_summary"})}</p> | ||
</div> | ||
`, | ||
}, | ||
}) | ||
]); | ||
|
||
search.start(); | ||
</script> | ||
{% endblock %} |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.