|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | var OWNER = 'temesotejam'; |
| 5 | + var SELF_REPO = 'github-tavern'; |
5 | 6 | var API = 'https://api.github.com'; |
6 | 7 | var SUMMARY_URL = './data/summaries.json'; |
7 | 8 | var TIMEOUT = 8000; |
|
17 | 18 | detailTitle: id('detailTitle'), detailRepo: id('detailRepo'), keeperText: id('keeperText'), detailMeta: id('detailMeta'), |
18 | 19 | detailDescription: id('detailDescription'), featureSection: id('featureSection'), featureList: id('featureList'), |
19 | 20 | techSection: id('techSection'), techList: id('techList'), repoLink: id('repoLink'), pagesLink: id('pagesLink'), |
20 | | - summarySource: id('summarySource') |
| 21 | + summarySource: id('summarySource'), selfSummary: id('selfSummary'), selfUpdated: id('selfUpdated'), |
| 22 | + selfSource: id('selfSource'), selfKeeperRow: id('selfKeeperRow'), selfKeeper: id('selfKeeper'), selfRepoLink: id('selfRepoLink') |
21 | 23 | }; |
22 | 24 |
|
23 | | - var state = { repos: [], summaries: {}, category: 'all', query: '', sort: 'updated', selectedRow: 0, pendingRepo: null, liveApi: false }; |
| 25 | + var state = { repos: [], selfRepo: null, summaries: {}, category: 'all', query: '', sort: 'updated', selectedRow: 0, pendingRepo: null, liveApi: false }; |
24 | 26 |
|
25 | 27 | var RULES = [ |
26 | 28 | { id: 'learning', label: '学習・AI', words: ['reinforcement','learning','ppo','sac','td3','acrobot','cartpole','強化学習','機械学習',' ai '] }, |
|
55 | 57 | return fetch(url, opts).finally(function(){ clearTimeout(timer); }); |
56 | 58 | } |
57 | 59 | function summaryFor(repo) { return state.summaries[repo.name] || null; } |
| 60 | + function setRepos(list) { |
| 61 | + var archive = []; |
| 62 | + var self = null; |
| 63 | + (list || []).forEach(function(repo){ |
| 64 | + if (repo && repo.name === SELF_REPO) self = repo; |
| 65 | + else if (repo) archive.push(repo); |
| 66 | + }); |
| 67 | + if (self) state.selfRepo = self; |
| 68 | + state.repos = archive; |
| 69 | + } |
| 70 | + function renderSelf() { |
| 71 | + var s = state.summaries[SELF_REPO] || {}; |
| 72 | + var repo = state.selfRepo || {}; |
| 73 | + var summary = s.summary || repo.description || 'Project Tavernは、公開GitHubリポジトリを古い情報端末のように探索するためのアーカイブ端末だ。'; |
| 74 | + var updated = repo.pushed_at || repo.updated_at || s.sourcePushedAt || s.generatedAt || ''; |
| 75 | + els.selfSummary.textContent = summary; |
| 76 | + els.selfUpdated.textContent = 'UPDATED ' + fmtDate(updated); |
| 77 | + els.selfSource.textContent = s.summary ? 'COPILOT ANALYSIS / ' + fmtDate(s.generatedAt) : 'REPOSITORY METADATA'; |
| 78 | + els.selfRepoLink.href = repo.html_url || ('https://github.com/' + OWNER + '/' + SELF_REPO); |
| 79 | + var closing = String(s.closingRemark || '').trim(); |
| 80 | + els.selfKeeperRow.hidden = !closing; |
| 81 | + els.selfKeeper.textContent = closing; |
| 82 | + } |
58 | 83 | function textFor(repo) { |
59 | 84 | var s = summaryFor(repo) || {}; |
60 | 85 | return [repo.name, repo.description, repo.language].concat(repo.topics || [], [s.title,s.summary,s.detail], s.technologies || [], s.categories || []).filter(Boolean).join(' ').toLowerCase(); |
|
297 | 322 | var liveError=null; |
298 | 323 | var livePromise=fetchLive().catch(function(e){liveError=e;return null;}); |
299 | 324 | fetchCache().then(function(data){ |
300 | | - state.summaries=data.repositories||{}; state.repos=reposFromCache(data); status('CACHE'); renderRepos(); |
| 325 | + state.summaries=data.repositories||{}; setRepos(reposFromCache(data)); renderSelf(); status('CACHE'); renderRepos(); |
301 | 326 | return livePromise; |
302 | 327 | }).then(function(live){ |
303 | | - if(live&&live.length){state.repos=live;state.liveApi=true;status('LIVE API');renderRepos();} |
| 328 | + if(live&&live.length){setRepos(live);state.liveApi=true;renderSelf();status('LIVE API');renderRepos();} |
304 | 329 | else if(state.repos.length){status(liveError&&liveError.name==='AbortError'?'API TIMEOUT / CACHE':'API UNAVAILABLE / CACHE');} |
305 | 330 | }).catch(function(err){ |
306 | 331 | livePromise.then(function(live){ |
307 | | - if(live&&live.length){state.repos=live;state.liveApi=true;status('LIVE API / SUMMARY unavailable');renderRepos();} |
| 332 | + if(live&&live.length){setRepos(live);state.liveApi=true;renderSelf();status('LIVE API / SUMMARY unavailable');renderRepos();} |
308 | 333 | else {els.notice.classList.add('is-error');els.noticeText.textContent='記録を取得できませんでした: '+err.message;els.count.textContent='0 RECORDS';els.grid.innerHTML='';} |
309 | 334 | }); |
310 | 335 | }); |
|
0 commit comments