aboutsummaryrefslogtreecommitdiff
path: root/viewer
diff options
context:
space:
mode:
Diffstat (limited to 'viewer')
-rw-r--r--viewer/src/@types/tag/index.d.ts1
-rw-r--r--viewer/src/components/LdTagInput.vue7
-rw-r--r--viewer/src/store/galleryStore.ts3
-rw-r--r--viewer/src/tools.ts30
4 files changed, 38 insertions, 3 deletions
diff --git a/viewer/src/@types/tag/index.d.ts b/viewer/src/@types/tag/index.d.ts
index c77fc3b..1d5df88 100644
--- a/viewer/src/@types/tag/index.d.ts
+++ b/viewer/src/@types/tag/index.d.ts
@@ -20,6 +20,7 @@
20declare namespace Tag { 20declare namespace Tag {
21 interface Node { 21 interface Node {
22 tag: Gallery.RawTag; 22 tag: Gallery.RawTag;
23 tagfiltered: Gallery.RawTag;
23 items: Gallery.Item[]; 24 items: Gallery.Item[];
24 children: Index; 25 children: Index;
25 } 26 }
diff --git a/viewer/src/components/LdTagInput.vue b/viewer/src/components/LdTagInput.vue
index 71131e6..7c9981f 100644
--- a/viewer/src/components/LdTagInput.vue
+++ b/viewer/src/components/LdTagInput.vue
@@ -42,6 +42,7 @@
42<script lang="ts"> 42<script lang="ts">
43import { Component, Vue } from "vue-property-decorator"; 43import { Component, Vue } from "vue-property-decorator";
44import { Operation } from "@/@types/tag/Operation"; 44import { Operation } from "@/@types/tag/Operation";
45import Tools from "@/tools";
45 46
46@Component 47@Component
47export default class LdTagInput extends Vue { 48export default class LdTagInput extends Vue {
@@ -92,18 +93,20 @@ export default class LdTagInput extends Vue {
92 category: string, 93 category: string,
93 disambiguation: string 94 disambiguation: string
94 ): Tag.Search[] { 95 ): Tag.Search[] {
96 disambiguation = Tools.normalize(disambiguation);
95 return Object.values(tags) 97 return Object.values(tags)
96 .filter(node => node.tag.includes(category)) 98 .filter(node => node.tag.includes(category))
97 .flatMap(node => 99 .flatMap(node =>
98 Object.values(node.children) 100 Object.values(node.children)
99 .filter(child => child.tag.includes(disambiguation)) 101 .filter(child => child.tagfiltered.includes(disambiguation))
100 .map(child => ({ ...child, parent: node, operation, display: `${operation}${node.tag}:${child.tag}` })) 102 .map(child => ({ ...child, parent: node, operation, display: `${operation}${node.tag}:${child.tag}` }))
101 ); 103 );
102 } 104 }
103 105
104 searchTagsFromFilter(tags: Tag.Index, operation: Operation, filter: string): Tag.Search[] { 106 searchTagsFromFilter(tags: Tag.Index, operation: Operation, filter: string): Tag.Search[] {
107 filter = Tools.normalize(filter);
105 return Object.values(tags) 108 return Object.values(tags)
106 .filter(node => node.tag.includes(filter)) 109 .filter(node => node.tagfiltered.includes(filter))
107 .map(node => ({ ...node, operation, display: `${operation}${node.tag}` })); 110 .map(node => ({ ...node, operation, display: `${operation}${node.tag}` }));
108 } 111 }
109 112
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index c4a039f..663340f 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -18,6 +18,7 @@
18*/ 18*/
19 19
20import { createModule, mutation, action } from "vuex-class-component"; 20import { createModule, mutation, action } from "vuex-class-component";
21import Tools from '@/tools';
21 22
22const VuexModule = createModule({ 23const VuexModule = createModule({
23 namespaced: "galleryStore", 24 namespaced: "galleryStore",
@@ -88,7 +89,7 @@ export default class GalleryStore extends VuexModule {
88 const parts = tag.split('.'); 89 const parts = tag.split('.');
89 let lastPart: string | null = null; 90 let lastPart: string | null = null;
90 for (const part of parts) { 91 for (const part of parts) {
91 if (!index[part]) index[part] = { tag: part, items: [], children: {} }; 92 if (!index[part]) index[part] = { tag: part, tagfiltered: Tools.normalize(part), items: [], children: {} };
92 if (!index[part].items.includes(item)) index[part].items.push(item); 93 if (!index[part].items.includes(item)) index[part].items.push(item);
93 if (lastPart) index[lastPart].children[part] = index[part]; 94 if (lastPart) index[lastPart].children[part] = index[part];
94 lastPart = part; 95 lastPart = part;
diff --git a/viewer/src/tools.ts b/viewer/src/tools.ts
new file mode 100644
index 0000000..5eb287e
--- /dev/null
+++ b/viewer/src/tools.ts
@@ -0,0 +1,30 @@
1/* ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery.
3--
4-- Copyright (C) 2019-2020 Guillaume FOUET
5--
6-- This program is free software: you can redistribute it and/or modify
7-- it under the terms of the GNU Affero General Public License as
8-- published by the Free Software Foundation, either version 3 of the
9-- License, or (at your option) any later version.
10--
11-- This program is distributed in the hope that it will be useful,
12-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-- GNU Affero General Public License for more details.
15--
16-- You should have received a copy of the GNU Affero General Public License
17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20export default class Tools {
21
22 // Normalize a string to lowercase, no-accents
23 public static normalize(value: string) {
24 return value
25 .normalize("NFD")
26 .replace(/[\u0300-\u036f]/g, "")
27 .toLowerCase();
28 }
29
30} \ No newline at end of file