reworked .paths(), now it will search subpaths too...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-08-06 11:09:25 +03:00
parent 232bcc603a
commit 617dac9ce3
6 changed files with 81 additions and 14 deletions

View File

@ -34,6 +34,8 @@ store.update('System',
var pwiki = var pwiki =
module.pwiki = module.pwiki =
// XXX
//page.DOMPage('/', '/', store)
page.Page('/', '/', store) page.Page('/', '/', store)

View File

@ -1087,6 +1087,21 @@ object.Constructor('Page', BasePage, {
//---------------------------------------------------------------------
// XXX do we actually need this???
var DOMPage =
module.DOMPage =
object.Constructor('DOMPage', Page, {
dom: undefined,
// XXX might be a good idea to move this up to Page and trigger when
// done updating...
onLoad: types.event.Event('onLoad'),
})
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// System pages/actions... // System pages/actions...
@ -1190,5 +1205,6 @@ module.System = {
/********************************************************************** /**********************************************************************
* vim:set ts=4 sw=4 nowrap : */ return module }) * vim:set ts=4 sw=4 nowrap : */ return module })

View File

@ -124,7 +124,15 @@ module = {
// //
// NOTE: if seen is given (when called recursively) this will not // NOTE: if seen is given (when called recursively) this will not
// search for .ALTERNATIVE_PAGES... // search for .ALTERNATIVE_PAGES...
// XXX should we search for each path element or just the last one (current)??? // NOTE: this will search for basename and each subpath, e.g:
// a/b/c
// -> a/b/c/d
// -> a/c/d
// -> c/d
// -> d
// // now search for 'c/d'...
// -> a/c/d
// -> ...
// XXX should we keep the trailing '/'??? // XXX should we keep the trailing '/'???
paths: function*(path='/', strict=false){ paths: function*(path='/', strict=false){
if(path === true || path === false){ if(path === true || path === false){
@ -159,16 +167,23 @@ module = {
var page = path.pop() var page = path.pop()
for(var tpl of ['.', ...this.SEARCH_PATHS]){ for(var tpl of ['.', ...this.SEARCH_PATHS]){
// search for page up the path... // search for page up the path...
var p = path.slice() var pg = page
while(p.length > 0){ var base = path.slice()
var cur = this.relative(p, tpl +'/'+ page, 'string') while(base.length > 0){
if(!seen.has(cur)){ var p = base.slice()
seen.add(cur) while(p.length > 0){
yield cur } var cur = this.relative(p, tpl +'/'+ pg, 'string')
// special case: non-relative template/page path... if(!seen.has(cur)){
if(tpl[0] == '/'){ seen.add(cur)
break } yield cur }
p.pop() } } // special case: non-relative template/page path...
if(tpl[0] == '/'){
break }
p.pop() }
// next search for tail sub-path...
// for a/b/c
// c in a/b -> b/c in a
pg = base.pop() +'/'+ pg } }
// alternative pages... // alternative pages...
if(alt_pages){ if(alt_pages){
for(var page of [...this.ALTERNATIVE_PAGES]){ for(var page of [...this.ALTERNATIVE_PAGES]){

View File

@ -10,6 +10,7 @@
var object = require('ig-object') var object = require('ig-object')
var pwiki = require('./pwiki2') var pwiki = require('./pwiki2')
module.path = pwiki.path
// XXX for some reason this does not run quietly in browser // XXX for some reason this does not run quietly in browser
var pouchdbstore = require('./pwiki/store/pouchdb') var pouchdbstore = require('./pwiki/store/pouchdb')

View File

@ -83,10 +83,18 @@ require.config({
] ]
}) })
document.pwikiloaded = new Event('pwikiloaded')
// start loading pWiki... // start loading pWiki...
require(['./browser'], function(m){ require(['./browser'], function(m){
window.pwiki = m.pwiki window.pwiki = m.pwiki
// XXX make a pWikiDom page to manage this...
pwiki.dom = document.querySelector('#pWiki')
// handle location.hash (both directions) // handle location.hash (both directions)
var _debounceHashChange = false var _debounceHashChange = false
pwiki.onNavigate(async function(){ pwiki.onNavigate(async function(){
@ -96,7 +104,13 @@ require(['./browser'], function(m){
setTimeout(function(){ setTimeout(function(){
_debounceHashChange = false }, 0) _debounceHashChange = false }, 0)
// render... // render...
document.querySelector('#pWiki').innerHTML = await this.text }) pwiki.dom.innerHTML = await this.text
// pwiki page loaded event...
// XXX do we need to use a MutationObserver here to trigger this
// after the above is done loading???
// (see: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)
pwiki.dom.dispatchEvent(document.pwikiloaded) })
window.addEventListener('hashchange', function(evt){ window.addEventListener('hashchange', function(evt){
evt.preventDefault() evt.preventDefault()
if(_debounceHashChange){ if(_debounceHashChange){
@ -105,7 +119,19 @@ require(['./browser'], function(m){
path = path.trim() == '' ? path = path.trim() == '' ?
'/' '/'
: path : path
pwiki.path = path }) pwiki.path = path
// XXX when loaded us <elem>.scrollIntoView() to get to hash...
// ...would also be nice to keep hash within location.hash...
})
// XXX use a pwiki.onLoad event...
pwiki.dom.addEventListener('pwikiloaded', function(evt){
console.log('pWiki loaded')
// XXX scroll
})
// show current page... // show current page...
pwiki.path = location.hash.slice(1) pwiki.path = location.hash.slice(1)

View File

@ -1,6 +1,11 @@
/********************************************************************** /**********************************************************************
* *
* *
* XXX shoul Doc/About be found from both / and /WikiHome???
* ...currently / + Doc/About reolves correctly while
* /WikiHome + Doc/About is not found...
* ...this is a questions of subpath search, i.e. when we do not
* find "About" should we search for Doc/About and so on...
* XXX wikiword filter seems to act up on / * XXX wikiword filter seems to act up on /
* XXX BUG? /test/wikiword -- produces nested links... * XXX BUG? /test/wikiword -- produces nested links...
* *
@ -120,7 +125,9 @@
var object = require('ig-object') var object = require('ig-object')
var types = require('ig-types') var types = require('ig-types')
var pwpath = require('./pwiki/path') var pwpath =
module.path =
require('./pwiki/path')
var page = require('./pwiki/page') var page = require('./pwiki/page')
var basestore = require('./pwiki/store/base') var basestore = require('./pwiki/store/base')