mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
'.' and '..' now supported in path...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
02bf51ca96
commit
de8595e2ce
@ -53,10 +53,7 @@ var activateWikiWords = text =>
|
|||||||
text
|
text
|
||||||
// set new...
|
// set new...
|
||||||
.replace(
|
.replace(
|
||||||
RegExp('('+[
|
Wiki.__wiki_link__,
|
||||||
'[A-Z][a-z0-9]+[A-Z\/][a-zA-Z0-9\/]*',
|
|
||||||
'\\[[^\\]]+\\]',
|
|
||||||
].join('|') +')', 'g'),
|
|
||||||
'<a class="WikiWord" href="#" onclick="go($(this).text().replace(/^\\[|\\]$/g, \'\'))">$1</a>')
|
'<a class="WikiWord" href="#" onclick="go($(this).text().replace(/^\\[|\\]$/g, \'\'))">$1</a>')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
55
wiki.js
55
wiki.js
@ -28,36 +28,69 @@ var data = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
var path2lst = path =>
|
var path2lst = path =>
|
||||||
(path instanceof Array ?
|
(path instanceof Array ? path : path.split(/[\\\/]+/g))
|
||||||
path
|
// handle '..' (lookahead) and trim path elements...
|
||||||
: path.split(/[\\\/]+/g))
|
// NOTE: this will not touch the leading '.' or '..'
|
||||||
.map(p => p.trim())
|
.map((p, i, l) =>
|
||||||
|
(i > 0 && (p.trim() == '..' || p.trim() == '.')
|
||||||
|
|| (l[i+1] || '').trim() == '..') ?
|
||||||
|
null
|
||||||
|
: p.trim())
|
||||||
|
// cleanup and clear '.'...
|
||||||
.filter(p =>
|
.filter(p =>
|
||||||
p != '' && p != '.')
|
p != null && p != '')
|
||||||
|
|
||||||
var normalizePath = path =>
|
var normalizePath = path =>
|
||||||
path2lst(path).join('/')
|
path2lst(path).join('/')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*********************************************************************/
|
||||||
|
|
||||||
var Wiki = {
|
var Wiki = {
|
||||||
__wiki_data: data,
|
__wiki_data: data,
|
||||||
|
|
||||||
__home_page__: 'WikiHome',
|
__home_page__: 'WikiHome',
|
||||||
__default_page__: 'EmptyPage',
|
__default_page__: 'EmptyPage',
|
||||||
__templates__: 'Templates',
|
__templates__: 'Templates',
|
||||||
|
//__redirect_template__: 'RedirectTemplate',
|
||||||
|
|
||||||
__wiki_link__: RegExp('('+[
|
__wiki_link__: RegExp('('+[
|
||||||
'[A-Z][a-z0-9]+[A-Z\/][a-zA-Z0-9\/]*',
|
'(\\./|\\.\\./|[A-Z][a-z0-9]+[A-Z/])[a-zA-Z0-9/]*',
|
||||||
'\\[[^\\]]+\\]',
|
'\\[[^\\]]+\\]',
|
||||||
].join('|') +')', 'g'),
|
].join('|') +')', 'g'),
|
||||||
|
|
||||||
|
|
||||||
|
// Resolve '.' and '..' relative to current page...
|
||||||
|
//
|
||||||
|
// With the .path set to A/B/C, this will resolve the folowing to:
|
||||||
|
// '.' -> 'A/B'
|
||||||
|
// '..' -> 'A'
|
||||||
|
// './X' -> 'A/B/X'
|
||||||
|
// '../X' -> 'A/X'
|
||||||
|
//
|
||||||
|
resolveDotPath: function(path){
|
||||||
|
path = normalizePath(path)
|
||||||
|
// '.' or './*'
|
||||||
|
return path == '.' || /^\.\//.test(path) ?
|
||||||
|
path.replace(/^\./, this.dir)
|
||||||
|
// '..' or '../*'
|
||||||
|
: path == '..' || /^\.\.\//.test(path) ?
|
||||||
|
path.replace(/^\.\./,
|
||||||
|
normalizePath(path2lst(this.dir).slice(0, -1)))
|
||||||
|
: path
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// current location...
|
// current location...
|
||||||
get location(){
|
get location(){
|
||||||
return this.__location || this.__home_page__ },
|
return this.__location || this.__home_page__ },
|
||||||
set location(value){
|
set location(value){
|
||||||
this.__location = normalizePath(value) },
|
this.__location = this.resolveDotPath(value) },
|
||||||
|
|
||||||
// page path...
|
// page path...
|
||||||
//
|
//
|
||||||
@ -72,7 +105,7 @@ var Wiki = {
|
|||||||
get path(){
|
get path(){
|
||||||
return this.location },
|
return this.location },
|
||||||
set path(value){
|
set path(value){
|
||||||
value = normalizePath(value)
|
value = this.resolveDotPath(value)
|
||||||
|
|
||||||
var l = this.location
|
var l = this.location
|
||||||
|
|
||||||
@ -205,7 +238,7 @@ var Wiki = {
|
|||||||
// - explicit path
|
// - explicit path
|
||||||
// - .title in path
|
// - .title in path
|
||||||
// - .title in templates
|
// - .title in templates
|
||||||
// - aquire default page (same order as above)
|
// - aquire empty page (same order as above)
|
||||||
//
|
//
|
||||||
get text(){
|
get text(){
|
||||||
return (this.acquireData() || {}).text || '' },
|
return (this.acquireData() || {}).text || '' },
|
||||||
@ -231,11 +264,9 @@ var Wiki = {
|
|||||||
return links
|
return links
|
||||||
},
|
},
|
||||||
|
|
||||||
// XXX
|
// XXX list children/sub-pages...
|
||||||
get list(){
|
get list(){
|
||||||
},
|
},
|
||||||
set list(value){
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
exists: function(path){
|
exists: function(path){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user