Skip to content

Instantly share code, notes, and snippets.

View benhinchley's full-sized avatar

Ben Hinchley benhinchley

View GitHub Profile
@benhinchley
benhinchley / machine.js
Last active November 12, 2019 04:56
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
function ResultRenderer(props) {
const { values, token, resultClicked } = props;
return (
<div className="gg-result">
{values["image"] ? (
<div className="gg-result__image">
<TokenLink
url={values["url"]}
token={token}
@benhinchley
benhinchley / triblive-custom-integration.md
Last active January 29, 2019 12:38
Dynamic Content installation instructions for TribLive

TribLive - Custom Integration Installation

Render Targets

<!-- navigation search box -->
<div id="nav-search-box"></div>

<!-- results page -->
<div id="results-search-box"></div>
<div id="results-search-response"></div>
@benhinchley
benhinchley / schema-creation.js
Created October 17, 2018 06:05
an example of how to create a sajari schema with @sajari/sdk-node
const sajari = require("@sajari/sdk-node")
const SajariProject = "<your-project>";
const SajariCollection = "<your-collection>";
const SajariCredentials = {
key: "<your-api-key>",
secret: "<your-api-secret>"
};
// create client
@benhinchley
benhinchley / nrma-install.md
Last active October 17, 2018 04:08
Installation instructions for the NRMA - Sajari Search Integration

NRMA - Sajari Search Integration Install

Integration

Setup function

The following Javascript code block should be placed in the <head /> of your global page template.

<script>
    (function() {
        function setup(c,a,f){function g(){var a=[],b=function(){a.push(arguments)};b.arr=a;c.sajari=c.sajari||{};c.sajari.ui=c.sajari.ui||[];c.sajari.ui.push(b);return b}var d=a.createElement("link");d.href=f;d.as="script";d.rel="preload";d.crossorigin=!0;var e=a.createElement("script");e.async=!0;e.src=f;a.head.appendChild(d);a.head.appendChild(e);a=g();a.init=function(a){var b=g();b(a);return b};return a};
<?php
/*
// createLocationFilter generates the location filter based on the
// location matching matrix provided by careerone
func createLocationFilter(locationLevel int, locations []int) string {
filterSegmentFmt := "(location_level_%[1]d = %[2]d OR location_level_%[1]d = 0)"
s := make([]string, 0, len(locations))
for i := locationLevel; i < len(locations)+1; i++ {
/* fixing the text alignment and suggestions container width */
#nav-search-box ul,
#results-search-box ul {
margin: 0;
padding: 0;
text-align: left;
}
@benhinchley
benhinchley / triblive-search-results.html
Created October 10, 2018 04:24
updated integration code for triblive search results
<script>
var getUrlParam = function (e) { var t = new RegExp("[?&]" + e.replace(/[\[\]]/g, "\\$&") + "(=([^&#]*)|&|#|$)"), a = t.exec(window.location.href); return a && a[2] ? decodeURIComponent(a[2].replace(/\+/g, " ")) : "" };
var setup = function (c, a, f) { function g() { var a = [], b = function () { a.push(arguments) }; b.arr = a; c.sajari = c.sajari || {}; c.sajari.ui = c.sajari.ui || []; c.sajari.ui.push(b); return b } var e = a.createElement("script"); e.async = !0; e.src = f; var d = a.createElement("link"); d.as = "script"; d.rel = "preload"; d.crossorigin = !0; d.href = f; a.head.appendChild(d); a.head.appendChild(e); a = g(); a.init = function (a) { var b = g(); b(a); return b }; return a };
var sajari = setup(window, document, "//cdn.sajari.net/js/integrations/website-search-1.4.js");
var searchBox = sajari.init({
mode: "search-box",
project: "1534384424562720477", // Set this to your project.
collection: "triblive-com", // Set this to your collection
/*
Removing this rule, achieves the same result as adding 10px padding to the following selector .top-search-form input[placeholder="Search"]
*/
.top-search-form input {
position: absolute;
background: none;
top: 0;
left: 0;
}
@benhinchley
benhinchley / install.js
Last active September 8, 2018 03:21 — forked from mish15/install.js
Dynamic content block
// 1. Assumes the following div exists in the page, note: you can change this using the "attachDynamicContent" setting
// <div id="dynamic-content"></div>
// 2. The "pipeline" parameter controls the query execution, this example uses "popular", this is configurable
// 3. The "values" map controls the query. You don't need the "q" parameter, but can use this to control the context of
// the results. For example you may wish to use the "document.title" to find related content to the current page
// 4. The filter parameter allows any number of filters to be used to filter the query results, e.g. to domains, or sections,
// or any other number of factors
var recommend = setup(window, document, "script", "sajari", "//cdn.sajari.net/js/integrations/website-search-1.4.js");
recommend({