From 01e59af5a198676851986829b8e21ac1b46b8192 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 26 Oct 2022 19:54:22 +0300 Subject: [PATCH] added masic tag listing... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 24 ++++++++++++++++-------- pwiki/store/base.js | 12 ++++++++++++ pwiki2.js | 6 ++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index 2ec27cb..bf17ae1 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -76,8 +76,8 @@ object.Constructor('BasePage', { type: true, ctime: true, mtime: true, - // XXX TAGS HACK -- should this be a list??? - tags: 'tagstr', + // XXX + //tags: true, }, // These actions will be default get :$ARGS appended if no args are // explicitly given... @@ -358,9 +358,6 @@ object.Constructor('BasePage', { ...(await this.data), tags: [...value], } }.call(this) }, - // XXX TAGS HACK -- should this be a list??? - get tagstr(){ return async function(){ - return JSON.stringify(await this.tags ?? []).slice(1,-1) }.call(this) }, tag: async function(...tags){ this.tags = [...new Set([ ...(await this.tags), @@ -2065,7 +2062,7 @@ module.System = { type: @source(../type)
- tags: @source(../tags)
+ tags: @source(../tags join=", ")
ctime: @source(../ctime)
mtime: @source(../mtime)
@@ -2077,8 +2074,19 @@ module.System = { stores: function(){ return Object.keys(this.store.substores ?? {}) }, - tagslist: function(){ - return this.tags }, + // tags... + // + // XXX should these be actions??? + // ...actions do not yet support lists/generators... + tags: async function*(){ + yield* this.get('..').tags }, + allTags: async function*(){ + yield* Object.keys((await this.store.tags).tags) }, + relatedTags: async function*(){ + yield* this.store.relatedTags( + ...((await this.args.tags) + ?? this.get('..').tags + ?? [])) }, // page parts... // diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 4b3fefe..2cf8172 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -282,6 +282,18 @@ module.BaseStore = { get tags(){ return this.__tags() }, + relatedTags: function*(...tags){ + var cur = tags + var {tags, paths} = this.tags + var seen = new Set() + for(var tag of cur){ + for(var p of tags[tag] ?? []){ + for(var t of paths[p] ?? []){ + if(!seen.has(t)){ + seen.add(t) + yield t } } } } }, + + // XXX text search index (???) diff --git a/pwiki2.js b/pwiki2.js index 292d770..510bed6 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -17,6 +17,12 @@ * - CLI * * +* XXX BUG: +* await pwiki.parse('@source(/Test/list/static join=", ")') +* -> 'abcdef, abcdef, abcdef, abcdef, abcdef, abcdef' +* should be: +* await pwiki.parse('@source(/Test/list/static join=", ")') +* -> 'a, b, c, d, e, f' * XXX TAGS should ./tags (i.e. .tagstr) return a list of tags??? * XXX TAGS * - add tags to page -- macro/filter