Added search using elasticlunr.
This commit is contained in:
parent
205a096654
commit
32ebfc6176
7 changed files with 71 additions and 41 deletions
|
|
@ -2,9 +2,8 @@
|
||||||
<div id="linksBox">
|
<div id="linksBox">
|
||||||
<h1 id="title">neoBeta</h1>
|
<h1 id="title">neoBeta</h1>
|
||||||
<ul id="headerLinks">
|
<ul id="headerLinks">
|
||||||
<a href="/index.html">home</a> -
|
<a href="/">home</a> -
|
||||||
<a href="/index.html">mods</a> -
|
<a href="/search">search</a>
|
||||||
<a href="/index.html">plugins</a>
|
|
||||||
</ul>
|
</ul>
|
||||||
<p id="credits">Adrian Victor, 2025 (<a href="https://git.disroot.org/adrianvictor/neoBeta">Unlicense</a>)</p>
|
<p id="credits">Adrian Victor, 2025 (<a href="https://git.disroot.org/adrianvictor/neoBeta">Unlicense</a>)</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
38
assets/search.js
Normal file
38
assets/search.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
fetch('/search_index.json')
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(data => {
|
||||||
|
const idx = elasticlunr.Index.load(data);
|
||||||
|
const docs = idx.documentStore.docs;
|
||||||
|
console.log(Object.values(docs)[0])
|
||||||
|
const searchInput = document.getElementById('search');
|
||||||
|
const out = document.getElementById('searchResults');
|
||||||
|
const filterSelect = document.getElementById('searchMode');
|
||||||
|
|
||||||
|
function runSearch(q, tags) {
|
||||||
|
return idx.search(q, { expand: true })
|
||||||
|
.map(r => docs[r.ref] )
|
||||||
|
.filter(d => tags === 'all' || d.tags.includes(tags));
|
||||||
|
}
|
||||||
|
|
||||||
|
function render(doc) {
|
||||||
|
return `<div>
|
||||||
|
<img class="searchItemImage" src="${doc.image}">
|
||||||
|
<a class="searchItemTitle" href="${doc.url}">${doc.title}</a>
|
||||||
|
<p class="searchItemDescription">${doc.subtitle}</p>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
const q = searchInput.value.trim();
|
||||||
|
if (!q) {
|
||||||
|
out.innerHTML = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = runSearch(q, filterSelect.value);
|
||||||
|
out.innerHTML = results.map(render).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
searchInput.addEventListener('input', update);
|
||||||
|
filterSelect.addEventListener('change', update);
|
||||||
|
});
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
|
|
@ -86,6 +87,10 @@ code {
|
||||||
margin-bottom: auto;
|
margin-bottom: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.searchItemImage {
|
||||||
|
height: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
#featured {
|
#featured {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
border: 2px solid greenyellow;
|
border: 2px solid greenyellow;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import elasticlunr from 'elasticlunr';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
let allPlugins = [];
|
let allPlugins = [];
|
||||||
let lunrIndex = null;
|
|
||||||
|
|
||||||
export default function (eleventyConfig) {
|
export default function (eleventyConfig) {
|
||||||
eleventyConfig.addPassthroughCopy("projects/**/*.png");
|
eleventyConfig.addPassthroughCopy("projects/**/*.png");
|
||||||
|
|
@ -11,11 +10,13 @@ export default function (eleventyConfig) {
|
||||||
eleventyConfig.addPassthroughCopy("assets");
|
eleventyConfig.addPassthroughCopy("assets");
|
||||||
|
|
||||||
eleventyConfig.addCollection('searchIndex', (collectionApi) => {
|
eleventyConfig.addCollection('searchIndex', (collectionApi) => {
|
||||||
const result = collectionApi.getFilteredByTag("plugin").map(item => {
|
const result = collectionApi.getAll().map(item => {
|
||||||
return {
|
return {
|
||||||
title: item.data.projectName,
|
title: item.data.projectName,
|
||||||
subtitle: item.data.projectSubtitle || "",
|
subtitle: item.data.projectSubtitle || "",
|
||||||
url: item.url
|
url: item.url,
|
||||||
|
image: (item.data.logoName && item.data.logoExtension) ? item.url + item.data.logoName + '.' + item.data.logoExtension : '',
|
||||||
|
tags: item.data.tags
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ export default function (eleventyConfig) {
|
||||||
this.setRef('url');
|
this.setRef('url');
|
||||||
this.addField('title', { boost: 2 });
|
this.addField('title', { boost: 2 });
|
||||||
this.addField('subtitle');
|
this.addField('subtitle');
|
||||||
|
this.addField('tags')
|
||||||
|
|
||||||
allPlugins.forEach(doc => this.addDoc(doc));
|
allPlugins.forEach(doc => this.addDoc(doc));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
layout: "project.njk"
|
layout: "project.njk"
|
||||||
projectName: "Aboukkit"
|
projectName: "Aboukkit"
|
||||||
projectSubtitle: "Adds a simple way to add custom commands with custom responses to your server."
|
projectSubtitle: "A simple way to add custom commands with custom responses to your server."
|
||||||
projectAuthor: "tenkuma"
|
projectAuthor: "tenkuma"
|
||||||
projectDownloadLink: "https://modrinth.com/plugin/aboukkit/versions"
|
projectDownloadLink: "https://modrinth.com/plugin/aboukkit/versions"
|
||||||
backgroundImageSize: "cover"
|
backgroundImageSize: "cover"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
layout: "project.njk"
|
layout: "project.njk"
|
||||||
projectName: "Ghosts 'n Stuff"
|
projectName: "Ghosts 'n Stuff"
|
||||||
projectSubtitle: "Adds a simple way to add custom commands with custom responses to your server."
|
projectSubtitle: "Miscellaneous additions to your Minecraft server."
|
||||||
projectAuthor: "tenkuma"
|
projectAuthor: "tenkuma"
|
||||||
projectDownloadLink: "https://modrinth.com/plugin/ghosts/versions"
|
projectDownloadLink: "https://modrinth.com/plugin/ghosts/versions"
|
||||||
backgroundImageSize: "cover"
|
backgroundImageSize: "cover"
|
||||||
|
|
@ -10,7 +10,7 @@ logoExtension: "png"
|
||||||
tags: "plugin"
|
tags: "plugin"
|
||||||
---
|
---
|
||||||
|
|
||||||
This plugins aims to use stuff from my library that would not fit into any plugin (or not in the way presented here) that has ~~a lot~~ (WIP) of random stuff. Everything should be togglable in the config.
|
This plugins was made to use stuff from my library that would not fit into any plugin (or not in the way presented here) that has ~~a lot~~ (WIP) of random stuff. Everything should be togglable in the config.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- **RainbowChat:** Rainbow color code.
|
- **RainbowChat:** Rainbow color code.
|
||||||
|
|
|
||||||
48
search.html
48
search.html
|
|
@ -1,37 +1,23 @@
|
||||||
---
|
---
|
||||||
layout: "base.njk"
|
layout: "base.njk"
|
||||||
---
|
---
|
||||||
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/elasticlunr/0.9.6/elasticlunr.min.js"></script>
|
||||||
|
<script src="/assets/search.js" defer></script>
|
||||||
|
|
||||||
<input type="text" id="search" placeholder="Search..." />
|
<style>
|
||||||
<ul id="results"></ul>
|
main {
|
||||||
|
display: flex;
|
||||||
<script
|
flex-direction: column;
|
||||||
type="text/javascript"
|
gap: 1em;
|
||||||
src="https://cdnjs.cloudflare.com/ajax/libs/elasticlunr/0.9.6/elasticlunr.min.js"
|
justify-content: center;
|
||||||
></script>
|
|
||||||
<script>
|
|
||||||
fetch('/search_index.json')
|
|
||||||
.then(r => r.json())
|
|
||||||
.then(data => {
|
|
||||||
const idx = elasticlunr.Index.load(data);
|
|
||||||
const docs = idx.documentStore.docs;
|
|
||||||
const searchInput = document.getElementById('search');
|
|
||||||
const out = document.getElementById('results');
|
|
||||||
|
|
||||||
searchInput.addEventListener('input', function () {
|
|
||||||
const q = this.value.trim();
|
|
||||||
if (!q) {
|
|
||||||
out.innerHTML = '';
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
const items = idx.search(q).map(r => {
|
<div style="display: flex; gap: .5em;">
|
||||||
const doc = docs[r.ref];
|
<input type="text" id="search" placeholder="Search..." style="flex-grow: 1;"/>
|
||||||
return `<li><a href="${doc.url}">${doc.title}</a></li>`;
|
<select name="Search mode" id="searchMode">
|
||||||
});
|
<option value="plugin" selected>Plugins</option>
|
||||||
|
<option value="mod">Mods</option>
|
||||||
out.innerHTML = items.join('');
|
</select>
|
||||||
});
|
</div>
|
||||||
|
<div id="searchResults" style="display: flex; gap: .5em; flex-direction: column;"></div>
|
||||||
});
|
|
||||||
</script>
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue