mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 13:46:19 +01:00
Docs: add basic search feature for install and API
This commit is contained in:
@@ -55,11 +55,11 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/docute@4/dist/docute.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/docute-google-analytics@1/dist/index.min.js"></script>
|
||||
<script>
|
||||
var docuteApiTitlePlugin = {
|
||||
const docuteApiTitlePlugin = {
|
||||
name: 'apiTitle',
|
||||
extend(api) {
|
||||
api.processMarkdown(function (md) {
|
||||
var title = api.store.getters.sidebarLinks
|
||||
const title = api.store.getters.sidebarLinks
|
||||
.filter(function (sidebarLink) {
|
||||
return sidebarLink.link === api.router.history.current.path
|
||||
})
|
||||
@@ -72,6 +72,37 @@
|
||||
});
|
||||
}
|
||||
};
|
||||
const docuteApiSearchPlugin = {
|
||||
name: 'apiSearch',
|
||||
extend(api) {
|
||||
api.enableSearch({
|
||||
handler: function (keyword) {
|
||||
if (keyword.trim().length > 2) {
|
||||
return fetch('/search-index.json')
|
||||
.then(function (res) {
|
||||
return res.json();
|
||||
})
|
||||
.then(function (entries) {
|
||||
const results = [];
|
||||
entries.forEach(function (entry) {
|
||||
if (entry.k.includes(keyword)) {
|
||||
results.push({
|
||||
title: entry.t,
|
||||
link: entry.l,
|
||||
description: entry.d,
|
||||
label: entry.l.startsWith("/api") ? "API" : "Install"
|
||||
});
|
||||
}
|
||||
})
|
||||
return results.slice(0, 3);
|
||||
})
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
new Docute({
|
||||
router: { mode: 'history' },
|
||||
logo: '<div style="display:flex;align-items:center">'
|
||||
@@ -85,7 +116,8 @@
|
||||
footer: '<a href="https://pixelplumbing.com/" target="_blank">pixelplumbing.com<a>',
|
||||
plugins: [
|
||||
docuteGoogleAnalytics('UA-13034748-12'),
|
||||
docuteApiTitlePlugin
|
||||
docuteApiTitlePlugin,
|
||||
docuteApiSearchPlugin
|
||||
],
|
||||
sourcePath: 'https://cdn.jsdelivr.net/gh/lovell/sharp@v0.25.2/docs',
|
||||
nav: [
|
||||
|
||||
Reference in New Issue
Block a user