2020-03-26 12:57:10 -06:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
// Algolia search
|
|
|
|
docsearch({
|
|
|
|
apiKey: '14275a785f6ebd31d162f9d2d8fc0125',
|
|
|
|
indexName: 'caddyserver',
|
|
|
|
inputSelector: '#search',
|
2020-03-26 13:00:57 -06:00
|
|
|
debug: false // Set debug to true if you want to inspect the dropdown
|
2020-03-26 12:57:10 -06:00
|
|
|
});
|
|
|
|
});
|
2020-07-16 15:51:46 -06:00
|
|
|
|
|
|
|
const caddyImportPath = 'github.com/caddyserver/caddy/v2';
|
|
|
|
|
|
|
|
function isStandard(packagePath) {
|
|
|
|
return packagePath.startsWith(caddyImportPath);
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:26:35 -06:00
|
|
|
function truncate(str, maxLen) {
|
2020-07-16 15:51:46 -06:00
|
|
|
if (!str) return "";
|
2021-05-25 17:26:35 -06:00
|
|
|
str = str.trim();
|
|
|
|
let firstPeriod = str.match(/\.(\s|$)/); // first dot not in the middle of a word, or at end of string
|
|
|
|
let terminate = firstPeriod ? firstPeriod.index+1 : str.length;
|
|
|
|
str = str.substring(0, terminate);
|
|
|
|
if (str.length <= maxLen) {
|
|
|
|
return str;
|
2020-07-16 15:51:46 -06:00
|
|
|
}
|
2021-05-25 17:26:35 -06:00
|
|
|
return str+"...";
|
2020-07-16 15:51:46 -06:00
|
|
|
}
|
2021-05-25 17:26:35 -06:00
|
|
|
|
|
|
|
function moduleDocsPreview(mod, maxLen) {
|
|
|
|
if (!mod || !mod.docs) return "";
|
|
|
|
let short = truncate(mod.docs, maxLen);
|
|
|
|
if (short.indexOf(mod.name) === 0) {
|
|
|
|
short = short.substr(mod.name.length).trim();
|
|
|
|
}
|
|
|
|
return short;
|
|
|
|
}
|