From b0be6d6b6e8948b180e885aa485b97b7c416fe6c Mon Sep 17 00:00:00 2001 From: Tangent Date: Fri, 14 Jun 2019 17:47:18 -0700 Subject: [PATCH] close #7 and make tags all lowercase --- helpers.moon | 4 +--- migrations.moon | 12 ++++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/helpers.moon b/helpers.moon index c387e76..6b5a7e7 100644 --- a/helpers.moon +++ b/helpers.moon @@ -2,14 +2,12 @@ process_tags = (tags_str) -> -- split into a table to garuntee uniqueness unique = {} for tag in tags_str\gmatch "%S+" - unique[tag] = true + unique[tag\lower!] = true -- place back into an array taglist = {} for tag in pairs unique table.insert taglist, tag - -- sort case-sensitively and then case-insensitively (so capitalized tags appear before their uncapitalized counterparts) table.sort taglist - table.sort taglist, (a, b) -> a\lower! < b\lower! return " #{table.concat taglist, " "} " update_track = (user_input) -> diff --git a/migrations.moon b/migrations.moon index aaca4ea..6b69971 100644 --- a/migrations.moon +++ b/migrations.moon @@ -27,6 +27,7 @@ import Tracks from require "models" } add_column "tracks", unpack column [3]: => + -- NOTE: bad migration! for track in *Tracks\select "*" tags = "" for field in *{"artist", "mood", "link", "genre"} @@ -35,4 +36,15 @@ import Tracks from require "models" if #tags > 0 track.tags = process_tags trim(track.tags or "untagged") .. tags track\update "tags" + [4]: => + -- WARNING: removes all tags! + for track in *Tracks\select "*" + tags = "" + for field in *{"artist", "mood", "link", "genre"} + if track[field] and #track[field] > 0 + tags ..= " #{field}:#{track[field]}" + if #tags > 0 + track.tags = process_tags "untagged" .. tags + else + track.tags = " untagged " }