3434</ head >
3535< body >
3636 < div class ="wrap ">
37- < aside class ="sidebar " id ="sidebar ">
38- < div class ="controls ">
39- < div style ="display:flex;gap:6px;flex:1 ">
40- < input id ="owner " placeholder ="owner " value ="octocat " />
41- < input id ="repo " placeholder ="repo " value ="Hello-World " />
42- </ div >
43- < button id ="loadBtn "> Load</ button >
44- </ div >
45- < div style ="display:flex;gap:8px;margin-bottom:10px ">
46- < input id ="path " placeholder ="path (leave empty for root) " style ="flex:1 " />
47- < input id ="token " placeholder ="GitHub token (optional) " style ="width:180px " />
48- </ div >
49-
50- < div id ="status " class ="small "> Enter owner/repo and click Load.</ div >
51- < hr style ="border:none;border-top:1px solid rgba(255,255,255,.03);margin:8px 0 ">
52- < nav id ="treeRoot " aria-label ="Repository tree "> </ nav >
53- </ aside >
37+ <!-- Left sidebar removed. Main viewer occupies full layout. -->
5438
5539 < main class ="main ">
5640 < div class ="viewer ">
57- < div class ="title " id ="fileTitle "> No file selected</ div >
58- < div class ="meta small " id ="fileMeta "> </ div >
59- < div class ="content " id ="fileContent "> Select a file in the tree to preview it here.</ div >
41+ < div class ="title " id ="fileTitle "> No file selected</ div >
42+ < div class ="meta small " id ="fileMeta "> </ div >
43+ < div id ="status " class ="small "> Status messages will appear here.</ div >
44+ < div class ="content " id ="fileContent "> Select a file in the tree to preview it here.</ div >
6045 </ div >
6146 </ main >
6247 </ div >
6348
6449 < script >
65- // GitHub Copilot: repo-browser single-file implementation
66- const loadBtn = document . getElementById ( 'loadBtn' ) ;
67- const ownerInput = document . getElementById ( 'owner' ) ;
68- const repoInput = document . getElementById ( 'repo' ) ;
69- const pathInput = document . getElementById ( 'path' ) ;
70- const tokenInput = document . getElementById ( 'token' ) ;
71- const treeRoot = document . getElementById ( 'treeRoot' ) ;
50+ // GitHub Copilot: repo-browser single-file implementation (sidebar removed)
51+ const params = new URLSearchParams ( location . search ) ;
52+ let owner = params . get ( 'owner' ) || 'octocat' ;
53+ let repo = params . get ( 'repo' ) || 'Hello-World' ;
54+ const token = params . get ( 'token' ) || '' ;
7255 const statusEl = document . getElementById ( 'status' ) ;
7356 const fileTitle = document . getElementById ( 'fileTitle' ) ;
7457 const fileContent = document . getElementById ( 'fileContent' ) ;
8063 }
8164
8265 function apiFetch ( url , opts = { } ) {
83- const token = tokenInput . value . trim ( ) ;
8466 const headers = opts . headers || { } ;
8567 headers [ 'Accept' ] = 'application/vnd.github.v3+json' ;
8668 if ( token ) headers [ 'Authorization' ] = 'token ' + token ;
133115 try {
134116 li . _loading = true ;
135117 setStatus ( 'Loading directory ' + entry . path + '...' ) ;
136- const data = await apiFetch ( `https://api.github.com/repos/${ ownerInput . value } /${ repoInput . value } /contents/${ encodeURIComponent ( entry . path ) } ` ) ;
118+ const data = await apiFetch ( `https://api.github.com/repos/${ owner } /${ repo } /contents/${ encodeURIComponent ( entry . path ) } ` ) ;
137119 renderDirectoryUnder ( li , data ) ;
138120 li . _loaded = true ;
139121 setStatus ( 'Directory loaded.' ) ;
151133 }
152134
153135 function renderDirectory ( entries ) {
154- treeRoot . innerHTML = '' ;
136+ const root = document . getElementById ( 'treeRoot' ) ;
137+ if ( ! root ) return ;
138+ root . innerHTML = '' ;
155139 const ul = document . createElement ( 'ul' ) ;
156140 ul . className = 'tree' ;
157141 entries . sort ( ( a , b ) => ( a . type === b . type ) ? a . name . localeCompare ( b . name ) : ( a . type === 'dir' ? - 1 : 1 ) ) ;
162146 wrapper . appendChild ( itemLi ) ;
163147 ul . appendChild ( wrapper ) ;
164148 } ) ;
165- treeRoot . appendChild ( ul ) ;
149+ root . appendChild ( ul ) ;
166150 }
167151
168152 function renderDirectoryUnder ( parentEl , entries ) {
189173 if ( entry . content ) {
190174 data = entry ;
191175 } else {
192- data = await apiFetch ( `https://api.github.com/repos/${ ownerInput . value } /${ repoInput . value } /contents/${ encodeURIComponent ( entry . path ) } ` ) ;
176+ data = await apiFetch ( `https://api.github.com/repos/${ owner } /${ repo } /contents/${ encodeURIComponent ( entry . path ) } ` ) ;
193177 }
194178 const b64 = data . content || '' ;
195179 const decoded = decodeBase64ToUtf8 ( b64 ) ;
234218 return s . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) ;
235219 }
236220
237- loadBtn . addEventListener ( 'click' , async ( ) => {
238- const owner = ownerInput . value . trim ( ) ;
239- const repo = repoInput . value . trim ( ) ;
221+ async function loadPosts ( owner , repo ) {
240222 if ( ! owner || ! repo ) {
241223 setStatus ( 'Owner and repo required' , true ) ;
242224 return ;
243225 }
244226 // We specifically load the `posts` directory and render each post's README
245227 const postsPath = 'posts' ;
246228 setStatus ( 'Loading posts directory...' ) ;
247- treeRoot . innerHTML = '' ;
248229 fileTitle . textContent = 'Posts' ;
249230 fileMeta . textContent = '' ;
250231 fileContent . innerHTML = '<div class="small">Loading posts... please wait.</div>' ;
326307 setStatus ( 'Failed to load posts: ' + err . message , true ) ;
327308 fileContent . innerHTML = `<div class="small" style="color:#ffb4b4">Failed to load posts: ${ err . message } </div>` ;
328309 }
329- } ) ;
310+ }
330311
331- // allow pressing Enter in inputs to load
332- [ ownerInput , repoInput , pathInput , tokenInput ] . forEach ( inp => {
333- inp . addEventListener ( 'keydown' , ( e ) => {
334- if ( e . key === 'Enter' ) loadBtn . click ( ) ;
335- } ) ;
336- } ) ;
312+ // Auto-load posts using query params or defaults
313+ loadPosts ( owner , repo ) ;
337314
338- // small convenience: if the page was opened with ?owner=&repo=&path=, prefill and auto-load
339- ( function prefillFromQuery ( ) {
340- const params = new URLSearchParams ( location . search ) ;
341- const o = params . get ( 'owner' ) , r = params . get ( 'repo' ) , p = params . get ( 'path' ) ;
342- if ( o ) ownerInput . value = o ;
343- if ( r ) repoInput . value = r ;
344- if ( p ) pathInput . value = p ;
345- if ( o && r ) loadBtn . click ( ) ;
346- } ) ( ) ;
315+ // inputs and sidebar removed; posts are auto-loaded from URL params or defaults
347316 </ script >
348317</ body >
349318</ html >
0 commit comments