Skip to content

Commit 7607d92

Browse files
committed
Added asset sort on latest vs stars
1 parent b19c59e commit 7607d92

File tree

8 files changed

+49
-23
lines changed

8 files changed

+49
-23
lines changed

_includes/tagfilter.html

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
{%- assign tags = alltags | uniq | sort -%}
44
<p>FILTER</p>
55
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); grid-gap: 0 1rem; font-size: 0.9em;">
6-
{%- if page.tag -%}
6+
{%- if include.tag -%}
77
{%- assign class="" -%}
88
{%- else -%}
99
{%- assign class="active" -%}
1010
{%- endif-%}
11-
<a class="filter {{ class }}" href="/assets">ALL ({{ site.data.assetindex.size }})</a>
11+
<a class="filter {{ class }}" href="/assets_{{ include.sort }}">ALL ({{ site.data.assetindex.size }})</a>
1212
{%- for tag in tags -%}
1313
{% assign tagged_assets = site.data.assetindex | where: "tags", tag %}
1414
{% assign tag_no_space = tag | replace: " ", "" | downcase %}
@@ -17,8 +17,13 @@
1717
{%- else -%}
1818
{%- assign class="" -%}
1919
{%- endif-%}
20-
<a class="filter {{ class }}" href="/tags/{{ tag | replace: ' ' | downcase }}">{{ tag }} ({{ tagged_assets.size }})</a>
20+
<a class="filter {{ class }}" href="/tags/{{ include.sort }}/{{ tag | replace: ' ' | downcase }}">{{ tag }} ({{ tagged_assets.size }})</a>
2121
{%- endfor -%}
2222
</div>
2323
<br/>
24+
{%- if include.tag -%}
25+
<p>SORT BY: <a href="/tags/stars/{{ include.tag }}">Stars</a>, <a href="/tags/timestamp/{{ include.tag }}">Latest</a></p>
26+
{%- else -%}
27+
<p>SORT BY: <a href="/assets_stars">Stars</a>, <a href="/assets_timestamp">Latest</a></p>
28+
{%- endif-%}
2429
</div>

_layouts/asset.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ <h5>Discuss</h5>
9393
<td valign="top">Tags</td>
9494
<td valign="top">
9595
{%- for tag in asset.tags -%}
96-
<a href="/tags/{{ tag | downcase | remove: ' ' }}">{{ tag }}</a><br/>
96+
<a href="/tags/stars/{{ tag | downcase | remove: ' ' }}">{{ tag }}</a><br/>
9797
{%- endfor -%}
9898
</td>
9999
</tr>

_layouts/assetportal.html

+5-9
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,19 @@ <h1>Asset portal</h1>
1515
{% include secondary_button.html link="/submit_asset" text="Submit asset" %}
1616
</div>
1717
</div>
18+
{%- assign sort_order = page.sort | default: "stars" -%}
1819
{%- if page.tag -%}
1920
{%- assign tag = site.data.tags[page.tag] -%}
2021
{%- assign tagid = tag.id -%}
2122
{%- assign assetname = tag.name -%}
23+
{%- assign assetids = tag.assets | sort: sort_order | reverse | map: "id" -%}
2224

23-
{%- if page.sort == "stars" -%}
24-
{%- assign assetids = tag.assets | sort: "stars" | reverse | map: "id" -%}
25-
{%- else -%}
26-
{%- assign assetids = tag.assets | map: "id" -%}
27-
{% endif %}
28-
29-
{%- include tagfilter.html tag=tagid -%}
25+
{%- include tagfilter.html tag=tagid sort=sort_order -%}
3026
{%- include assetgrid.html assetids=assetids showfilter=true title=assetname -%}
3127
{%- else -%}
32-
{%- assign assetids = site.data.assetindex | sort: "stars" | reverse | map: "id" -%}
28+
{%- assign assetids = site.data.assetindex | sort: sort_order | reverse | map: "id" -%}
3329

34-
{%- include tagfilter.html -%}
30+
{%- include tagfilter.html sort=sort_order -%}
3531
{%- include assetgrid.html assetids=assetids showfilter=true title="All" -%}
3632
{%- endif -%}
3733
<div class="row" style="margin-top: 30px">

assets_stars.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: assetportal
3+
sort: stars
4+
---

assets_timestamp.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: assetportal
3+
sort: timestamp
4+
---

tags/stars.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: assetportal
3+
sort: stars
4+
---

tags/timestamp.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
layout: assetportal
3+
sort: timestamp
4+
---

update.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@
5252
---
5353
"""
5454

55-
TAG_SORT_STARS_MD_FRONTMATTER = """---
55+
TAG_SORT_MD_FRONTMATTER = """---
5656
layout: assetportal
5757
tag: {}
5858
title: {}
59-
sort: stars
59+
sort: {}
6060
---
6161
"""
6262

@@ -472,10 +472,6 @@ def process_assets(download = False):
472472
author_collection_dir = "authors"
473473
rmmkdir(author_collection_dir)
474474

475-
# Jekyll tags collection
476-
tag_collection_dir = "tags"
477-
rmmkdir(tag_collection_dir)
478-
479475
# Jekyll asset data
480476
asset_data_dir = os.path.join("_data", "assets")
481477
rmmkdir(asset_data_dir)
@@ -519,7 +515,8 @@ def process_assets(download = False):
519515
"id": asset_id,
520516
"tags": asset["tags"],
521517
"platforms": asset["platforms"],
522-
"stars": asset.get("stars") or 0
518+
"stars": asset.get("stars") or 0,
519+
"timestamp": asset.get("timestamp") or 0
523520
})
524521

525522
# build tag index
@@ -532,7 +529,8 @@ def process_assets(download = False):
532529
}
533530
tagindex[tag]["assets"].append({
534531
"id": asset_id,
535-
"stars": asset.get("stars") or 0
532+
"stars": asset.get("stars") or 0,
533+
"timestamp": asset.get("timestamp") or 0
536534
})
537535

538536
# build platform index
@@ -591,14 +589,25 @@ def process_assets(download = False):
591589
platformlist.sort(key=lambda x: x.get("id").lower())
592590
write_as_json(PLATFORMINDEX_JSON, platformlist)
593591

592+
# Jekyll tags collection (one subdirectory per sort order)
593+
tag_collection_dir = "tags"
594+
sort_orders = ["stars", "timestamp"]
595+
for sort_order in sort_orders:
596+
rmmkdir(os.path.join(tag_collection_dir, sort_order))
597+
594598
# write tag data
595599
for tag in taglist:
596600
tag["assets"].sort(key=lambda x: x.get("id"))
601+
602+
# _data/tags
597603
filename = os.path.join(tag_data_dir, tag["id"] + ".json")
598604
with open(filename, "w") as f:
599605
f.write(json.dumps(tag, indent=2, sort_keys=True))
600-
with open(os.path.join(tag_collection_dir, tag["id"] + ".md"), "w") as f:
601-
f.write(TAG_SORT_STARS_MD_FRONTMATTER.format(tag["id"], tag["name"]))
606+
607+
# tags/stars, tags/timestamp
608+
for sort_order in sort_orders:
609+
with open(os.path.join(tag_collection_dir, sort_order, tag["id"] + ".md"), "w") as f:
610+
f.write(TAG_SORT_MD_FRONTMATTER.format(tag["id"], tag["name"], sort_order))
602611

603612

604613

0 commit comments

Comments
 (0)