Skip to content

Commit 98bb78b

Browse files
committed
Initial conversion
1 parent b4ea315 commit 98bb78b

18 files changed

+27
-283
lines changed

npm-shrinkwrap.json

+1-93
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"gulp-replace": "^0.6.1",
3131
"handlebars": "^3.0.1",
3232
"lodash": "^4.17.4",
33-
"lunr": "^0.7.2",
3433
"marked": "^0.3.6",
3534
"md5": "^2.2.1",
3635
"metalsmith": "^2.3.0",
@@ -45,7 +44,6 @@
4544
"metalsmith-in-place": "^1.0.1",
4645
"metalsmith-layouts": "^1.8.0",
4746
"metalsmith-less": "^2.0.0",
48-
"metalsmith-lunr": "git://github.com/particle-iot/metalsmith-lunr#0.3.1",
4947
"metalsmith-markdown": "spark/metalsmith-markdown#v0.4.2",
5048
"metalsmith-move-up": "^1.0.0",
5149
"metalsmith-paths": "2.1.1",

scripts/metalsmith.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ var fixLinks = require('./fixLinks');
3232
var inPlace = require('metalsmith-in-place');
3333
var watch = require('metalsmith-watch');
3434
var autotoc = require('metalsmith-autotoc');
35-
var lunr = require('metalsmith-lunr');
36-
var lunr_ = require('lunr');
3735
var fileMetadata = require('metalsmith-filemetadata');
3836
var msIf = require('metalsmith-if');
3937
var precompile = require('./precompile');
@@ -62,9 +60,6 @@ var generateSearch = process.env.SEARCH_INDEX !== '0';
6260

6361
var noScripts = false;
6462

