Skip to content

Commit

Permalink
Use search_index_path helper to locate Search assets
Browse files Browse the repository at this point in the history
This fixes search when Middleman is configured with the http_prefix option.

This is the recommended approach from the Middleman search gem itself,
rather than hardcoding '/search.json'

References:

- https://github.com/manastech/middleman-search#asset-pipeline
- https://github.com/manastech/middleman-search/blob/ed9e5254bb554988c755fc40238d9e9f67b20abe/lib/middleman-search/extension.rb#L29
  • Loading branch information
odlp committed Jan 20, 2022
1 parent 6f84654 commit 3c629e7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/assets/javascripts/_modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
var results
var query
var maxSearchEntries = 20
var searchIndexPath

this.start = function start ($element) {
$searchForm = $element.find('form')
Expand All @@ -25,6 +26,7 @@
$searchResults = $searchResultsWrapper.find('.search-results__content')
$searchResultsTitle = $searchResultsWrapper.find('.search-results__title')
$searchHelp = $('#search-help')
searchIndexPath = $element.data('searchIndexPath')

changeSearchAction()
changeSearchLabel()
Expand All @@ -49,7 +51,7 @@
this.downloadSearchIndex = function downloadSearchIndex () {
updateTitle('Loading search results')
$.ajax({
url: '/search.json',
url: searchIndexPath,
cache: true,
method: 'GET',
success: function (data) {
Expand Down
2 changes: 1 addition & 1 deletion lib/source/layouts/_search.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if config[:tech_docs][:enable_search] %>
<div class="search" data-module="search">
<div class="search" data-module="search" data-search-index-path="<%= search_index_path %>">
<form action="https://www.google.co.uk/search" method="get" role="search" class="search__form govuk-!-margin-bottom-4">
<input type="hidden" name="as_sitesearch" value="<%= config[:tech_docs][:host] %>"/>
<label class="govuk-label search__label" for="search" aria-hidden="true">
Expand Down

0 comments on commit 3c629e7

Please sign in to comment.