@@ -4,7 +4,7 @@ import {pathEscapeSegments} from '../utils/url.ts';
44import  { createElementFromHTML }  from  '../utils/dom.ts' ; 
55import  { html }  from  '../utils/html.ts' ; 
66
7- export  function  createViewFileTreeStore ( props : { repoLink : string ,  repoName :  string ,   treePath : string ,  currentRefNameSubURL : string } )  { 
7+ export  function  createViewFileTreeStore ( props : { repoLink : string ,  treePath : string ,  currentRefNameSubURL : string } )  { 
88  const  store  =  reactive ( { 
99    rootFiles : [ ] , 
1010    selectedItem : props . treePath , 
@@ -25,30 +25,24 @@ export function createViewFileTreeStore(props: {repoLink: string, repoName: stri
2525    } , 
2626
2727    async  loadViewContent ( url : string )  { 
28-       url  =  url . includes ( '?' )  ? url . replace ( '?' ,  '?only_content=true' )  : `${ url }  ?only_content=true` ; 
29-       const  response  =  await  GET ( url ) ; 
30-       document . querySelector ( '.repo-view-content' ) . innerHTML  =  await  response . text ( ) ; 
28+       const  u  =  new  URL ( url ,  window . origin ) ; 
29+       u . searchParams . set ( 'only_content' ,  '1' ) ; 
30+       const  response  =  await  GET ( u . href ) ; 
31+       const  elViewContent  =  document . querySelector ( '.repo-view-content' ) ; 
32+       elViewContent . innerHTML  =  await  response . text ( ) ; 
33+       document . title  =  elViewContent . querySelector ( '.repo-view-content-data' ) . getAttribute ( 'data-document-title' ) ; 
3134    } , 
3235
3336    async  navigateTreeView ( treePath : string )  { 
3437      const  url  =  store . buildTreePathWebUrl ( treePath ) ; 
35-       const  title  =  store . buildTitle ( store . selectedItem ,  treePath ) ; 
3638      window . history . pushState ( { treePath,  url} ,  null ,  url ) ; 
3739      store . selectedItem  =  treePath ; 
3840      await  store . loadViewContent ( url ) ; 
39-       document . title  =  title ; 
4041    } , 
4142
4243    buildTreePathWebUrl ( treePath : string )  { 
4344      return  `${ props . repoLink }  /src/${ props . currentRefNameSubURL }  /${ pathEscapeSegments ( treePath ) }  ` ; 
4445    } , 
45- 
46-     buildTitle ( oldTreePath : string ,  treePath : string )  { 
47-       // the title always starts with "<repoName>/<treePath>" 
48-       const  oldPrefixLength  =  props . repoName . length  +  1  +  oldTreePath . length ; 
49-       const  titleSuffix  =  document . title . substring ( oldPrefixLength ) ; 
50-       return  `${ props . repoName }  /${ treePath } ${ titleSuffix }  ` ; 
51-     } , 
5246  } ) ; 
5347  return  store ; 
5448} 
0 commit comments