From 9343c4f0c4bafae1d76735d6ca9fbfa1d8e8e3e3 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 26 Oct 2022 17:17:06 +0300 Subject: [PATCH] added .toggleTags(..)... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pwiki/page.js b/pwiki/page.js index d6a733b..8d99c15 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -339,6 +339,8 @@ object.Constructor('BasePage', { } else { this.__update__(value) } }, + // tags... + // get tags(){ return async function(){ return (await this.data).tags ?? [] }.call(this) }, set tags(value){ return async function(){ @@ -348,7 +350,7 @@ object.Constructor('BasePage', { } }.call(this) }, // XXX TAGS HACK -- should this be a list??? get tagstr(){ return async function(){ - return JSON.stringify(await this.tags ?? []) }.call(this) }, + return JSON.stringify(await this.tags ?? []).slice(1,-1) }.call(this) }, tag: async function(...tags){ this.tags = [...new Set([ ...(await this.tags), @@ -360,6 +362,14 @@ object.Constructor('BasePage', { .filter(function(tag){ return !tags.includes(tag) }) return this }, + toggleTags: async function(...tags){ + var t = new Set(await this.tags) + for(var tag of tags){ + t.has(tag) ? + t.delete(tag) + : t.add(tag) } + this.tags = t + return this }, // metadata... //