mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-16 08:01:39 +00:00
reworked .paths(), now it will search subpaths too...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
232bcc603a
commit
617dac9ce3
@ -34,6 +34,8 @@ store.update('System',
|
||||
|
||||
var pwiki =
|
||||
module.pwiki =
|
||||
// XXX
|
||||
//page.DOMPage('/', '/', store)
|
||||
page.Page('/', '/', store)
|
||||
|
||||
|
||||
|
||||
@ -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...
|
||||
|
||||
@ -1190,5 +1205,6 @@ module.System = {
|
||||
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* vim:set ts=4 sw=4 nowrap : */ return module })
|
||||
|
||||
@ -124,7 +124,15 @@ module = {
|
||||
//
|
||||
// NOTE: if seen is given (when called recursively) this will not
|
||||
// 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 '/'???
|
||||
paths: function*(path='/', strict=false){
|
||||
if(path === true || path === false){
|
||||
@ -159,16 +167,23 @@ module = {
|
||||
var page = path.pop()
|
||||
for(var tpl of ['.', ...this.SEARCH_PATHS]){
|
||||
// search for page up the path...
|
||||
var p = path.slice()
|
||||
while(p.length > 0){
|
||||
var cur = this.relative(p, tpl +'/'+ page, 'string')
|
||||
if(!seen.has(cur)){
|
||||
seen.add(cur)
|
||||
yield cur }
|
||||
// special case: non-relative template/page path...
|
||||
if(tpl[0] == '/'){
|
||||
break }
|
||||
p.pop() } }
|
||||
var pg = page
|
||||
var base = path.slice()
|
||||
while(base.length > 0){
|
||||
var p = base.slice()
|
||||
while(p.length > 0){
|
||||
var cur = this.relative(p, tpl +'/'+ pg, 'string')
|
||||
if(!seen.has(cur)){
|
||||
seen.add(cur)
|
||||
yield cur }
|
||||
// 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...
|
||||
if(alt_pages){
|
||||
for(var page of [...this.ALTERNATIVE_PAGES]){
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
var object = require('ig-object')
|
||||
|
||||
var pwiki = require('./pwiki2')
|
||||
module.path = pwiki.path
|
||||
|
||||
// XXX for some reason this does not run quietly in browser
|
||||
var pouchdbstore = require('./pwiki/store/pouchdb')
|
||||
|
||||
30
pwiki2.html
30
pwiki2.html
@ -83,10 +83,18 @@ require.config({
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
document.pwikiloaded = new Event('pwikiloaded')
|
||||
|
||||
|
||||
// start loading pWiki...
|
||||
require(['./browser'], function(m){
|
||||
window.pwiki = m.pwiki
|
||||
|
||||
// XXX make a pWikiDom page to manage this...
|
||||
pwiki.dom = document.querySelector('#pWiki')
|
||||
|
||||
|
||||
// handle location.hash (both directions)
|
||||
var _debounceHashChange = false
|
||||
pwiki.onNavigate(async function(){
|
||||
@ -96,7 +104,13 @@ require(['./browser'], function(m){
|
||||
setTimeout(function(){
|
||||
_debounceHashChange = false }, 0)
|
||||
// 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){
|
||||
evt.preventDefault()
|
||||
if(_debounceHashChange){
|
||||
@ -105,7 +119,19 @@ require(['./browser'], function(m){
|
||||
path = path.trim() == '' ?
|
||||
'/'
|
||||
: 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...
|
||||
pwiki.path = location.hash.slice(1)
|
||||
|
||||
@ -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 BUG? /test/wikiword -- produces nested links...
|
||||
*
|
||||
@ -120,7 +125,9 @@
|
||||
var object = require('ig-object')
|
||||
var types = require('ig-types')
|
||||
|
||||
var pwpath = require('./pwiki/path')
|
||||
var pwpath =
|
||||
module.path =
|
||||
require('./pwiki/path')
|
||||
var page = require('./pwiki/page')
|
||||
|
||||
var basestore = require('./pwiki/store/base')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user