IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Commit 91c29bef authored by Amy Rose's avatar Amy Rose
Browse files

improve search, support multiple owners for project, fix jekyll front matter name clash

parent ee45eb8c
Pipeline #849 passed with stage
in 3 minutes and 25 seconds
......@@ -18,10 +18,10 @@ TODO: documentation
</div>
<div id="projects-container">
{% for project-page in site.projects %}
<div id="{{ project-page.slug }}" class="project">
<div id="{{ project-page.mystic-slug }}" class="project">
<h2>{{ project-page.project }}</h2>
<p>{{ project-page.tldr }}</p>
<p>{{ project-page.owner }}</p>
<p>{{ project-page.owner | join: " & " }}</p>
<a href="{{ project-page.url | relative_url }}">View more</a>
</div>
{% endfor %}
......@@ -30,10 +30,10 @@ TODO: documentation
<script>
const PROJECTS_DATA = {
{% for project-page in site.projects %}
"{{ project-page.slug }}": {
"name": "{{ project-page.project }}",
"tldr": "{{ project-page.tldr }}",
"owner": "{{ project-page.owner }}",
"{{ project-page.mystic-slug }}": {
"name": "{{ project-page.project }}",
"tldr": "{{ project-page.tldr }}",
"owner": "{{ project-page.owner | join: ' & ' }}",
},
{% endfor %}
}
......
......@@ -3,8 +3,10 @@ layout: project
project: Sound Voltex
tldr: A 6-key + 2-knob game about applying effects to music
owner: dj TAKA
slug: test1
owner:
- dj TAKA
- PHQAUSE
mystic-slug: test1
---
## List of Services
......
......@@ -4,7 +4,7 @@ layout: project
project: beatmania IIDX
tldr: The genre-defining 7-key + turntable game
owner: L.E.D.
slug: test2
mystic-slug: test2
---
## List of Services
......
......@@ -4,7 +4,7 @@ layout: project
project: pop'n music
tldr: The deceptively difficult 9-button color burger-smashing game
owner: wac
slug: test3
mystic-slug: test3
---
## List of Services
......
......@@ -4,7 +4,7 @@ layout: project
project: Dance Dance Revolution
tldr: The ubiquitous 4-panel dance game that swept the world
owner: NAOKI
slug: test4
mystic-slug: test4
---
## List of Services
......
......@@ -4,7 +4,7 @@ layout: project
project: jubeat
tldr: A 16-button musical whack-a-mole game on life support
owner: S-C-U
slug: test5
mystic-slug: test5
---
## List of Services
......
......@@ -4,7 +4,7 @@ layout: project
project: GuitarFreaks & DrumMania
tldr: The games that Guitar Hero ripped off
owner: Yoshihiko Koezuka
slug: test6
mystic-slug: test6
---
## List of Services
......
......@@ -25,10 +25,11 @@
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
}
.project {
flex: 1 0 33%;
flex-basis: 33%;
min-width: 200px;
box-sizing: border-box;
padding: 1em;
......
......@@ -3,7 +3,7 @@
/* Config - Field and its search weight (scalar) */
// TODO: refine values
const SEARCHABLE_FIELDS = {
"name": 2.5,
"name": 3.5,
"owner": 1.75,
"tldr": 1,
};
......@@ -40,37 +40,8 @@ function handle_search(event) {
prev_search = search_text;
/* Only search if the query isn't empty */
if (search_text.length > 0) {
/* Search */
const searched_projects = PROJECTS_LIST.filter(project => {
project.search_valid = Object.entries(project)
.some(([field, value]) => {
if (Object.keys(SEARCHABLE_FIELDS).includes(field)) {
return value
.toLowerCase()
.indexOf(search_text.toLowerCase()) !== -1;
}
return false;
});
return project.search_valid;
});
/* Sort */
searched_projects.forEach(project => {
const scores = [];
Object.entries(SEARCHABLE_FIELDS)
.forEach(([search_field, weight]) => {
const dist = levenshtein(project[search_field], search_text);
const score = dist * weight
scores.push(score);
});
project.search_score = Math.min(...scores);
});
searched_projects.sort((a, b) => {
return b.search_score - a.search_score;
});
let i = 1;
searched_projects.forEach(project => {
project.search_order = i++;
});
const searched_projects = search_projects(search_text);
sort_projects(search_text, searched_projects);
} else {
/* Reset to default */
PROJECTS_LIST.forEach(project => {
......@@ -82,6 +53,47 @@ function handle_search(event) {
update_content();
}
function search_projects(search_text) {
return PROJECTS_LIST.filter(project => {
project.search_valid = Object.entries(project)
.some(([field, value]) => {
if (Object.keys(SEARCHABLE_FIELDS).includes(field)) {
return value
.trim()
.toLowerCase()
.indexOf(
search_text
.trim()
.toLowerCase()
) !== -1;
}
return false;
});
return project.search_valid;
});
}
function sort_projects(search_text, projects) {
projects.forEach(project => {
const scores = [];
Object.entries(SEARCHABLE_FIELDS)
.forEach(([search_field, weight]) => {
const value = project[search_field];
const dist = levenshtein(value, search_text);
const score = (dist * weight) / value.length;
scores.push(score);
});
project.search_score = Math.min(...scores);
});
projects
.sort((a, b) => (
b.search_score - a.search_score
))
.forEach((project, i) => {
project.search_order = i;
});
}
function update_content() {
PROJECTS_LIST.forEach(project => {
/* Apply visibility */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment