Get search working

This commit is contained in:
redfast00 2020-09-15 21:44:23 +02:00
parent 205d1eb770
commit 039b5935f9
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
3 changed files with 12 additions and 43 deletions

View file

@ -5,7 +5,7 @@
<button type="submit">Zoek!</button>
</form>
</div>
<div id="search_wrapper" class="search__result"></div>
<div id="search_wrapper" class="fancy_link_container"></div>
</div>
<script src="https://unpkg.com/lunr/lunr.js"></script>
@ -81,30 +81,13 @@ function ready() {
function render_results(div, partials) {
const create_wrapper= document.createElement('div');
for(let partial of partials) {
const html = `<div class="link" onclick="window.location.href = '${partial.url}'">
<div class="link__img">
<img src="https://dsa.ugent.be/api/verenigingen/${partial.abbrev}/logo?size=small" alt="${partial.titel}">
</div>
<div class="link__content">
<h3 class="link__title">
${partial.titel} (${partial.kind})
</h3>
<p class="link__text">
${partial.text}
</p>
</div>
</div>`;
if(html) {
create_wrapper.innerHTML = html;
div.appendChild(create_wrapper.firstChild);
}
create_wrapper.innerHTML = partial;
div.appendChild(create_wrapper.firstChild);
}
}
const documents = <%= CreateFullTextIndex.new(@items.find_all("**/verenigingen/*") + @items.find_all("**/konventen/*")).call.to_json %>;
const partials = <%= Hash[(partial_konventen + partial_verenigingen).map { |x| [x[:url], x] }].to_json %>;
partials = <%= to_partials_search(all_groups()) %>;
const index = lunr(function () {
this.field('id', {boost: 15});
this.field('title', {boost: 10});

View file

@ -435,8 +435,9 @@ fieldset p label input {
gap: 20px;
padding: 0.5rem;
max-width: 50%;
max-width: 700px;
flex-grow: 1;
min-width: 20%;
}
.fancy_link_container {
@ -445,6 +446,7 @@ fieldset p label input {
gap: 20px;
flex-wrap: wrap;
justify-content: space-evenly;
}
.link:hover {

View file

@ -26,28 +26,12 @@ module SearchHelper
end
end
def partial_verenigingen
@items.find_all("**/verenigingen/*").map do |x|
{
titel: x[:titel] || x[:naam],
url: x.path,
konvent: x[:konvent],
abbrev: abbreviation(x),
kind: "vereniging",
text: text_segment(x.compiled_content)
}
end
end
def to_partials_search(items)
my_hash = {}
def partial_konventen
@items.find_all("**/konventen/*").map do |x|
{
titel: x[:titel] || x[:naam],
url: x.path,
abbrev: abbreviation(x),
kind: "konvent",
text: text_segment(x.compiled_content)
}
items.each do |item|
my_hash[(item.path)] = (render '/partials/pretty_link.*', :item => item).gsub("\n", '')
end
my_hash.to_json
end
end