forked from twitter/opensource-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite projects page and search functionality
Rather than building the whole page in javascript, output the initial project cards as static HTML (ordered by push date), and add search functionality as progressive enhancement. Search results are now sorted by ranking order as returned by fusejs. Cards are ordered using the "order" CSS value rather than rebuilding the DOM every time. This should be more performant in theory, though in practice our dataset is small enough that it's not really noticeable. It does make the code much simpler though.
- Loading branch information
1 parent
9bb2f7b
commit 2a2479d
Showing
3 changed files
with
89 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,29 @@ | ||
{{ define "header" }} | ||
<h1 class="large-title">Projects</h1> | ||
<div class="search-bar"> | ||
<input class="search-box" type="text" name="search" placeholder="Search Projects" autocomplete="off" /> | ||
<input id="search-box" type="text" name="search" placeholder="Search Projects" autocomplete="off" /> | ||
<svg id="search-icon" viewBox="0 0 24 24" aria-hidden="true" class="r-14j79pv r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-4wgw6l r-f727ji r-bnwqim r-1plcrui r-lrvibr"><g><path d="M21.53 20.47l-3.66-3.66C19.195 15.24 20 13.214 20 11c0-4.97-4.03-9-9-9s-9 4.03-9 9 4.03 9 9 9c2.215 0 4.24-.804 5.808-2.13l3.66 3.66c.147.146.34.22.53.22s.385-.073.53-.22c.295-.293.295-.767.002-1.06zM3.5 11c0-4.135 3.365-7.5 7.5-7.5s7.5 3.365 7.5 7.5-3.365 7.5-7.5 7.5-7.5-3.365-7.5-7.5z"></path></g></svg> | ||
</div> | ||
{{ end }} | ||
|
||
{{ define "content" }} | ||
<!-- Container for no results text --> | ||
<div class="container no-results-container"></div> | ||
<!-- Container for results text --> | ||
<div id="results" class="container hide">Found <span class="count"></span> results for <span class="query"></span></div> | ||
|
||
<!-- Projects grid (See renderProjects() in projects.js) --> | ||
<div class="container all-projects"></div> | ||
<!-- End of all-projects --> | ||
|
||
<script type="text/javascript"> | ||
let allProjects = []; | ||
{{ range $.Site.Data.projects }} | ||
allProjects.push({ | ||
name: "{{ .name }}", | ||
nameWithOwner: "{{ .nameWithOwner }}", | ||
description: "{{ .descriptionHTML }}", | ||
{{- with .primaryLanguage }} | ||
color: "{{ .color }}", | ||
primaryLanguage: "{{ .name }}", | ||
{{ end -}} | ||
homepageURL: "{{ .homepageUrl }}", | ||
pushedAt : "{{ .pushedAt }}", | ||
languages : "{{ .languages }}", | ||
forks : "{{ .forkCount }}", | ||
topics : "{{ .repositoryTopics }}", | ||
stars : "{{ .stargazers }}", | ||
watchers : "{{ .watchers }}", | ||
}) | ||
<div class="container all-projects"> | ||
{{ range sort $.Site.Data.projects "pushedAt" "desc" -}} | ||
<div class="project-card" id="{{ .nameWithOwner }}"> | ||
<h1 class="project-name small-margin">{{ .name }}</h1> | ||
<div class="border small-margin"{{ with .primaryLanguage }} style="border-bottom-color:{{ .color }}"{{ end }}></div> | ||
<div class="project-description xsmall-margin">{{ .descriptionHTML | safeHTML }}</div> | ||
<p class="project-language">{{ with .primaryLanguage }}{{ .name }}{{ end }}</p> | ||
<div class="whitespace"></div> | ||
<div class="project-links"> | ||
<a href="https://github.com/{{ .nameWithOwner }}" target="_blank" rel="noopener">GitHub</a> | ||
{{ with .homepageUrl }}<a href="{{ . }}" target="_blank" rel="noopener">Website</a>{{ end }} | ||
</div> | ||
<a href="https://twitter.github.io/metrics/{{ .nameWithOwner }}/WEEKLY" class="Button Button--tertiary">Metrics</a> | ||
</div> | ||
{{ end }} | ||
</script> | ||
</div> | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters