Skip to content
This repository was archived by the owner on Aug 16, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ gem "jekyll-last-modified-at"

# gem "torture", path: "../torture"
gem "torture", git: "https://github.com/apotonick/torture"
group :jekyll_plugins do
gem 'algoliasearch-jekyll', '~> 0.7'
end
22 changes: 21 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
algoliasearch (1.16.0)
httpclient (~> 2.8.3)
json (>= 1.5.1)
algoliasearch-jekyll (0.8.0)
algoliasearch (~> 1.4)
appraisal (~> 2.1.0)
awesome_print (~> 1.6)
json (~> 1.8)
nokogiri (~> 1.6)
verbal_expressions (~> 0.1.5)
appraisal (2.1.0)
bundler
rake
thor (>= 0.14.0)
awesome_print (1.8.0)
coffee-script (2.4.1)
coffee-script-source
execjs
Expand Down Expand Up @@ -56,6 +71,7 @@ GEM
html-pipeline (2.4.1)
activesupport (>= 2, < 5)
nokogiri (>= 1.4)
httpclient (2.8.3)
i18n (0.7.0)
jekyll (3.1.6)
colorator (~> 0.1)
Expand Down Expand Up @@ -112,6 +128,7 @@ GEM
sawyer (~> 0.7.0, >= 0.5.3)
pkg-config (1.1.7)
public_suffix (1.5.3)
rake (12.1.0)
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
Expand All @@ -126,20 +143,23 @@ GEM
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thor (0.20.0)
thread_safe (0.3.5)
typhoeus (0.8.0)
ethon (>= 0.8.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
verbal_expressions (0.1.5)

PLATFORMS
ruby

DEPENDENCIES
algoliasearch-jekyll (~> 0.7)
github-pages
jekyll-last-modified-at
therubyracer
torture!

BUNDLED WITH
1.15.1
1.15.4
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Currently, the `bower_components/font-awesome/fonts` is copied over to `/`.

bundle exec jekyll serve -I

# Updating the search index

bundle exec jekyll algolia push

# Push to master

Always work on the `f6` branch.
Expand Down
8 changes: 8 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ include:
gems:
- jekyll-redirect-from
- jekyll-last-modified-at
algolia:
application_id: 'fill_in'
index_name: 'trailblazer'
read_only_api_key: 'fill_in'
excluded_files:
- 404.html
- index.html

3 changes: 3 additions & 0 deletions _includes/doc-2-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

{% include top-bar.html %}

<div class="content-area">
{% include hero.html %}

<div class="expanded row">
Expand Down Expand Up @@ -49,8 +50,10 @@
{% include sidebar-2-1.html %}
</div>
</div>
</div>


{% include search.html %}
{% include footer.html %}

</body>
Expand Down
3 changes: 3 additions & 0 deletions _includes/doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

{% include top-bar.html %}

<div class="content-area">
{% include hero.html %}

<div class="expanded row">
Expand Down Expand Up @@ -49,7 +50,9 @@
{% include sidebar.html %}
</div>
</div>
</div>

{% include search.html %}

{% include footer.html %}

Expand Down
43 changes: 43 additions & 0 deletions _includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,46 @@ <h4>
</footer>

{% include google_analytics.html %}

<!-- script -->
<script>
window.ALGOLIA_CONFIG = {
'applicationId': '{{ site.algolia.application_id }}',
'indexName': '{{ site.algolia.index_name }}',
'apiKey': '{{ site.algolia.read_only_api_key }}',
'baseurl': '{{ site.baseurl }}'
}
</script>
<script id="algolia__template" type="text/template">
{% raw %}
<div class="algolia__result">
<a class="algolia__result-link" href="{{ full_url }}#algolia:{{ css_selector }}">{{{ _highlightResult.title.value }}}</a>
{{#posted_at}}
<div class="algolia__result-date">{{ posted_at_readable }}</div>
{{/posted_at}}
<div class="algolia__result-text">{{{ _highlightResult.text.value }}}</div>
</div>
{% endraw %}
</script>
<script id="algolia__template--no-results" type="text/template">
No results found.
</script>
<script src="/javascripts/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/algoliasearch/3.6.0/algoliasearch.min.js"></script>
<script src="//cdn.jsdelivr.net/algoliasearch.helper/2.1.0/algoliasearch.helper.min.js"></script>
<script src="//cdn.jsdelivr.net/hogan.js/3.0.2/hogan.min.js"></script>
<script src="/javascripts/application.min.js"></script>
<script src="/javascripts/algolia.js"></script>
<script>
jQuery(document).ready(function($) {
$(document).foundation();

anchors.add("article h2");
anchors.add("article h3");

hljs.initHighlightingOnLoad();

// $('#code-slider').slick({arrows: true, dots: true});
$('.carousel').slick({arrows: true, dots: true});
});
</script>
1 change: 1 addition & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="shortcut icon" href="/favicon.ico">
<link href="//fonts.googleapis.com/css?family=Open+Sans:300, 400,700,800|Raleway:400,200,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/css/application.css" />
<link rel="stylesheet" href="/css/algolia.css" />

<!-- script -->
<script src="/javascripts/jquery.min.js"></script>
Expand Down
18 changes: 18 additions & 0 deletions _includes/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="search-content">
<!-- Hero -->
<div class="hero gems-hero search-hero">
<div class="hero-unit">
<div class="expanded row">
<div class="columns">
<h1 id="project_title">
<img class="algolia-logo" style="height: 5rem;" src="/images/algolia.svg" alt="Search" />
</h1>
</div>
</div>
</div>
</div>
<div class="row">
<div class="column medium-9 medium-centered">
<div class="search-results"></div>
</div>
</div>
3 changes: 3 additions & 0 deletions _includes/top-bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<li class=""><a href="/gems/disposable">DISPOSABLE</a></li>
</ul>
</li>
<li class="menu-text">
<input class="search-input" type="search" placeholder="Search ..."/>
</li>
<li>
<a href="https://leanpub.com/trailblazer" class="button secondary" onclick="trackOutboundLink('https://leanpub.com/trailblazer'); return false;">GET THE BOOK</a>
</li>
Expand Down
3 changes: 3 additions & 0 deletions _layouts/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

{% include top-bar.html %}

<div class="content-area">
{{ content }}
</div>
{% include search.html %}

{% include footer.html %}

Expand Down
2 changes: 1 addition & 1 deletion css/application.css

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions images/algolia.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions javascripts/algolia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Init the search box
$(function(config) {
'use strict';

var applicationId = config.applicationId;
var apiKey = config.apiKey;
var indexName = config.indexName;

var algolia = algoliasearch(applicationId, apiKey);
var helper = algoliasearchHelper(algolia, indexName);
helper.setQueryParameter('distinct', true);
helper.on('result', onResult);

// Content to hide/show when searching
var $initialContent = $('.content-area');
var $searchContent = $('.search-content');
var $searchContentResults = $searchContent.find('.search-results');
$searchContentResults.on('click', 'a', onLinkClick);
// Rendering templates
var templateResult = Hogan.compile($('#algolia__template').html());
var templateNoResults = $('#algolia__template--no-results').html();

var lastQuery;

// Toggle result page
function showResults() {
window.scroll(0, 0);
$initialContent.addClass('algolia__initial-content--hidden');
$searchContent.addClass('algolia__search-content--active');

}
function hideResults() {
$initialContent.removeClass('algolia__initial-content--hidden');
$searchContent.removeClass('algolia__search-content--active');
}

// Handle typing query
function onQueryChange() {
lastQuery = $(this).val();
if (lastQuery.length === 0) {
hideResults();
return false;
}
helper.setQuery(lastQuery).search();
showResults();
}

function onResult(data) {
// Avoid race conditions, discard results that do not match the latest query
if (data.query !== lastQuery) {
return false;
}
var content = data.nbHits ? renderResults(data) : templateNoResults;
$searchContentResults.html(content);
}

function renderResults(data) {
return $.map(data.hits, function(hit) {
if (hit.posted_at) {
hit.posted_at_readable = moment.unix(hit.posted_at).fromNow();
}
hit.css_selector = encodeURI(hit.css_selector);
hit.full_url = hit.url;

return templateResult.render(hit);
}).join('');
}

// Scroll page to correct element
function getAnchorSelector(hash) {
var anchor = hash.substring(1);
if (!anchor.match(/^algolia:/)) {
return false;
}
return decodeURI(anchor.replace(/^algolia:/, ''));
}

function scrollPageToSelector(selector) {
var target = $('.content-area').find(selector);
var targetOffset = target[0].getBoundingClientRect().top + window.pageYOffset - 70;
window.setTimeout(function() {
window.scroll(0, targetOffset);
}, 100);
}

function onLinkClick(event) {
var selector = getAnchorSelector(event.target.hash);
// Normal link, going to another page
if (event.target.pathname !== window.location.pathname || !selector) {
return true;
}
// Scrolling to a result on the same page
hideResults();
scrollPageToSelector(selector);
event.preventDefault();
return false;
}

window.setTimeout(function() {
var selector = getAnchorSelector(window.location.hash);
if (selector) {
scrollPageToSelector(selector);
}
}, 100);

// Input listening for queries
var $searchInput = $('.search-input');
$searchInput.on('keyup', onQueryChange).trigger('keyup');
}(window.ALGOLIA_CONFIG));
Loading