From 7733a3298551acac7742ca82203e44135e8293d7 Mon Sep 17 00:00:00 2001 From: SET001 Date: Fri, 17 Nov 2023 18:08:48 +0200 Subject: [PATCH] add version filter to assets --- sass/pages/_assets.scss | 6 ++- static/assets.js | 42 ++++++++++++++++- templates/assets.html | 102 ++++++++++++++++++++++------------------ 3 files changed, 101 insertions(+), 49 deletions(-) diff --git a/sass/pages/_assets.scss b/sass/pages/_assets.scss index 3f95cffa0c..81abaa8fbf 100644 --- a/sass/pages/_assets.scss +++ b/sass/pages/_assets.scss @@ -3,6 +3,10 @@ margin-bottom: 20px; } + .assets-filters { + margin-bottom: 20px; + } + .asset-section { font-size: 2.4rem; margin: 0 0 20px; @@ -31,4 +35,4 @@ } } } -} \ No newline at end of file +} diff --git a/static/assets.js b/static/assets.js index 77031d1bd9..99299b9815 100644 --- a/static/assets.js +++ b/static/assets.js @@ -36,4 +36,44 @@ function hideEmptySections() { } section.style.display = 'none' }) -} \ No newline at end of file +} + +// ------------ Version Filtering +function normalize_version(raw_version) { + let version = raw_version + .replace(/^[^\d]+/, '') + .replace(/[^\d]+$/, ''); + return version ? Array.from({ ...version.split('.'), length: 3 }, (v, i) => v ?? 0).join('.') : null; +} + +let versionsQuery = document.querySelectorAll('.asset-card .asset-card__tags .asset-card__bevy-versions .asset-card__tag'); +let versions = [...new Set([...versionsQuery] + .map(item => normalize_version(item.innerText)) + .filter(i => i) +)]; + + +let versionsSelect = document.querySelector('#assets-filter'); +if (versionsSelect) { + versions.map(i => { + var opt = document.createElement('option'); + opt.value = i; + opt.innerHTML = i; + versionsSelect.appendChild(opt); + }) +} + +document + .querySelector('#assets-filter') + .addEventListener("change", (item) => { + + for (const asset of document.querySelectorAll('.asset-card')) { + let tag = asset.querySelector('.asset-card__tags .asset-card__bevy-versions .asset-card__tag'); + if (tag) { + const searchMatch = item.target.value === normalize_version(tag.innerText); + asset.parentElement.style.display = searchMatch ? 'block' : 'none' + } else { + asset.parentElement.style.display = 'none' + } + } + }) diff --git a/templates/assets.html b/templates/assets.html index 1f83e9556d..f3b2f4f194 100644 --- a/templates/assets.html +++ b/templates/assets.html @@ -4,70 +4,78 @@ {% block page_name %}Bevy Assets{% endblock %} {% block mobile_page_menu %} - {{assets_macros::assets_menu(prefix="mobile-menu", root=section)}} +{{assets_macros::assets_menu(prefix="mobile-menu", root=section)}} {% endblock %} {% block page_menu %} - {{assets_macros::assets_menu(prefix="page-menu", root=section)}} +{{assets_macros::assets_menu(prefix="page-menu", root=section)}} {% endblock %} {% block page_content %} -
- {{ assets_macros::init_svg() }} +
+ {{ assets_macros::init_svg() }} - + -
- A collection of third-party Bevy assets, plugins, learning resources, and apps made by the community. If you would like to - share what you're working on, submit a pull request! -
+
+ + +
- {% for subsection in section.subsections %} - {% set section = get_section(path=subsection) %} +
+ A collection of third-party Bevy assets, plugins, learning resources, and apps made by the community. If you + would like to + share what you're working on, submit a pull request! +
-

- {{ section.title }}# -

+ {% for subsection in section.subsections %} + {% set section = get_section(path=subsection) %} - {% if section.pages %} -
- {% set pages = section.pages %} - {% if section.extra.sort_order_reversed %} - {% set pages = section.pages | reverse %} - {% endif %} - {% for post in pages %} - {{ assets_macros::card(post=post) }} - {% endfor %} -
- {% endif %} +

+ {{ section.title }}# +

- {% set subsections = section.subsections %} + {% if section.pages %} +
+ {% set pages = section.pages %} {% if section.extra.sort_order_reversed %} - {% set subsections = section.subsections | reverse %} + {% set pages = section.pages | reverse %} {% endif %} - {% for subsection in subsections %} - {% set section = get_section(path=subsection) %} + {% for post in pages %} + {{ assets_macros::card(post=post) }} + {% endfor %} +
+ {% endif %} -

- {{ section.title }}# -

-
- {% set pages = section.pages %} - {% if section.extra.sort_order_reversed %} - {% set pages = section.pages | reverse %} - {% endif %} - {% for post in pages %} - {{ assets_macros::card(post=post) }} - {% endfor %} -
+ {% set subsections = section.subsections %} + {% if section.extra.sort_order_reversed %} + {% set subsections = section.subsections | reverse %} + {% endif %} + {% for subsection in subsections %} + {% set section = get_section(path=subsection) %} - {% endfor %} +

+ {{ section.title }}# +

+
+ {% set pages = section.pages %} + {% if section.extra.sort_order_reversed %} + {% set pages = section.pages | reverse %} + {% endif %} + {% for post in pages %} + {{ assets_macros::card(post=post) }} {% endfor %}
- + {% endfor %} + {% endfor %} +
+ + {% endblock %}