aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2020-02-27 21:05:51 +0100
committerNotkea2020-02-27 21:36:39 +0100
commitc7fa5bd40d0e5c9ea50190a90a0ccfee8ad96c25 (patch)
tree6c524899070301a13c7ce03bc6640d9c266bed71
parent8f041b9f13b4c043acc7720aa4c082583b52ffe1 (diff)
downloadldgallery-c7fa5bd40d0e5c9ea50190a90a0ccfee8ad96c25.tar.gz
viewer: use colon as tag separator instead of dot
For consistency with the query language and allowing the use of the very common dot in tags. This also introduces a migration script. GitHub: closes #164
-rw-r--r--compiler/ldgallery.1.md2
-rw-r--r--example/src/DSC0001.jpg.yaml4
-rw-r--r--example/src/Ormont-Dessus/DSC0002.jpg.yaml6
-rw-r--r--example/src/Ormont-Dessus/DSC0003.jpg.yaml6
-rw-r--r--example/src/Ormont-Dessus/_directory.yaml2
-rw-r--r--example/src/gallery.yaml4
-rwxr-xr-xscripts/migrate_tags_dot_to_colon.py25
-rw-r--r--viewer/src/components/LdProposition.vue4
-rw-r--r--viewer/src/services/indexfactory.ts2
9 files changed, 40 insertions, 15 deletions
diff --git a/compiler/ldgallery.1.md b/compiler/ldgallery.1.md
index 1d42eff..59a5b30 100644
--- a/compiler/ldgallery.1.md
+++ b/compiler/ldgallery.1.md
@@ -107,7 +107,7 @@ description
107 107
108tags 108tags
109: List of tags for the item. 109: List of tags for the item.
110 Tag groups can be defined using prefixes separated by "." (dot). 110 Tag groups can be defined using prefixes separated by ":" (colon).
111 Tags specified in a directory metadata sidecar are applied to all items within that directory. 111 Tags specified in a directory metadata sidecar are applied to all items within that directory.
112 112
113 113
diff --git a/example/src/DSC0001.jpg.yaml b/example/src/DSC0001.jpg.yaml
index b946ff7..cca1379 100644
--- a/example/src/DSC0001.jpg.yaml
+++ b/example/src/DSC0001.jpg.yaml
@@ -6,7 +6,7 @@ description: >
6 © Philippe NGUYEN 6 © Philippe NGUYEN
7 7
8tags: 8tags:
9 - photographer.nphilou 9 - photographer:nphilou
10 - location.germany.berlin 10 - location:germany:berlin
11 - books 11 - books
12 - book-shop 12 - book-shop
diff --git a/example/src/Ormont-Dessus/DSC0002.jpg.yaml b/example/src/Ormont-Dessus/DSC0002.jpg.yaml
index 5b845b6..a69deb9 100644
--- a/example/src/Ormont-Dessus/DSC0002.jpg.yaml
+++ b/example/src/Ormont-Dessus/DSC0002.jpg.yaml
@@ -6,8 +6,8 @@ description: >
6 © Philippe NGUYEN 6 © Philippe NGUYEN
7 7
8tags: 8tags:
9 - photographer.nphilou 9 - photographer:nphilou
10 - time.day 10 - time:day
11 - weather.foggy 11 - weather:foggy
12 - catwalk 12 - catwalk
13 - mountain 13 - mountain
diff --git a/example/src/Ormont-Dessus/DSC0003.jpg.yaml b/example/src/Ormont-Dessus/DSC0003.jpg.yaml
index 85a88ec..558f921 100644
--- a/example/src/Ormont-Dessus/DSC0003.jpg.yaml
+++ b/example/src/Ormont-Dessus/DSC0003.jpg.yaml
@@ -6,8 +6,8 @@ description: >
6 © Philippe NGUYEN 6 © Philippe NGUYEN
7 7
8tags: 8tags:
9 - photographer.nphilou 9 - photographer:nphilou
10 - time.day 10 - time:day
11 - weather.foggy 11 - weather:foggy
12 - forest 12 - forest
13 - trees 13 - trees
diff --git a/example/src/Ormont-Dessus/_directory.yaml b/example/src/Ormont-Dessus/_directory.yaml
index 75ad01b..5b3e0c7 100644
--- a/example/src/Ormont-Dessus/_directory.yaml
+++ b/example/src/Ormont-Dessus/_directory.yaml
@@ -1,3 +1,3 @@
1# The following tags are applied to all items in the directory 1# The following tags are applied to all items in the directory
2tags: 2tags:
3 - location.switzerland.ormont-dessus 3 - location:switzerland:ormont-dessus
diff --git a/example/src/gallery.yaml b/example/src/gallery.yaml
index d2f90aa..c4a5077 100644
--- a/example/src/gallery.yaml
+++ b/example/src/gallery.yaml
@@ -6,14 +6,14 @@
6#excludedDirectories: [] 6#excludedDirectories: []
7 7
8includedFiles: 8includedFiles:
9 - "*.jpg" 9 - '*.jpg'
10 10
11#excludedFiles: 11#excludedFiles:
12# - "*.md" 12# - "*.md"
13 13
14tagsFromDirectories: 14tagsFromDirectories:
15 fromParents: 0 # default 15 fromParents: 0 # default
16 prefix: "" # default 16 prefix: '' # default
17 17
18thumbnailMaxResolution: 18thumbnailMaxResolution:
19 width: 400 # default 19 width: 400 # default
diff --git a/scripts/migrate_tags_dot_to_colon.py b/scripts/migrate_tags_dot_to_colon.py
new file mode 100755
index 0000000..bf56c4c
--- /dev/null
+++ b/scripts/migrate_tags_dot_to_colon.py
@@ -0,0 +1,25 @@
1#!/usr/bin/env nix-shell
2#!nix-shell -i python -p "python3.withPackages (ps: with ps; [ruamel_yaml])"
3
4from argparse import ArgumentParser
5from ruamel.yaml import YAML
6from collections.abc import Iterable
7
8parser = ArgumentParser(description='Converts tag separator from dot to colon in sidecar files, easing migration after GH-164.')
9parser.add_argument('file', type=str, nargs='+', help='YAML sidecar file(s) to migrate.')
10args = parser.parse_args()
11
12yaml = YAML(typ='rt') # preserve order, style and comments
13yaml.indent(mapping=2, sequence=2, offset=2)
14
15for file_path in args.file:
16 with open(file_path, 'r+') as file:
17 sidecar = yaml.load(file)
18 if not sidecar: continue
19
20 if 'tags' in sidecar and isinstance(sidecar['tags'], Iterable):
21 sidecar['tags'] = [tag.replace('.', ':') for tag in sidecar['tags']]
22
23 file.seek(0)
24 yaml.dump(sidecar, file)
25 file.truncate()
diff --git a/viewer/src/components/LdProposition.vue b/viewer/src/components/LdProposition.vue
index 375c482..3357777 100644
--- a/viewer/src/components/LdProposition.vue
+++ b/viewer/src/components/LdProposition.vue
@@ -74,7 +74,7 @@ export default class LdProposition extends Vue {
74 } else { 74 } else {
75 // Tags count from the current directory 75 // Tags count from the current directory
76 this.currentTags 76 this.currentTags
77 .flatMap(tag => tag.split(".")) 77 .flatMap(tag => tag.split(":"))
78 .map(tag => this.tagsIndex[tag]) 78 .map(tag => this.tagsIndex[tag])
79 .forEach(tagindex => (propositions[tagindex.tag] = tagindex.items.length)); 79 .forEach(tagindex => (propositions[tagindex.tag] = tagindex.items.length));
80 } 80 }
@@ -89,7 +89,7 @@ export default class LdProposition extends Vue {
89 } 89 }
90 90
91 rightmost(tag: Gallery.RawTag): Gallery.RawTag { 91 rightmost(tag: Gallery.RawTag): Gallery.RawTag {
92 const dot = tag.lastIndexOf("."); 92 const dot = tag.lastIndexOf(":");
93 return dot <= 0 ? tag : tag.substr(dot + 1); 93 return dot <= 0 ? tag : tag.substr(dot + 1);
94 } 94 }
95 95
diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts
index a6bc865..6fed6cc 100644
--- a/viewer/src/services/indexfactory.ts
+++ b/viewer/src/services/indexfactory.ts
@@ -36,7 +36,7 @@ export default class IndexFactory {
36 return; // Directories are not indexed 36 return; // Directories are not indexed
37 } 37 }
38 for (const tag of item.tags) { 38 for (const tag of item.tags) {
39 const parts = tag.split('.'); 39 const parts = tag.split(':');
40 let lastPart: string | null = null; 40 let lastPart: string | null = null;
41 for (const part of parts) { 41 for (const part of parts) {
42 if (!tagsIndex[part]) tagsIndex[part] = { tag: part, tagfiltered: Navigation.normalize(part), items: [], children: {} }; 42 if (!tagsIndex[part]) tagsIndex[part] = { tag: part, tagfiltered: Navigation.normalize(part), items: [], children: {} };