@@ -47,15 +47,14 @@ function addContentAccessQuery(note: SNote | BNote, secondEl?:boolean) {
4747 return ""
4848}
4949
50- function getSharedSubTreeRoot ( note : SNote | BNote | undefined ) : Subroot {
50+ export function getSharedSubTreeRoot ( note : SNote | BNote | undefined , parentId : string | undefined = undefined ) : Subroot {
5151 if ( ! note || note . noteId === shareRoot . SHARE_ROOT_NOTE_ID ) {
5252 // share root itself is not shared
5353 return { } ;
5454 }
5555
56- // every path leads to share root, but which one to choose?
57- // for the sake of simplicity, URLs are not note paths
58- const parentBranch = note . getParentBranches ( ) [ 0 ] ;
56+ const parentBranches = note . getParentBranches ( )
57+ const parentBranch = ( parentId ? parentBranches . find ( ( pb : SBranch | BBranch ) => pb . parentNoteId === parentId ) : undefined ) || parentBranches [ 0 ] ;
5958
6059 if ( note instanceof BNote ) {
6160 return {
@@ -71,7 +70,7 @@ function getSharedSubTreeRoot(note: SNote | BNote | undefined): Subroot {
7170 } ;
7271 }
7372
74- return getSharedSubTreeRoot ( parentBranch . getParentNote ( ) ) ;
73+ return getSharedSubTreeRoot ( parentBranch . getParentNote ( ) , parentId ) ;
7574}
7675
7776export function renderNoteForExport ( note : BNote , parentBranch : BBranch , basePath : string , ancestors : string [ ] ) {
@@ -98,7 +97,7 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
9897}
9998
10099export function renderNoteContent ( note : SNote ) {
101- const subRoot = getSharedSubTreeRoot ( note ) ;
100+ const subRoot = getSharedSubTreeRoot ( note , note . parentId ) ;
102101
103102 const ancestors : string [ ] = [ ] ;
104103 let notePointer = note ;
@@ -114,23 +113,23 @@ export function renderNoteContent(note: SNote) {
114113 // Determine CSS to load.
115114 const cssToLoad : string [ ] = [ ] ;
116115 if ( ! note . isLabelTruthy ( "shareOmitDefaultCss" ) ) {
117- cssToLoad . push ( `assets/styles.css` ) ;
118- cssToLoad . push ( `assets/scripts.css` ) ;
116+ cssToLoad . push ( `../ assets/styles.css` ) ;
117+ cssToLoad . push ( `../ assets/scripts.css` ) ;
119118 }
120119 for ( const cssRelation of note . getRelations ( "shareCss" ) ) {
121- cssToLoad . push ( `api/notes/${ cssRelation . value } /download${ addContentAccessQuery ( note ) } ` ) ;
120+ cssToLoad . push ( `../ api/notes/${ cssRelation . value } /download${ addContentAccessQuery ( note ) } ` ) ;
122121 }
123122
124123 // Determine JS to load.
125124 const jsToLoad : string [ ] = [
126- "assets/scripts.js"
125+ "../ assets/scripts.js"
127126 ] ;
128127 for ( const jsRelation of note . getRelations ( "shareJs" ) ) {
129- jsToLoad . push ( `api/notes/${ jsRelation . value } /download${ addContentAccessQuery ( note ) } ` ) ;
128+ jsToLoad . push ( `../ api/notes/${ jsRelation . value } /download${ addContentAccessQuery ( note ) } ` ) ;
130129 }
131130
132131 const customLogoId = note . getRelation ( "shareLogo" ) ?. value ;
133- const logoUrl = customLogoId ? `api/images/${ customLogoId } /image.png${ addContentAccessQuery ( note ) } ` : `../${ assetUrlFragment } /images/icon-color.svg` ;
132+ const logoUrl = customLogoId ? `../ api/images/${ customLogoId } /image.png${ addContentAccessQuery ( note ) } ` : `../ ../${ assetUrlFragment } /images/icon-color.svg` ;
134133
135134 return renderNoteContentInternal ( note , {
136135 subRoot,
@@ -140,7 +139,7 @@ export function renderNoteContent(note: SNote) {
140139 logoUrl,
141140 ancestors,
142141 isStatic : false ,
143- faviconUrl : note . hasRelation ( "shareFavicon" ) ? `api/notes/${ note . getRelationValue ( "shareFavicon" ) } /download${ addContentAccessQuery ( note ) } ` : `../favicon.ico`
142+ faviconUrl : note . hasRelation ( "shareFavicon" ) ? `../ api/notes/${ note . getRelationValue ( "shareFavicon" ) } /download${ addContentAccessQuery ( note ) } ` : `../ ../favicon.ico`
144143 } ) ;
145144}
146145
@@ -365,7 +364,7 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: GetNot
365364 const attachment = getAttachment ( attachmentId ) ;
366365
367366 if ( attachment ) {
368- linkEl . setAttribute ( "href" , `api/attachments/${ attachmentId } /download${ addContentAccessQuery ( note ) } ` ) ;
367+ linkEl . setAttribute ( "href" , `../ api/attachments/${ attachmentId } /download${ addContentAccessQuery ( note ) } ` ) ;
369368 linkEl . classList . add ( `attachment-link` ) ;
370369 linkEl . classList . add ( `role-${ attachment . role } ` ) ;
371370 linkEl . childNodes . length = 0 ;
@@ -381,7 +380,7 @@ function handleAttachmentLink(linkEl: HTMLElement, href: string, getNote: GetNot
381380 const linkedNote = getNote ( noteId ) ;
382381 if ( linkedNote ) {
383382 const isExternalLink = linkedNote . hasLabel ( "shareExternalLink" ) ;
384- const href = isExternalLink ? linkedNote . getLabelValue ( "shareExternalLink" ) : `./${ linkedNote . shareId } ` ;
383+ const href = isExternalLink ? linkedNote . getLabelValue ( "shareExternalLink" ) : `.. /${ linkedNote . shareId } ` ;
385384 if ( href ) {
386385 linkEl . setAttribute ( "href" , href ) ;
387386 }
@@ -438,7 +437,7 @@ function renderMermaid(result: Result, note: SNote | BNote) {
438437 }
439438
440439 result . content = `
441- <img src="api/images/${ note . noteId } /${ note . encodedTitle } ?${ note . utcDateModified } ${ addContentAccessQuery ( note , true ) } ">
440+ <img src="../ api/images/${ note . noteId } /${ note . encodedTitle } ?${ note . utcDateModified } ${ addContentAccessQuery ( note , true ) } ">
442441<hr>
443442<details>
444443 <summary>Chart source</summary>
@@ -447,14 +446,14 @@ function renderMermaid(result: Result, note: SNote | BNote) {
447446}
448447
449448function renderImage ( result : Result , note : SNote | BNote ) {
450- result . content = `<img src="api/images/${ note . noteId } /${ note . encodedTitle } ?${ note . utcDateModified } ${ addContentAccessQuery ( note , true ) } ">` ;
449+ result . content = `<img src="../ api/images/${ note . noteId } /${ note . encodedTitle } ?${ note . utcDateModified } ${ addContentAccessQuery ( note , true ) } ">` ;
451450}
452451
453452function renderFile ( note : SNote | BNote , result : Result ) {
454453 if ( note . mime === "application/pdf" ) {
455- result . content = `<iframe class="pdf-view" src="api/notes/${ note . noteId } /view${ addContentAccessQuery ( note ) } "></iframe>` ;
454+ result . content = `<iframe class="pdf-view" src="../ api/notes/${ note . noteId } /view${ addContentAccessQuery ( note ) } "></iframe>` ;
456455 } else {
457- result . content = `<button type="button" onclick="location.href='api/notes/${ note . noteId } /download${ addContentAccessQuery ( note ) } '">Download file</button>` ;
456+ result . content = `<button type="button" onclick="location.href='../ api/notes/${ note . noteId } /download${ addContentAccessQuery ( note ) } '">Download file</button>` ;
458457 }
459458}
460459
0 commit comments