11// Pure function that generates an nbgitpuller URL
2- function generateRegularUrl ( hubUrl , serverPath , urlPath , repoUrl , branch ) {
2+ function generateRegularUrl ( hubUrl , serverPath , urlPath , repoUrl , branch , targetPath ) {
33
44 // assume hubUrl is a valid URL
55 var url = new URL ( hubUrl ) ;
@@ -14,6 +14,10 @@ function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch) {
1414 url . searchParams . set ( 'branch' , branch ) ;
1515 }
1616
17+ if ( targetPath ) {
18+ url . searchParams . set ( 'targetPath' , targetPath ) ;
19+ }
20+
1721 if ( ! url . pathname . endsWith ( '/' ) ) {
1822 url . pathname += '/'
1923 }
@@ -27,7 +31,7 @@ function generateRegularUrl(hubUrl, serverPath, urlPath, repoUrl, branch) {
2731 return url . toString ( ) ;
2832}
2933
30- function generateCanvasUrl ( hubUrl , urlPath , repoUrl , branch ) {
34+ function generateCanvasUrl ( hubUrl , urlPath , repoUrl , branch , targetPath ) {
3135 // assume hubUrl is a valid URL
3236 var url = new URL ( hubUrl ) ;
3337
@@ -43,6 +47,10 @@ function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
4347 nextUrlParams . append ( 'branch' , branch ) ;
4448 }
4549
50+ if ( targetPath ) {
51+ nextUrlParams . append ( 'targetPath' , targetPath ) ;
52+ }
53+
4654 var nextUrl = '/hub/user-redirect/git-pull?' + nextUrlParams . toString ( ) ;
4755
4856 if ( ! url . pathname . endsWith ( '/' ) ) {
@@ -55,7 +63,7 @@ function generateCanvasUrl(hubUrl, urlPath, repoUrl, branch) {
5563}
5664
5765function generateBinderUrl ( hubUrl , userName , repoName , branch , urlPath ,
58- contentRepoUrl , contentRepoBranch ) {
66+ contentRepoUrl , contentRepoBranch , targetPath ) {
5967
6068 var url = new URL ( hubUrl ) ;
6169
@@ -71,6 +79,10 @@ function generateBinderUrl(hubUrl, userName, repoName, branch, urlPath,
7179 nextUrlParams . append ( 'branch' , contentRepoBranch ) ;
7280 }
7381
82+ if ( targetPath ) {
83+ nextUrlParams . append ( 'targetPath' , targetPath ) ;
84+ }
85+
7486 var nextUrl = 'git-pull?' + nextUrlParams . toString ( ) ;
7587
7688 var path = '/v2/gh/' ;
@@ -168,6 +180,7 @@ function displayLink() {
168180 var server = document . getElementById ( 'server' ) . value ;
169181 var appName = form . querySelector ( 'input[name="app"]:checked' ) . value ;
170182 var activeTab = document . querySelector ( ".nav-link.active" ) . id ;
183+ var targetPath = document . getElementById ( 'targetPath' ) . value ;
171184
172185 if ( appName === 'custom' ) {
173186 var urlPath = document . getElementById ( 'urlpath' ) . value ;
@@ -184,19 +197,19 @@ function displayLink() {
184197
185198 if ( activeTab === "tab-auth-default" ) {
186199 document . getElementById ( 'default-link' ) . value = generateRegularUrl (
187- hubUrl , server , urlPath , repoUrl , branch
200+ hubUrl , server , urlPath , repoUrl , branch , targetPath
188201 ) ;
189202 } else if ( activeTab === "tab-auth-canvas" ) {
190203 document . getElementById ( 'canvas-link' ) . value = generateCanvasUrl (
191- hubUrl , urlPath , repoUrl , branch
204+ hubUrl , urlPath , repoUrl , branch , targetPath
192205 ) ;
193206 } else if ( activeTab === "tab-auth-binder" ) {
194207 // FIXME: userName parsing using new URL(...) assumes a
195208 // HTTP based repoUrl. Does it make sense to create a
196209 // BinderHub link for SSH URLs? Then let's fix this parsing.
197210 var userName = new URL ( repoUrl ) . pathname . split ( '/' ) [ 1 ] ;
198211 document . getElementById ( 'binder-link' ) . value = generateBinderUrl (
199- hubUrl , userName , repoName , branch , urlPath , contentRepoUrl , contentRepoBranch
212+ hubUrl , userName , repoName , branch , urlPath , contentRepoUrl , contentRepoBranch , targetPath
200213 ) ;
201214 }
202215 }
@@ -289,4 +302,4 @@ function copyLink(elementId) {
289302 copyText . select ( ) ;
290303 copyText . setSelectionRange ( 0 , copyText . value . length ) ;
291304 navigator . clipboard . writeText ( copyText . value ) ;
292- }
305+ }
0 commit comments