()
| 81 | }); |
| 82 | |
| 83 | async function init(): Promise<void> { |
| 84 | // Construct class only when it's needed, as it is relatively expensive |
| 85 | const dateFormatter = new Intl.DateTimeFormat('en-US', { |
| 86 | year: 'numeric', |
| 87 | month: 'long', |
| 88 | day: 'numeric', |
| 89 | }); |
| 90 | |
| 91 | const [firstCommitDate, lastCommitsPageUrl] = await firstCommit.get(); |
| 92 | const birthday = new Date(firstCommitDate); |
| 93 | |
| 94 | // `twas` could also return `an hour ago` or `just now` |
| 95 | const [value, unit] = twas(birthday.getTime()) |
| 96 | .replace('just now', '1 second') |
| 97 | .replace(/^an?/, '1') |
| 98 | .split(' '); |
| 99 | |
| 100 | // About a day old or less ? |
| 101 | const age = Date.now() - birthday.getTime() < 10e7 |
| 102 | ? randomArrayItem(fresh) |
| 103 | : <> |
| 104 | <strong>{value}</strong> {unit} old |
| 105 | </>; |
| 106 | |
| 107 | const sidebarForksLinkIcon = await elementReady('.BorderGrid .octicon-repo-forked'); |
| 108 | closestElement('.mt-2', sidebarForksLinkIcon).after( |
| 109 | <h3 className="sr-only">Repository age</h3>, |
| 110 | <div className="mt-2 tmp-mt-2"> |
| 111 | <a href={lastCommitsPageUrl} className="Link--muted" title={`First commit dated ${dateFormatter.format(birthday)}`}> |
| 112 | <RepoIcon className="mr-2 tmp-mr-2" /> {age} |
| 113 | </a> |
| 114 | </div>, |
| 115 | ); |
| 116 | } |
| 117 | |
| 118 | void features.add(import.meta.url, { |
| 119 | include: [ |
nothing calls this directly
no test coverage detected