Skip to content

Commit

Permalink
Built Open GoPro docs from Internal Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 5, 2024
1 parent 85c021c commit cf4fb03
Show file tree
Hide file tree
Showing 50 changed files with 36,930 additions and 21,778 deletions.
2 changes: 1 addition & 1 deletion assets/css/main.css

Large diffs are not rendered by default.

90 changes: 45 additions & 45 deletions assets/css/main.css.map

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions assets/css/main_spec.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions assets/js/_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $(document).ready(function () {
}

// Auto scroll sticky ToC with content
document.addEventListener("gumshoeActivate", function (event) {
const scrollTocToContent = function (event) {
var target = event.target;
var scrollOptions = { behavior: "auto", block: "nearest", inline: "start" };

Expand All @@ -75,7 +75,12 @@ $(document).ready(function () {
} else {
target.scrollIntoView(scrollOptions);
}
});
};

// Has issues on Firefox, whitelist Chrome for now
if (!!window.chrome) {
document.addEventListener("gumshoeActivate", scrollTocToContent);
}

// add lightbox class to all image links
$(
Expand Down Expand Up @@ -190,12 +195,23 @@ $(document).ready(function () {
var result = copyText(codeBlock.innerText);
// Restore the focus to the button
thisButton.focus();
if (result) {
if (thisButton.interval !== null) {
clearInterval(thisButton.interval);
}
thisButton.classList.add('copied');
thisButton.interval = setTimeout(function () {
thisButton.classList.remove('copied');
clearInterval(thisButton.interval);
thisButton.interval = null;
}, 1500);
}
return result;
};

if (window.enable_copy_code_button) {
document
.querySelectorAll(".page__content pre > code")
.querySelectorAll(".page__content pre.highlight > code")
.forEach(function (element, index, parentList) {
// Locate the <pre> element
var container = element.parentElement;
Expand All @@ -206,7 +222,7 @@ $(document).ready(function () {
var copyButton = document.createElement("button");
copyButton.title = "Copy to clipboard";
copyButton.className = "clipboard-copy-button";
copyButton.innerHTML = '<span class="sr-only">Copy code</span><i class="far fa-copy"></i>';
copyButton.innerHTML = '<span class="sr-only">Copy code</span><i class="far fa-fw fa-copy"></i><i class="fas fa-fw fa-check copied"></i>';
copyButton.addEventListener("click", copyButtonEventListener);
container.prepend(copyButton);
});
Expand Down
144 changes: 91 additions & 53 deletions assets/js/lunr/lunr-en.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// Create combined search store
let store = jekyllStore.concat(specStore);

// Build the store
var idx = lunr(function () {
let idx = lunr(function () {
this.field('title');
this.field('excerpt');
this.field('categories'); // Not currently used
this.field('tags'); // Not currently used
this.ref('id');
this.metadataWhitelist = ['position'];

for (var item in store) {
for (let item in store) {
this.add({
title: store[item].title,
excerpt: store[item].excerpt,
categories: store[item].categories,
tags: store[item].tags,
id: item,
});
}
Expand All @@ -23,68 +22,107 @@ const SNIPPET_LEN = 200;
$(document).ready(function () {
$('input#search').on('keyup', function () {
// Build and perform the search
var resultdiv = $('#results');
var query = $(this).val().toLowerCase();
var results = idx.query(function (q) {
let resultdiv = $('#results');
let query = $(this).val().toLowerCase();
let results = idx.query(function (q) {
// Biggest boost goes to complete phrase in title
q.term(query, { fields: ['title'], boost: 100 });
// Actual search term in excerpt with no wildcards get a boost
q.term(query, { fields: ['excerpt'], boost: 50 });
// Now add terms for individual words
query.split(lunr.tokenizer.separator).forEach(function (term) {
// Actual search term with no wildcards get a big boost
q.term(term, { fields: ['excerpt'], boost: 100 });
// Term with wildcards gets a smaller boost
// Actual search term in title with no wildcards get a boost
q.term(term, { fields: ['title'], boost: 10 });
// Title Term with wildcards gets a smaller boost
if (query.lastIndexOf(' ') != query.length - 1) {
q.term(term, {
fields: ['excerpt'],
fields: ['title'],
wildcard: lunr.Query.wildcard.TRAILING,
boost: 10,
boost: 5,
});
}
// Add fuzziness of 1 character change with no boost
if (term != '') {
q.term(term, { fields: ['excerpt'], editDistance: 1 });
// Actual search term in excerpt with no wildcards get a boost
q.term(term, { fields: ['excerpt'], boost: 5 });
// excerpt Term with wildcards gets a smaller boost
if (query.lastIndexOf(' ') != query.length - 1) {
q.term(term, {
fields: ['title'],
wildcard: lunr.Query.wildcard.TRAILING,
boost: 1,
});
}
// TODO currently not using any fuzziness
// Add fuzziness of 1 character change with no boost
// if (term != '') {
// q.term(term, { fields: ['excerpt'], editDistance: 1 });
// }
});
});
// Build and display the results
resultdiv.empty();
resultdiv.prepend(
'<p class="results__found">' + results.length + ' Result(s) found</p>'
);
for (var item in results) {
var ref = results[item].ref;
var excerpt = store[ref].excerpt;
var searchitem =
'<div class="list__item">' +
'<article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">' +
'<h2 class="archive__item-title" itemprop="headline">' +
'<a href="' +
store[ref].url +
'" rel="permalink">' +
store[ref].title +
'</a>' +
'</h2>';
for (metadata_item in results[item].matchData.metadata) {
var metadata = results[item].matchData.metadata[metadata_item];
for (position_item in metadata.excerpt['position']) {
var position = metadata.excerpt['position'][position_item];
var match_start = position[0];
var match_end = match_start + position[1];
var snippet_start = Math.max(0, match_start - SNIPPET_LEN / 2);
var snippet_end = Math.min(
match_end - match_start + snippet_start + SNIPPET_LEN,
excerpt.length
);
searchitem +=
'<p class="archive__item-excerpt" itemprop="description">...' +
excerpt.slice(snippet_start, match_start) +
'<mark>' +
excerpt.slice(match_start, match_end) +
'</mark>' +
excerpt.slice(match_end, snippet_end) +
'...</p><br>';
}
}
searchitem += '</article></div>';
resultdiv.append(searchitem);

function isResultAnOperation(result) {
return (
store[result.ref].tags.includes('bleOperation') ||
store[result.ref].tags.includes('httpOperation')
);
}

// Split into operation and other results(
let operationResults = results.filter((result) => isResultAnOperation(result));
let jekyllResults = results.filter((result) => !isResultAnOperation(result));

function displayResults(results) {
results.forEach((result) => {
let ref = result.ref;
let excerpt = store[ref].excerpt;
let searchitem =
'<div class="list__item">' +
'<article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">' +
'<h2 class="archive__item-title" itemprop="headline">' +
'<a href="' +
store[ref].url +
'" rel="permalink">' +
store[ref].title +
'</a>' +
'</h2>';

// For each match in this result...
for (const metadata of Object.values(result.matchData.metadata)) {
// TODO what is going on here? It's not working for some results, presumably titles.
if (metadata.excerpt) {
for (position_item in metadata.excerpt['position']) {
let position = metadata.excerpt['position'][position_item];
let match_start = position[0];
let match_end = match_start + position[1];
let snippet_start = Math.max(
0,
match_start - SNIPPET_LEN / 2
);
let snippet_end = Math.min(
match_end - match_start + snippet_start + SNIPPET_LEN,
excerpt.length
);
searchitem +=
'<p class="archive__item-excerpt" itemprop="description">...' +
excerpt.slice(snippet_start, match_start) +
'<mark>' +
excerpt.slice(match_start, match_end) +
'</mark>' +
excerpt.slice(match_end, snippet_end) +
'...</p><br>';
}
}
};
searchitem += '</article></div>';
resultdiv.append(searchitem);
});
}

displayResults(operationResults);
displayResults(jekyllResults);
});
});
Loading

0 comments on commit cf4fb03

Please sign in to comment.