Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 1, 2017. It is now read-only.

Sync changes from upstream repository#920

Merged
hubot merged 1 commit intomasterfromupdate-1449454305
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes fromall 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
6 changes: 5 additions & 1 deletion.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,10 +7,14 @@
/vendor/bundle/
/node_modules/

# bower brings in *a lot* of files
/assets/vendor/lunr.js/*
!/assets/vendor/lunr.js/lunr.js
!/assets/vendor/lunr.js/lunr.min.js

output
tmp
.DS_Store
.bundle
crash.log
npm-debug.log
static/search-index.json
2 changes: 1 addition & 1 deletionGemfile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,6 @@ ruby '2.2.3'

gem 'nanoc', '~> 4.0'
gem 'nanoc-conref-fs', '~> 0.5'
gem 'nokogiri', '~> 1.6.0'

# rendering
gem 'nanoc-html-pipeline', '0.3.3'
Expand All@@ -17,6 +16,7 @@ gem 'page-toc-filter', '~> 0.0.1'
gem 'builder', '~> 3.2'

group :development do
gem 'nokogiri', '~> 1.6.0'
gem 'rake', '10.3.2'
gem 'awesome_print', '1.6.1'
end
Expand Down
11 changes: 8 additions & 3 deletionsRules
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,7 @@
# * The order of rules is important: for each item, only the first matching
# rule is applied.

# Reset search-index by deleting it every time
preprocessdo
File.delete("output/search-index.json")ifFile.exists?("output/search-index.json")
create_individual_blog_pages
generate_redirects(config[:redirects])
end
Expand All@@ -25,7 +23,6 @@ compile '/integrations-directory/*' do
end

compile'/v3{.*,/**/*}'do
filter:search
filter:erb
filter:html_pipeline,@config[:pipeline_config]
filter:enterprise_only_filter
Expand All@@ -52,6 +49,10 @@ compile '/webhooks/**/*' do
layout(item[:layout] ?"/#{item[:layout]}.*" :'/webhooks.*')
end

compile'/search/search-index.json'do
filter:erb
end

compile'/**/*'do
filter:erb
filter:html_pipeline,@config[:pipeline_config]
Expand All@@ -62,6 +63,10 @@ route '/changes.atom' do
'/changes.atom'
end

route'/search/search-index.json'do
item.identifier.to_s
end

route'/**/index.*'do
item.identifier.without_ext +'.html'
end
Expand Down
37 changes: 20 additions & 17 deletionsassets/javascripts/search.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
$(function() {
var searchIndex,
searchHits;
searchHits,
searchWorker = new Worker("/assets/javascripts/search_worker.js");

$('.help-search .search-box').focus(function(){
$(this).css('background-position','0px -25px')
Expand All@@ -17,15 +18,22 @@ $(function() {
if (localStorage['searchIndex']) {
searchIndex = JSON.parse(localStorage['searchIndex']);

if (localStorageHasExpired())
if (localStorageHasExpired()) {
loadSearchIndex();
}
else {
searchIndex.type = "index";
searchWorker.postMessage(searchIndex);
}
} else {
loadSearchIndex();
}

function loadSearchIndex() {
$.getJSON('/assets/search-index.json', function(data) {
searchIndex = data["pages"];
$.getJSON('/search/search-index.json', function(data) {
data.type = { index: true };
searchWorker.postMessage(data);
searchIndex = data;
localStorage['searchIndex'] = JSON.stringify(searchIndex);
localStorage['updated'] = new Date().getTime();
});
Expand DownExpand Up@@ -118,22 +126,17 @@ $(function() {
function searchForString(searchString) {
searchHits = [];
searchString = searchString.toLowerCase();
searchWorker.postMessage({ query: searchString, type: "search" })
}

// Search for string in all pages
for (var i = 0; i < searchIndex.length; i++) {
var page = searchIndex[i];

// Add the page to the array of hits if there's a match
if (page.title.toLowerCase().indexOf(searchString) !== -1) {
searchHits.push(page);
}
searchWorker.addEventListener("message", function (e) {
if (e.data.type.search) {
renderResultsForSearch(e.data.query, e.data.results);
}

renderResultsForSearch(searchString);
}
});

// Update the UI representation of the search hits
function renderResultsForSearch(searchString){
function renderResultsForSearch(searchString, searchHits){
$("#search-results").empty();

// Check if there are any results. If not, show placeholder and exit
Expand All@@ -146,7 +149,7 @@ $(function() {
for (var i = 0; i < Math.min(searchHits.length, 8); i++) {
var page = searchHits[i];

$('<li class="result"><a href="' + page.url + '"><em>' + page.title + '</em><small>' + page.section + '</small></a></li>').appendTo("#search-results");
$('<li class="result"><a href="' + page.url + '"><em>' + page.title + '</em></a></li>').appendTo("#search-results");
}

// Select the first alternative
Expand Down
58 changes: 58 additions & 0 deletionsassets/javascripts/search_worker.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
importScripts('lunr.min.js');

// create lunr.js search index specifying that we want to index the title and body fields of documents.
var lunr_index = lunr(function() {
this.field('title', { boost: 10 });
this.field('body');
this.ref('id');
}),
entries;

onmessage = function (oEvent) {

populateIndex = function(data) {
// format the raw json into a form that is simpler to work with
this.entries = data.map(this.createEntry).filter(function(n){ return n !== undefined });
this.entries.forEach(function(entry) {
if (entry !== null)
this.lunr_index.add(entry);
});

postMessage({type: {indexed: true}});
};

decodeHtmlEntity = function(str) {
return str.replace(/&#(\d+);/g, function(match, dec) {
return String.fromCharCode(dec);
});
};

createEntry = function(entry, entry_id) {
if (entry.title === undefined)
return undefined;
entry.id = entry_id + 1;
entry.title = decodeHtmlEntity(entry.title);
return entry;
};

search = function(data) {
var entries = this.entries;

var results = lunr_index
.search(data.query)
.map(function(result) {
return entries.filter(function(entry) { return entry.id === parseInt(result.ref, 10); })[0];
})
.filter(function (result) {
return typeof result !== 'undefined';
});

postMessage({ query: data.query, results: results, type: { search: true } });
}

// if we're asked to index, index! else, search
if (oEvent.data.type == "index")
populateIndex(oEvent.data);
else
search(oEvent.data);
};
Loading

[8]ページ先頭

©2009-2025 Movatter.jp