Skip to content

Commit 0c4f4aa

Browse files
Rct225 search fellows (#2495)
* Search functionality for fellows page * updating head.html to allow fellow page to include javascript for search * Javascript to provide search on fellows pages * Adding search box and frontmatter to include search functionality * Small tweak to old fellows project to add a project_title * style: pre-commit fixes * drop the ".json" suffix, add permalink to have json in proper spot and layout: null to avoid layout from jekyll --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 080fb04 commit 0c4f4aa

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

_fellows/2019/RaghavKansal.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ photo: /assets/images/team/fellows-2019/Raghav-Kansal.jpg
1212
institution: University of California, San Diego
1313
e-mail: NoEmailYet
1414
focus-area: ia
15+
project_title: Fast HGCAL Simulation with Graph Network
1516
project_goal: >
1617
High granular calorimeters will be the biggest novelty of the CMS Phase II upgrade
1718
and, in general, for the next generation of collider experiments. This kind of detectors

_includes/head.html

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
{% if page.layout == "focus-area" or page.mermaid %}
2828
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js" integrity="sha384-6qzFcd+IG/OgXej451KTI/pbrex++8tdIfKsNF+gDVx1gfkmIG7z+uIIspvxAP7u" crossorigin="anonymous"></script>
2929
{% endif %}
30+
{% if page.minisearch %}
31+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/index.min.js" integrity="sha384-IniM+QBDckT3t/xRvZUiUyns2i4VQ1OFdqa5l/YN7RBCzb/BtLOoN6PDsAuACzRP" crossorigin="anonymous"></script>
32+
<script src="{{ '/assets/js/search_fellows.js' | append: site.github.build_revision | relative_url }}" integrity="sha384-W3Rovhs48ZFf1GPh9ckF2J9PRIljwtbrsnmxSwkjRWlItwFfpdLpRPtGOW/9eJ0+"></script>
33+
{% endif %}
3034

3135
<!-- Global site tag (gtag.js) - Google Analytics -->
3236
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-127196353-1"></script>

assets/js/search_fellows.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const ERROR_ELEMENT_ID = "error-message";
2+
3+
function displayErrorMessage(message) {
4+
const errorElement = document.getElementById(ERROR_ELEMENT_ID);
5+
if (errorElement) {
6+
errorElement.textContent = message;
7+
errorElement.style.display = "block";
8+
}
9+
}
10+
11+
async function getLiveData() {
12+
try {
13+
const response = await fetch("../../fellows_search.json", { mode: "cors" });
14+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
15+
return await response.json();
16+
} catch (error) {
17+
console.error("Error fetching or processing data:", error);
18+
displayErrorMessage("Failed to load data. Please try again later.");
19+
return null;
20+
}
21+
}
22+
23+
async function main() {
24+
const data = await getLiveData();
25+
if (!data) return;
26+
27+
const input = document.querySelector("input[type=search]");
28+
const container = document.createElement("div");
29+
container.id = "search-results";
30+
input.after(container);
31+
32+
const miniSearch = new MiniSearch({
33+
fields: ["name", "projects"],
34+
extractField: (doc, field) =>
35+
field === "projects"
36+
? doc.projects.map((p) => p.name).join(" ")
37+
: doc[field],
38+
});
39+
miniSearch.addAll(data);
40+
41+
input.addEventListener("input", (event) => {
42+
const query = event.target.value;
43+
const results = miniSearch.search(query);
44+
const findings = results.map((result) => {
45+
const entry = data.find((e) => e.id === result.id);
46+
return {
47+
id: entry.id,
48+
name: entry.name,
49+
url: entry.url,
50+
projects: entry.projects,
51+
};
52+
});
53+
54+
const list = document.createElement("ul");
55+
findings.forEach((finding) => {
56+
const item = document.createElement("li");
57+
const link = document.createElement("a");
58+
const dl = document.createElement("dl");
59+
finding.projects.forEach((project) => {
60+
const projectNameDt = document.createElement("dt");
61+
projectNameDt.appendChild(document.createTextNode("Project:"));
62+
const projectNameDd = document.createElement("dd");
63+
projectNameDd.appendChild(document.createTextNode(project.name));
64+
const projectMentorDt = document.createElement("dt");
65+
projectMentorDt.appendChild(document.createTextNode("Mentor(s):"));
66+
const projectMentorDd = document.createElement("dd");
67+
projectMentorDd.appendChild(
68+
document.createTextNode(project.mentors.join(", ")),
69+
);
70+
dl.appendChild(projectNameDt);
71+
dl.appendChild(projectNameDd);
72+
dl.appendChild(projectMentorDt);
73+
dl.appendChild(projectMentorDd);
74+
});
75+
76+
link.setAttribute("href", finding.url);
77+
link.appendChild(document.createTextNode(finding.name));
78+
item.appendChild(link);
79+
item.appendChild(dl);
80+
list.append(item);
81+
});
82+
83+
container.replaceChildren(list);
84+
});
85+
}
86+
87+
main().catch((error) => {
88+
console.error("Error loading data:", error);
89+
displayErrorMessage("Failed to load data. Please try again later.");
90+
});

fellows_search

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
permalink: /fellows_search.json
3+
layout: null
4+
---
5+
[
6+
{% assign id = 0 %}
7+
{% for post in site.fellows %}
8+
{% assign id = id | plus: 1 %}
9+
{
10+
"id" : {{ id }},
11+
"name" : "{{ post.fellow-name }}",
12+
"url" : "{{ site.url }}{{ post.permalink }}",
13+
"projects" : [
14+
{% if post.projects.size > 0 %}
15+
{% for project in post.projects %}
16+
{
17+
"name" : "{{ project.project_title | strip }}",
18+
"mentors" : [
19+
{% for mentor in project.mentors %}
20+
"{{ mentor }}"{% unless forloop.last %},{% endunless %}
21+
{% endfor %}
22+
]
23+
} {% unless forloop.last %},{% endunless %}
24+
{% endfor %}
25+
{% else %}
26+
{
27+
"name" : "{{ post.project_title | strip }}",
28+
"mentors" : [
29+
{% for mentor in post.mentors %}
30+
"{{ mentor }}"{% unless forloop.last %},{% endunless %}
31+
{% endfor %}
32+
]
33+
}
34+
{% endif %}
35+
]
36+
} {% unless forloop.last %},{% endunless %}
37+
38+
{% endfor %}
39+
]

pages/fellows.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
permalink: /fellows.html
33
layout: default
44
title: IRIS/HEP Fellows Program
5+
minisearch: true
56
---
67

78
# IRIS-HEP Fellows Program
@@ -27,6 +28,10 @@ We are preparing to announce the opening for the [2025 Fellows program](/fellows
2728

2829
The directions for adding a project can be found in the repository.
2930

31+
## Search for Fellows or Projects:
32+
<!-- <label for="site-search">Search for Fellows or Projects:</label> -->
33+
<input type="search" id="site-search" name="q" />
34+
3035
{% assign fellows = site.fellows | last_name_sort: "fellow-name"
3136
| reverse
3237
| iris_hep_fellow_sort

0 commit comments

Comments
 (0)