65-
// Make Particle.function searchable with function only
66-
lunr_.tokenizer.separator = /[\s\-.]+/;
67-
6863
exports.metalsmith = function () {
6964
function removeEmptyTokens(token) {
7065
if (token.length > 0) {
@@ -124,7 +119,7 @@ exports.metalsmith = function () {
124119
}))
125120
// Add properties to files that match the pattern
126121
.use(fileMetadata([
127-
{ pattern: 'content/**/*.md', metadata: { lunr: generateSearch, assets: '/assets', branch: gitBranch, noScripts: noScripts } }
122+
{ pattern: 'content/**/*.md', metadata: { assets: '/assets', branch: gitBranch, noScripts: noScripts } }
128123
]))
129124
.use(msIf(
130125
environment === 'development',
@@ -295,18 +290,6 @@ exports.metalsmith = function () {
295290
selector: 'h2, h3',
296291
pattern: '**/**/*.md'
297292
}))
298-
// Generate Lunr search index for all the files that have lunr: true
299-
// This is slow. Use SEARCH_INDEX=0 in development to avoid creating this file
300-
.use(lunr({
301-
indexPath: 'search-index.json',
302-
fields: {
303-
contents: 1,
304-
title: 10
305-
},
306-
pipelineFunctions: [
307-
removeEmptyTokens
308-
]
309-
}))
310293
// For files that have a template frontmatter key, look for that template file in the configured directory and
311294
// render that template using the Metalsmith file with all its keys as context
312295
.use(layouts({

src/assets/js/docs.js.hbs

+1-155
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-env browser */
2-
/* global jQuery, lunr, Handlebars, prettyPrint */
2+
/* global jQuery, Handlebars, prettyPrint */
33
/*!
44

55
Documentation middleware.
@@ -228,45 +228,6 @@ Created by Zach Supalla.
228228
Docs.resultsAdded = 0;
229229

230230
Docs.buildSearch = function() {
231-
if (typeof lunr === 'undefined') {
232-
return;
233-
}
234-
// Make Particle.function searchable with function only
235-
lunr.tokenizer.separator = /[\s\-.]+/;
236-
lunr.Pipeline.registerFunction(Docs._removeEmptyTokens, 'removeEmptyTokens');
237-
238-
$.getJSON('/search-index.json', function(data) {
239-
var store = data.store;
240-
var idx = lunr.Index.load(data.index);
241-
$('input.search-box').keyup(function() {
242-
var searchQuery = this.value;
243-
var specifier="";
244-
if (searchQuery.indexOf(":")!=-1) { // if the searchQuery has a specifier
245-
specifier = searchQuery.split(":")[0];
246-
searchQuery = searchQuery.split(":")[1];
247-
}
248-
Docs.emptyResults();
249-
if (searchQuery === '' || searchQuery.length < 3) {
250-
$('.search-results').hide();
251-
} else {
252-
$('.search-results').show();
253-
var results = idx.search(searchQuery);
254-
255-
// filter by section
256-
var sectionResults = Docs.filterSearchBySection(results,specifier);
257-
258-
// define urls to prioritize
259-
// var urlArray = ["faq/particle-devices/led-troubleshooting/photon/#blinking-green"];
260-
// Docs.boostSearchByUrl(sectionResults,urlArray);
261-
262-
// filter by device
263-
var topFilteredResults = Docs.filterSearchByDevice(sectionResults,specifier);
264-
265-
// build search
266-
Docs.buildSearchResults(topFilteredResults, store);
267-
}
268-
});
269-
});
270231

271232
$('body').click(function() {
272233
$('.search-results').hide();
@@ -288,121 +249,6 @@ Created by Zach Supalla.
288249
return stringToTitleCase;
289250
};
290251

291-
Docs.boostSearchByUrl = function(results,urlArray) {
292-
var resultsBoost=[];
293-
// if the results you get contain a particular URL, push this URL to the top of the pile.
294-
for (x=0; x<results.length; x++) {
295-
// check to see if there is any overlap between the two arrays
296-
var currentResult = results[x];
297-
var currentUrl = String(currentResult.ref);
298-
for (y=0; y<urlArray.length; y++) {
299-
if (currentUrl.indexOf(urlArray[y])!=-1) {
300-
// splice
301-
results.splice(x-1,x);
302-
// unshift
303-
results.unshift(currentResult);
304-
}
305-
}
306-
}
307-
return resultsBoost;
308-
}
309-
310-
Docs.filterSearchBySection = function(results,specifier) {
311-
var pathSearch = window.location.pathname.split("/").filter(function(n){return n!=""});
312-
var sectionSearch = pathSearch[0];
313-
314-
var sectionFilteredResults = [];
315-
var allSections = ["guide","tutorials","faq","reference","support"];
316-
317-
if (specifier.length>0) { // if the searchQuery has a specifier
318-
if (allSections.indexOf(specifier)!=-1) { // if your specifier identifies one of the sections
319-
// narrow by that section
320-
for (x=0; x<results.length; x++) {
321-
var params = String(results[x].ref);
322-
if (params.indexOf(specifier)!=-1) { // if the specifier is in this ref, then include it
323-
sectionFilteredResults.push(results[x]);
324-
}
325-
}
326-
}
327-
else { // if specifier is "all" or anything else, no need to narrow by section
328-
sectionFilteredResults = results;
329-
}
330-
}
331-
// else { // if there is no specifier, then narrow by current section
332-
// for (x=0; x<results.length; x++) {
333-
// var params = String(results[x].ref);
334-
// if (params.indexOf(sectionSearch)!=-1) { // if the this section is in this ref, then include it
335-
// sectionFilteredResults.push(results[x]);
336-
// }
337-
// }
338-
// }
339-
340-
else { // if there is no specifier, then search all
341-
sectionFilteredResults = results;
342-
}
343-
344-
return sectionFilteredResults;
345-
}
346-
347-
Docs.filterSearchByDevice = function(results,specifier) {
348-
var pathSearch = window.location.pathname.split("/").filter(function(n){return n!=""});
349-
var deviceSearch = pathSearch[pathSearch.length - 1];
350-
351-
var allDevices = ["photon","core","electron","argon","boron","xenon"];
352-
353-
if (specifier.length>0) {
354-
if (allDevices.indexOf(specifier)!=-1) { // the specifier is one of the devices
355-
deviceSearch=specifier;
356-
}
357-
}
358-
359-
var topFilteredResults = [];
360-
361-
if (allDevices.indexOf(deviceSearch)!=-1) { // this section has device sensitivity
362-
for (x=0; x<results.length; x++) {
363-
var params = String(results[x].ref);
364-
var paramDeviceCount=0;
365-
for (y=0; y<allDevices.length; y++) {
366-
if (params.indexOf(allDevices[y])>=0) {
367-
paramDeviceCount++;
368-
}
369-
}
370-
if (paramDeviceCount==0) { // does it have one of the allDevices in it?
371-
topFilteredResults.push(results[x]);
372-
}
373-
else { // check to see if it includes the deviceSearch term
374-
if (String(results[x].ref).indexOf(deviceSearch) >= 0) {
375-
topFilteredResults.push(results[x]);
376-
}
377-
}
378-
}
379-
}
380-
else { // this section does not have device sensitivity, do not filter by device
381-
// probably should filter by some "default" device, whatever is what people most likely want to see
382-
topFilteredResults=results;
383-
}
384-
return topFilteredResults;
385-
}
386-
387-
Docs.buildSearchResults = function(results, store) {
388-
var fiveResults = results.slice(0,5);
389-
390-
var niceResults = fiveResults.map(function(r) {
391-
var resultInfo = store[r.ref];
392-
var nr = {};
393-
nr.link = r.ref;
394-
nr.title = resultInfo.title;
395-
nr.device = resultInfo.device;
396-
nr.collection = Docs.titleize(resultInfo.collection);
397-
nr.pageTitle = resultInfo.pageTitle;
398-
nr.collectionClass = resultInfo.collection;
399-
return nr;
400-
});
401-
402-
var html = Handlebars.templates.search({results: niceResults});
403-
$('.search-results').append(html);
404-
};
405-
406252
Docs.toggleShowing = function() {
407253
$('span.popupLink, span.footnoteLink').on('click', function() {
408254
$(this).toggleClass('showing');

src/content/page-not-found.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ layout: page-not-found.hbs
1313
<div class="search">
1414
<div class="search-input-wrapper">
1515
<i class="ion-search"></i>
16-
<input class="search-box" type="text" placeholder="Search" value=""/>
16+
<input class="st-default-search-input" type="text" placeholder="Search" value=""/>
1717
</div>
1818
<div class="search-results">
1919
</div>

templates/layouts/api.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class='content-root'>
1111
<div class='menubar'>
1212

13-
<ul class="nav guide-menu">
13+
<ul class="nav guide-menu" data-swiftype-index="false">
1414
{{#each reference}}
1515
<li data-level="{{inc @index}}" class="guide-section {{#contains ../path.href section}}active-section{{/contains}}">
1616
<h3 class="guide-section-titles" >{{{titleize section}}}</h3>

templates/layouts/community.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<div class='content-root'>
1111
<div class='menubar'>
12-
<ul class="nav guide-menu">
12+
<ul class="nav guide-menu" data-swiftype-index="false">
1313
{{#each community}}
1414
<ul>
1515
<li class="top-level {{#page-equal ../path.href ../path.name path.href path.name}}active{{/page-equal}}">

templates/layouts/datasheet.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<div class='content-root'>
1111
<div class='menubar'>
12-
<ul class="nav guide-menu">
12+
<ul class="nav guide-menu" data-swiftype-index="false">
1313
{{#each datasheets}}
1414
<li data-level="{{inc @index}}" class="guide-section {{#contains ../path.href section}}active-section{{/contains}}">
1515
<h3 class="guide-section-titles" >{{{titleize section}}}</h3>

templates/layouts/faq.hbs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<div class='content-root'>
1111
<div class='menubar'>
12-
<ul class="nav guide-menu">
12+
<ul class="nav guide-menu" data-swiftype-index="false">
1313
{{#each faq}}
1414
<li data-level="{{inc @index}}" class="guide-section {{#contains ../path.href section}}active-section{{/contains}}">
1515
<h3 class="guide-section-titles" >{{{titleize section}}}</h3>

0 commit comments

Comments
 (0)