-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore AddSearch Experiences (Mostly) #8665
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from "react" | ||
|
||
|
||
class AddSearch extends React.Component { | ||
componentDidMount() { | ||
const resultPage = "/hi-rachel" | ||
window.addsearch_settings = { | ||
"search_widget": { | ||
"placeholder": "Search Pantheon Docs", | ||
"show_search_suggestions": true, | ||
"search_suggestion_position": "left", | ||
"default_sortby": "relevance", | ||
"display_date": false, | ||
"display_meta_description": true, | ||
"display_result_image": false, | ||
"link_target": "_blank", | ||
"hide_logo": false, | ||
"direction": "ltr", | ||
"api_throttle_time": 2000, | ||
"automatic_filter_results_by_site_language": false, | ||
"analytics_enabled": true | ||
} | ||
} | ||
const script = document.createElement("script") | ||
//alert(resultPage); | ||
|
||
script.setAttribute( | ||
"src", | ||
`https://cdn.addsearch.com/v5/addsearch-ui.min.js?key=a7b957b7a8f57f4cc544c54f289611c6&id=search_widget${ | ||
resultPage.includes("hello") ? "&type=resultpage" : "" | ||
}` | ||
) | ||
script.setAttribute("defer", true) | ||
|
||
document.body.appendChild(script) | ||
} | ||
render() { | ||
return <div className="addsearch-container" /> | ||
} | ||
} | ||
|
||
export default AddSearch |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +0,0 @@ | ||
import React from "react" | ||
import { Helmet } from "react-helmet" | ||
|
||
class SearchResults extends React.Component { | ||
render() { | ||
return ( | ||
<div className="addsearch-container"> | ||
<Helmet> | ||
<script | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
function parseParamsFromUrl() { | ||
var queryString = window.location.search; | ||
queryString = queryString.substring(11); | ||
queryString = queryString.split("+").join(" "); | ||
return queryString; | ||
} | ||
var urlParams = parseParamsFromUrl(); | ||
document.getElementById('piodocsearch').setAttribute('value', urlParams); | ||
`, | ||
}} | ||
/> | ||
</Helmet> | ||
|
||
<div id="addsearch-results"></div> | ||
|
||
<script | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
window.addsearch_settings = { | ||
display_url: true, | ||
display_resultscount: true, | ||
display_date: true, | ||
display_sortby: true, | ||
display_category: true | ||
} | ||
`, | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default SearchResults | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import React from "react" | |
import { StaticQuery, graphql, Link } from "gatsby" | ||
import './style.css'; | ||
import AddSearch from "../../components/addSearch" | ||
import AddSearch2023 from "../../components/addSearch2023" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went with this 2023 file name while doing side by side comparison with the pre-existing |
||
|
||
const Header = ({ data, page }) => ( | ||
<> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,62 +2,100 @@ import React from "react" | |
import Layout from "../layout/layout" | ||
import SEO from "../layout/seo" | ||
import SVG404 from "../../source/images/404_dark.svg" | ||
import { Link, graphql } from "gatsby" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rachelwhitton is it accurate that the 404 behavior you wanted to get working just isn't working? If so, I'd rather not add non-working code to this file |
||
|
||
|
||
class NotFoundPage extends React.Component { | ||
|
||
componentDidMount() { //On page load... | ||
|
||
window.addsearch_settings = { | ||
"search_widget": { | ||
"placeholder": "Search Pantheon Docs", | ||
"show_search_suggestions": true, | ||
"search_suggestion_position": "left", | ||
"default_sortby": "relevance", | ||
"display_date": false, | ||
"display_meta_description": true, | ||
"display_result_image": false, | ||
"link_target": "_blank", | ||
"hide_logo": false, | ||
"direction": "ltr", | ||
"api_throttle_time": 2000, | ||
"automatic_filter_results_by_site_language": false, | ||
"analytics_enabled": true | ||
} | ||
} | ||
|
||
const script = document.createElement("script") // Loads the Addsearch JS blob from them | ||
script.setAttribute( | ||
componentDidMount() { //On page load... | ||
const { pathname } = this.props.location // pull the "location" prop and save it as 'pathname' | ||
var searchPath = pathname.replace(/\//g, " ").replace(/-/g, " ") // define searchPath as pathname by removing the slash and replacing dashes w with spaces | ||
|
||
window.location.href.toString().includes("search") // If the current page address includes "addsearch"... | ||
? null // Do nothing | ||
: window.location = `/404?search=${searchPath}` // Otherwise, rewrite the URL (which I think inits a reload) to form the UTM parameters Addsearch needs to run a query. | ||
|
||
const script1 = document.createElement("script") // Loads the Addsearch JS blob from them | ||
script1.setAttribute( | ||
"src", | ||
`https://cdn.jsdelivr.net/npm/[email protected]/dist/addsearch-js-client.min.js` | ||
) | ||
//script2.setAttribute("defer", true) | ||
document.body.appendChild(script1) | ||
|
||
const script2 = document.createElement("script") // Loads the Addsearch JS blob from them | ||
script2.setAttribute( | ||
"src", | ||
`https://cdn.addsearch.com/v5/addsearch-ui.min.js?key=a7b957b7a8f57f4cc544c54f289611c6&id=search_widget` | ||
`https://cdn.jsdelivr.net/npm/addsearch[email protected]/dist/addsearch-search-ui.min.js` | ||
) | ||
script.setAttribute("defer", true) | ||
// script3.setAttribute("defer", true) | ||
script2.onload = () => this.addSearchStuff(); | ||
document.body.appendChild(script2) | ||
|
||
const link = document.createElement("script") // Loads the Addsearch JS blob from them | ||
link.setAttribute( | ||
"href", | ||
`https://cdn.jsdelivr.net/npm/[email protected]/dist/addsearch-search-ui.min.css` | ||
) | ||
link.setAttribute("rel", 'stylesheet') | ||
|
||
//alert('mount up'); | ||
document.body.appendChild(link) | ||
|
||
document.body.appendChild(script) | ||
} | ||
|
||
render() { | ||
const { pathname } = this.props.location | ||
addSearchStuff() { | ||
//alert('add it'); | ||
var client = new AddSearchClient('a7b957b7a8f57f4cc544c54f289611c6'); | ||
|
||
var searchui_conf = { | ||
searchResultsPageUrl: '/search?search=${searchPath}' | ||
} | ||
|
||
// Search UI instance | ||
var searchui = new AddSearchUI(client, searchui_conf); | ||
|
||
// Add components | ||
searchui.searchField({ | ||
searchAsYouType: true, | ||
selectorToBind: '.addsearch', | ||
}); | ||
searchui.searchResults({ | ||
containerId: 'addsearch-results' | ||
}); | ||
searchui.pagination({ | ||
containerId: 'addsearch-pagination' | ||
}); | ||
|
||
// All components added. Start | ||
searchui.start(); | ||
|
||
} | ||
|
||
render() { | ||
return ( | ||
<Layout type="404"> | ||
<SEO | ||
title="404" | ||
description="Zoinks! You've hit a URL that doesn't exist. Let's try a search:" | ||
/> | ||
/> | ||
<div style={{ marginTop: "-20px" }} className="container"> | ||
<main className=" doc-content-well" id="docs-main"> | ||
<div className="mb-70"> | ||
<img className="notfound" src={SVG404} /> | ||
|
||
<h2>Sorry, there's no page at that URL.</h2> | ||
|
||
<h3> | ||
You can try the search above, or go{" "} | ||
<Link to="/"> back to all docs</Link>? | ||
</h3> | ||
<div id="addsearch-results"></div> | ||
<div id="addsearch-pagination"></div> | ||
</div> | ||
</main> | ||
</div> | ||
</Layout> | ||
) | ||
return <div className="addsearch-container" /> | ||
} | ||
} | ||
|
||
} | ||
export default NotFoundPage |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import SEO from "../layout/seo" | |
|
||
class Search extends React.Component { | ||
componentDidMount() { //On page load... | ||
|
||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rachelwhitton please remove the commented out code |
||
window.addsearch_settings = { | ||
"search_widget": { | ||
"placeholder": "Search Pantheon Docs", | ||
|
@@ -33,7 +33,74 @@ class Search extends React.Component { | |
script.setAttribute("defer", true) | ||
|
||
document.body.appendChild(script) | ||
*/ | ||
const script2 = document.createElement("script") // Loads the Addsearch JS blob from them | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you pick more meaningful variable names? |
||
script2.setAttribute( | ||
"src", | ||
`https://cdn.jsdelivr.net/npm/[email protected]/dist/addsearch-js-client.min.js` | ||
) | ||
//script2.setAttribute("defer", true) | ||
document.body.appendChild(script2) | ||
|
||
|
||
const script3 = document.createElement("script") // Loads the Addsearch JS blob from them | ||
script3.setAttribute( | ||
"src", | ||
`https://cdn.jsdelivr.net/npm/[email protected]/dist/addsearch-search-ui.min.js` | ||
) | ||
// script3.setAttribute("defer", true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line please if we're not going to use it |
||
script3.onload = () => this.addSearchStuff(); | ||
document.body.appendChild(script3) | ||
|
||
|
||
const link = document.createElement("script") // Loads the Addsearch JS blob from them | ||
link.setAttribute( | ||
"href", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did this loading of the style sheet end up working? |
||
`https://cdn.jsdelivr.net/npm/[email protected]/dist/addsearch-search-ui.min.css` | ||
) | ||
link.setAttribute("rel", 'stylesheet') | ||
|
||
//alert('mount up'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove stray debugging code |
||
document.body.appendChild(link) | ||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
addSearchStuff() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you chose a more meaningful method name? I wrote this name before I knew what it would do. |
||
//alert('add it'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove stray debugging code please |
||
var client = new AddSearchClient('a7b957b7a8f57f4cc544c54f289611c6'); | ||
|
||
|
||
var searchui_conf = { | ||
//searchResultsPageUrl: 'search' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove unused code please |
||
searchResultsPageUrl: 'search' | ||
} | ||
// Search UI instance | ||
var searchui = new AddSearchUI(client, searchui_conf); | ||
|
||
// Add components | ||
searchui.searchField({ | ||
containerId: 'searchfield', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this code is meant to add a form that is different from the form in the header. But looking at https://pr-8665-documentation.appa.pantheon.site/search/, I only see the form in the header |
||
placeholder: 'Keyword..', | ||
button: 'Search', | ||
searchAsYouType: true, | ||
selectorToBind: '.addsearch', | ||
ignoreSearchResultsPageUrl: true, | ||
}); | ||
searchui.searchResults({ | ||
containerId: 'results' | ||
}); | ||
searchui.pagination({ | ||
containerId: 'pagination' | ||
}); | ||
|
||
// All components added. Start | ||
searchui.start(); | ||
|
||
} | ||
|
||
|
||
|
||
|
@@ -44,13 +111,17 @@ class Search extends React.Component { | |
<div style={{ marginTop: "-20px" }} className="container"> | ||
<main className=" doc-content-well" id="docs-main"> | ||
<div className=""> | ||
<h1 className="title">Search Results</h1> | ||
<h1 className="title">Search Results:</h1> | ||
</div> | ||
<div className="" style={{ marginBottom: "15px" }}></div> | ||
<div className=" mb-70"> | ||
<div className=""> | ||
<div className="container"> | ||
<div className="row"> | ||
<div className="row" id="searchfield"> | ||
</div> | ||
<div className="row addsearch" id="results"> | ||
</div> | ||
<div className="row" id="pagination"> | ||
</div> | ||
</div> | ||
</div> | ||
|
@@ -62,4 +133,4 @@ class Search extends React.Component { | |
} | ||
} | ||
|
||
export default Search | ||
export default Search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi-rachel
probably isn't what we want here 😆