pidgin/nest

Parents 520a5548f7ac
Children f1823bf275dd
Remove hacky pluginTable data, and use a uniq array slice instead

Credit goes here: https://discourse.gohugo.io/t/reduce-data-into-a-different-format-and-create-markup-from-the-new-format/22591/2?u=oiyouyeahyou

Plus, fix bug that leaves an empty string in the search types set
--- a/hugo/data/pluginTypes.json Wed Jan 01 22:12:52 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-[
- {
- "type": "Protocol",
- "i18n": {
- "en": "Protocol"
- }
- },
- {
- "type": "Security and Privacy",
- "i18n": {
- "en": "Security and Privacy"
- }
- },
- {
- "type": "Notifications",
- "i18n": {
- "en": "Notifications"
- }
- },
- {
- "type": "Profile and Status Updates",
- "i18n": {
- "en": "Profile and Status Updates"
- }
- },
- {
- "type": "Now Playing",
- "i18n": {
- "en": "Now Playing"
- }
- },
- {
- "type": "Interface Tweaks",
- "i18n": {
- "en": "Interface Tweaks"
- }
- },
- {
- "type": "Accounts and Logs",
- "i18n": {
- "en": "Accounts and Logs"
- }
- },
- {
- "type": "Miscellaneous",
- "i18n": {
- "en": "Miscellaneous"
- }
- }
-]
\ No newline at end of file
--- a/hugo/layouts/shortcodes/plugintable.html Wed Jan 01 22:12:52 2020 +0000
+++ b/hugo/layouts/shortcodes/plugintable.html Thu Jan 02 02:36:57 2020 +0000
@@ -53,10 +53,15 @@
<input type="text" id="plugin-filter-search" placeholder="{{ T "Search-placeholder" }}" />
<div id="plugin-selector">
- {{ range .Site.Data.pluginTypes }}
+ {{ $types := slice }}
+ {{ range .Site.Data.plugins }}
+ {{ $types = $types | append ( index . "type" ) }}
+ {{ end }}
+
+ {{ range uniq $types }}
<label class="pidgin-plugin-filter-checkbox">
- <input type="checkbox" data-type="{{ .type }}">
- {{ .i18n.en }}
+ <input type="checkbox" data-type="{{ . }}">
+ {{ . }}
</label>
{{ end }}
</div>
--- a/hugo/static/js/plugin-table.js Wed Jan 01 22:12:52 2020 +0000
+++ b/hugo/static/js/plugin-table.js Thu Jan 02 02:36:57 2020 +0000
@@ -37,6 +37,7 @@
.map(function(str) {
return str.trim();
})
+ .filter(Boolean)
: []
),
};
@@ -84,7 +85,7 @@
* @param {MouseEvent} event
* @param {HTMLInputElement} event.target
*/
-function pluginTypeSelectorClickEvent(target) {
+function pluginTypeSelectorClickEvent({ target }) {
searchState.type[target.checked ? "add" : "delete"](target.dataset.type);
updateFilters();
}
--- a/tools/plugin-map.js Wed Jan 01 22:12:52 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-const fs = require("fs");
-const data = require("../hugo/data/plugins.json");
-
-const types = new Set();
-
-data.forEach(plugin => {
- types.add(plugin.type);
-});
-
-const newData = Array.from(types).map(type => ({
- type,
- i18n: {
- en: type,
- },
-}));
-
-fs.writeFileSync(
- "../hugo/data/pluginTypes.json",
- JSON.stringify(newData, null, "\t")
-);