Skip to content

Added search by topic following previous format. #6083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions search2.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
</p>

<div class="row" id="search-form">
<div class="col-md-5">
<div class="col-md-3">
<div class="form-group">
<label for="title">Search</label>
<input type="text" class="form-control" id="title" placeholder="Search Materials" oninput="onInputDebounced()">
</div>
</div>

<div class="col-md-3">
<div class="col-md-2">
<div class="form-group">
<label for="type">Type</label>
<select class="form-control" id="type">
Expand All @@ -32,7 +32,7 @@
</div>
</div>

<div class="col-md-3">
<div class="col-md-2">
<div class="form-group">
<label for="level">Level</label>
<select class="form-control" id="level">
Expand All @@ -43,6 +43,30 @@
</select>
</div>
</div>

<div class="col-md-3">
<div class="form-group">
<label for="topic">Topic</label>
<select class="form-control" id="topic">
<!-- Manually add a few options -->
<option value="Any">Any</option>
<option value="GTN FAQ">GTN FAQ</option>
<option value="Galaxy FAQ">Galaxy FAQ</option>
<!-- Automatically add other topics with exclusions -->
{% assign sorted_topics = site | list_topics_ids | sort %}
{% assign exclude_topics = "SARS-CoV-2,ELIXIR,GMOD,One Health,Plants" | split: "," %}
{% for topic_name in sorted_topics %}
{% assign topic = site.data[topic_name] %}
{% unless exclude_topics contains topic.name or exclude_topics contains topic.title %}
{% if topic.draft != true or jekyll.environment != "production" %}
<option value="{{ topic.title }}">{{ topic.title }}</option>
{% endif %}
{% endunless %}
{% endfor %}
</select>
</div>
</div>

<div class="col-md-1">
<button class="btn btn-primary" onclick="search()">Search</button>
</div>
Expand Down Expand Up @@ -119,15 +143,16 @@
const textQuery = document.getElementById("title").value
const typeFilter = document.getElementById("type").value
const levelFilter = document.getElementById("level").value
const topicFilter = document.getElementById("topic").value

if (previousSearch == `${textQuery} ${typeFilter} ${levelFilter}`) {
if (previousSearch == `${textQuery} ${typeFilter} ${levelFilter} ${topicFilter}`) {
console.log("Skipping search for the same query")
return
}

// Include search term in page title
document.getElementsByTagName("title")[0].innerText = `${textQuery} | GTN Materials Search`
console.log(`Searching! ${textQuery} ${typeFilter} ${levelFilter}`)
console.log(`Searching! ${textQuery} ${typeFilter} ${levelFilter} ${topicFilter}`)

// Which should be hidden

Expand All @@ -144,6 +169,9 @@
return true;
}
}
if (topicFilter != "Any" && row.children[3].innerText != topicFilter) {
return true;
}
return false;
});

Expand All @@ -152,13 +180,13 @@
// Hide the rest
to_hide.map(r => r.style.display = "none");

previousSearch = `${textQuery} ${typeFilter} ${levelFilter}`
previousSearch = `${textQuery} ${typeFilter} ${levelFilter} ${topicFilter}`

if(typeof plausible !== 'undefined'){
// Plausible may be undefined (script blocked)
// or it may be defined, but opted-out (select box/DNT),
// which means `plausible()` will work but not send data, *nor* execute the callback.
plausible('Search', {props: {query: textQuery, type: typeFilter, level: levelFilter}})
plausible('Search', {props: {query: textQuery, type: typeFilter, level: levelFilter, topic: topicFilter}})
}
}

Expand Down