Skip to content

Commit

Permalink
clean up #2, + add title to entries
Browse files Browse the repository at this point in the history
  • Loading branch information
YueSteveYin committed Jul 22, 2024
1 parent 737e401 commit 444c286
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 48 deletions.
42 changes: 29 additions & 13 deletions assets/js/utils/search-people.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Utility function for creating a delay
const asyncSleep = async (ms = 100) => {
return new Promise((r) => setTimeout(r, ms));
return new Promise((resolve) => setTimeout(resolve, ms));
};

let currentSearchID = 0;

// Debounced search function to prevent excessive API calls
// See https://github.com/CloudCannon/pagefind/issues/441
async function debouncedSearch(
pf,
Expand All @@ -12,31 +14,36 @@ async function debouncedSearch(
debounceTimeoutMs = 300,
) {
if (
options.filters.relevantCourses.length == 0 &&
options.filters.researchAreas.length == 0
options.filters.relevantCourses.length === 0 &&
options.filters.researchAreas.length === 0
) {
const searchResult = await pf.search(term);
return searchResult;
}

options.filters.relevantCourses = options.filters.relevantCourses.map(
(course) => course.toLowerCase(),
);
options.filters.researchAreas = options.filters.researchAreas.map((area) =>
area.toLowerCase(),
);

const thisSearchID = ++currentSearchID;
await asyncSleep(debounceTimeoutMs);

if (thisSearchID !== currentSearchID) {
return null;
}

if (options.filters && options.filters.type) {
delete options.filters.type;
}

const searchResult = await pf.search(term, options);
if (thisSearchID !== currentSearchID) {
return null;
}

return searchResult;
}

Expand All @@ -52,6 +59,7 @@ export default function searchPeople() {
results: null,
resultCount: 0,

// Initialize the search component
async init() {
let pagefind;
try {
Expand All @@ -73,13 +81,13 @@ export default function searchPeople() {
}
},

// Perform the search
async search() {
// searchBox
let query = this.query;
// Don't wait for an empty search
let timeout = this.query.trim() ? 300 : 0;
let query = this.query.trim();
let timeout = query ? 300 : 0;
this.isLoading = true;
this.resultCount = 0;

let options = {};
if (this.filterType) {
options.filters = {
Expand All @@ -92,6 +100,7 @@ export default function searchPeople() {
(f) => f.value,
);
}

if (this.hasFilters && !query) {
query = null; // magic value for show all in category
}
Expand All @@ -117,18 +126,21 @@ export default function searchPeople() {
this.isLoading = false;
},

// Clear the search results
clear() {
this.query = "";
this.isLoading = false;
this.results = null;
this.error = null;
},

// Determine if the clear button should be shown
get showClearButton() {
if (this.isLoading) return false;
return !!this.query.trim();
},

// Map search results to a usable format
get people() {
if (!this.results) return [];
return this.results.map((data) => ({
Expand All @@ -137,7 +149,7 @@ export default function searchPeople() {
name: data.meta.title,
excerpt: data.excerpt,
role: data.meta.role || "",
researchAreas: data.filters.researchAreas || [], // New Filter
researchAreas: data.filters.researchAreas || [],
relevantCourses: data.filters.relevantCourses || [],
image: data.meta.image,
alt: data.meta.image_alt,
Expand All @@ -147,12 +159,15 @@ export default function searchPeople() {
}));
},

// Check if any filters are applied
get hasFilters() {
return (
this.filterResearchAreas.length || this.filterRelevantCourses.length
this.filterResearchAreas.length > 0 ||
this.filterRelevantCourses.length > 0
);
},

// Generate the results text
get resultsText() {
if (this.isLoading || !this.results) return "\u00a0";
if (!this.query && !this.hasFilters) return "\u00a0";
Expand All @@ -170,11 +185,12 @@ export default function searchPeople() {
return `Got ${total} search results. ${more}`;
},

andMore(a) {
if (a.length > 3) {
return a.slice(0, 2).join(", ") + " and more";
// Helper function to format arrays
andMore(arr) {
if (arr.length > 3) {
return arr.slice(0, 2).join(", ") + " and more";
}
return a.join(", ");
return arr.join(", ");
},
};
}
1 change: 1 addition & 0 deletions content/about/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: "Team Members"
title-tag: Team Members
date: 2024-07-17
draft: false
mission: "Our mission is to foster inclusivity and diversity in physics and astronomy education by creating an accessible, searchable online repository that highlights the contributions of historically marginalized scientists. We strive to support the retention and identity development of marginalized students in these fields by providing educators with the resources needed to incorporate diverse role models into their courses. Our values include integrity in our research and representation, innovation in educational resources, excellence in creating comprehensive and reliable content, collaboration across disciplines and backgrounds, and respect for the diverse contributions that have shaped and continue to shape the fields of physics and astronomy."
Expand Down
1 change: 1 addition & 0 deletions content/scientist/j-ernest-wilkins-jr.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title":"J. Ernest Wilkins Jr.",
"name":"J. Ernest Wilkins Jr.",
"linktitle":"J Ernest Wilkins Jr",
"last":"Wilkins",
Expand Down
1 change: 1 addition & 0 deletions content/scientist/mary-chilton-noyes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title" : "Mary Chilton Noyes",
"name": "Mary Chilton Noyes",
"linktitle": "Mary Chilton Noyes",
"last": "Noyes",
Expand Down
1 change: 1 addition & 0 deletions content/scientist/robert-a-ellis-jr.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"title": "Robert A. Ellis Jr.",
"name": "Robert A. Ellis Jr.",
"linktitle": "Robert A. Ellis Jr.",
"last": "Ellis",
Expand Down
8 changes: 1 addition & 7 deletions hugo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
baseURL = "https://amplifycolorado.colabnews.co/"
languageCode = "en-us"
title = "Amplify Colorado"
title = ""
enableRobotsTXT = true
enableGitInfo = true
rssLimit = 50
Expand All @@ -12,13 +12,7 @@ buildFuture = true
[params]
favicon = "/img/logos/hiddenfigs_logo.png"
touch-icon = "/img/logos/hiddenfigs_logo.png"
donate-link = "https://colab.fundjournalism.org/amplifycolorado/"
nominate-link = "http://bit.ly/AmplifyColorado"
[taxonomies]
expertise = "expertise"
location = "location"
beat = "beat"
area = "area"
researchAreas = "researchAreas"
relevantCourses = "relevantCourses"

Expand Down
49 changes: 21 additions & 28 deletions layouts/_default/person.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,31 @@ <h1 class="break-word font-bold leading-tight">
</h1>
{{ with .Param "organization" }}
<h2
class="break-word text-lg leading-tight text-gray"
class="break-word text-lg leading-tight text-gray"
data-pagefind-meta="organization"
>
{{ . }}
</h2>
{{ end }}


<!-- basic info section -->
<!-- Basic info section -->
<div class="links-blue-darker mt-2 text-sm sm:flex sm:flex-wrap">
<p class="sm:w-1/2">
<span class="mr-5 text-g-6">
<svg class="inline-block h-4 w-4 fill-current align-text-bottom">
<use xlink:href="#university-svg"></use>
</svg>
</span>
<span>
{{ .Params.institution_of_phd }}
</span>
<span>{{ .Params.institution_of_phd }}</span>
</p>
<p class="sm:w-1/2">
<span class="mr-5 text-g-6">
<svg class="inline-block h-4 w-4 fill-current align-text-bottom">
<use xlink:href="#phd"></use>
</svg>
</span>
<span>
{{ .Params.field_of_phd }}
</span>
<span>{{ .Params.field_of_phd }}</span>
</p>
<p class="sm:w-1/2">
<span class="mr-5 text-g-6">
Expand Down Expand Up @@ -82,32 +78,31 @@ <h1 class="break-word font-bold leading-tight">
<use xlink:href="#globe-svg"></use>
</svg>
</span>
<a href="{{ .Params.wikipedia }}" target="_blank">
{{ .Params.wikipedia }}
</a>
<a href="{{ .Params.wikipedia }}" target="_blank"
>{{ .Params.wikipedia }}</a
>
</p>
</div>
<!-- content button switch -->

<!-- Content button switch -->
<div class="mt-4 flex flex-row justify-around bg-black p-2">
<button
:class="isBio ? 'bg-white text-black' : 'bg-gray text-white'"
class="mx-4 flex-1 transform rounded-lg px-4 py-2
transition-transform duration-200 ease-in-out hover:scale-105 hover:shadow-lg focus:outline-none"
class="mx-4 flex-1 transform rounded-lg px-4 py-2 transition-transform duration-200 ease-in-out hover:scale-105 hover:shadow-lg focus:outline-none"
@click="isBio = true"
>
Bio
</button>
<button
:class="!isBio ? 'bg-white text-black' : 'bg-gray text-white'"
class="mx-4 flex-1 transform rounded-lg px-4 py-2
transition-transform duration-200 ease-in-out hover:scale-105 hover:shadow-lg focus:outline-none"
class="mx-4 flex-1 transform rounded-lg px-4 py-2 transition-transform duration-200 ease-in-out hover:scale-105 hover:shadow-lg focus:outline-none"
@click="isBio = false"
>
Contribution
</button>
</div>

<!-- content section: BIO -->
<!-- Content section: BIO -->
<div
x-show="isBio"
x-transition:enter="transition ease-out duration-100 delay-100"
Expand All @@ -132,12 +127,12 @@ <h2 class="text-lg font-bold">Scientist Biography</h2>
<a href="{{ $img.RelPermalink }}" download>
<img
data-pagefind-meta="
image[src],
image_alt[alt],
image_srcset[srcset],
image_width[width],
image_height[height],
"
image[src],
image_alt[alt],
image_srcset[srcset],
image_width[width],
image_height[height],
"
title="Click to download"
class="rounded bg-g-4 shadow transition-shadow duration-500 hover:shadow-lg"
alt="Headshot of {{ $.Title }}"
Expand Down Expand Up @@ -177,13 +172,11 @@ <h2 class="text-lg font-bold">Scientist Biography</h2>
class="content-area links-blue-darker clear-both mt-4 sm:clear-none"
>
<h2 class="sr-only" data-pagefind-ignore>Biographical information</h2>
<p>
{{ .Params.general_bio }}
</p>
<p>{{ .Params.general_bio }}</p>
</section>
<div class="links-blue-darker mt-4 flex flex-col md:flex">
<span>
<p class="mt-2 text-lg font-bold">Reserach Areas:</p>
<p class="mt-2 text-lg font-bold">Research Areas:</p>
{{ range $i, $p := .Params.researchAreas }}
{{- if ne $i 0 }},{{ end }}
<span data-pagefind-filter="researchAreas">{{ . -}}</span>
Expand All @@ -199,7 +192,7 @@ <h2 class="sr-only" data-pagefind-ignore>Biographical information</h2>
</div>
</div>

<!-- Contribute section -->
<!-- Contribution section -->
<div
x-show="!isBio"
x-transition:enter="transition ease-out duration-100 delay-100"
Expand Down

0 comments on commit 444c286

Please sign in to comment.