Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Resolves inheritance issue

AuthorDave Jarvis <email>
Date2026-02-20 22:01:43 GMT-0800
Commit0c498871a87763cb6c929a6c27af0c91d6871bd3
Parent4360914
pages/HomePage.php
<?php
-require_once __DIR__ . '/../File.php';
+require_once __DIR__ . '/BasePage.php';
require_once __DIR__ . '/../UrlBuilder.php';
-require_once __DIR__ . '/Page.php';
-abstract class BasePage implements Page {
+class HomePage extends BasePage {
private $repositories;
- private $title;
+ private $git;
- public function __construct( array $repositories, string $title = '' ) {
+ public function __construct( array $repositories, Git $git ) {
+ parent::__construct( $repositories );
$this->repositories = $repositories;
- $this->title = $title;
+ $this->git = $git;
}
- protected function renderLayout(
- $contentCallback,
- array $currentRepo = []
- ) {
- $siteTitle = Config::SITE_TITLE;
- $pageTitle = $this->title
- ? ' - ' . htmlspecialchars( $this->title )
- : '';
+ public function render() {
+ $this->renderLayout( function() {
+ echo '<h2>Repositories</h2>';
- ?>
-<!DOCTYPE html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title><?php echo $siteTitle . $pageTitle; ?></title>
- <link rel="stylesheet"
- href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css">
- <link rel="stylesheet" href="/styles/repo.css">
-</head>
-<body>
-<div class="container">
- <header>
- <h1><?php echo Config::SITE_TITLE; ?></h1>
+ if( empty( $this->repositories ) ) {
+ echo '<div class="empty-state">No repositories found.</div>';
+ } else {
+ echo '<div class="repo-grid">';
- <?php if( $currentRepo ) { ?>
- <input type="checkbox" id="clone-toggle" class="clone-checkbox">
- <?php } ?>
+ foreach( $this->repositories as $repo ) {
+ $this->renderRepoCard( $repo );
+ }
- <nav class="nav">
- <?php if( $currentRepo ) { ?>
- <a href="<?php echo (new UrlBuilder())->build(); ?>">Home</a>
- <?php $safeName = $currentRepo['safe_name']; ?>
- <a href="<?php echo (new UrlBuilder())
- ->withRepo( $safeName )
- ->withAction( 'tree' )
- ->build(); ?>">Files</a>
- <a href="<?php echo (new UrlBuilder())
- ->withRepo( $safeName )
- ->withAction( 'commits' )
- ->build(); ?>">Commits</a>
- <a href="<?php echo (new UrlBuilder())
- ->withRepo( $safeName )
- ->withAction( 'tags' )
- ->build(); ?>">Tags</a>
+ echo '</div>';
+ }
+ } );
+ }
- <label for="clone-toggle" class="clone-link">Clone</label>
- <?php } ?>
+ private function renderRepoCard( $repo ) {
+ $this->git->setRepository( $repo['path'] );
- <?php if( $currentRepo ) { ?>
- <div class="repo-selector">
- <label>Repository:</label>
- <select onchange="<?php echo (new UrlBuilder())
- ->withSwitcher( 'this.value' )
- ->build(); ?>">
- <?php foreach( $this->repositories as $r ) { ?>
- <option
- value="<?php echo htmlspecialchars( $r['safe_name'] ); ?>"
- <?php
- echo $r['safe_name'] === $currentRepo['safe_name']
- ? 'selected'
- : '';
- ?>
- <?php echo htmlspecialchars( $r['name'] ); ?>
- </option>
- <?php } ?>
- </select>
- </div>
- <?php } ?>
- </nav>
+ $main = $this->git->getMainBranch();
+ $stats = [
+ 'branches' => 0,
+ 'tags' => 0
+ ];
- <?php if( $currentRepo ) { ?>
- <div class="clone-region">
- <div class="clone-wrapper">
- <?php
- $cloneCmd = 'git clone https://repo.autonoma.ca/repo/' .
- $currentRepo['safe_name'] . '.git';
- ?>
- <span class="clone-sizer"><?php echo htmlspecialchars( $cloneCmd ); ?></span>
- <input type="text" class="clone-input" readonly
- value="<?php echo htmlspecialchars( $cloneCmd ); ?>">
- </div>
- </div>
- <?php } ?>
- </header>
+ $this->git->eachBranch( function() use ( &$stats ) {
+ $stats['branches']++;
+ } );
- <?php call_user_func( $contentCallback ); ?>
+ $this->git->eachTag( function() use ( &$stats ) {
+ $stats['tags']++;
+ } );
-</div>
-</body>
-</html>
- <?php
- }
+ $url = (new UrlBuilder())->withRepo( $repo['safe_name'] )->build();
+ echo '<a href="' . $url . '" class="repo-card">';
+ echo '<h3>' . htmlspecialchars( $repo['name'] ) . '</h3>';
+ echo '<p class="repo-meta">';
- protected function renderBreadcrumbs( array $repo, array $trail = [] ) {
- $repoUrl = (new UrlBuilder())->withRepo( $repo['safe_name'] )->build();
+ $branchLabel = $stats['branches'] === 1 ? 'branch' : 'branches';
+ $tagLabel = $stats['tags'] === 1 ? 'tag' : 'tags';
- $parts = array_merge(
- [
- '<a href="' . $repoUrl . '" class="repo-breadcrumb">' .
- htmlspecialchars( $repo['name'] ) . '</a>'
- ],
- $trail
- );
+ echo $stats['branches'] . ' ' . $branchLabel . ', ' .
+ $stats['tags'] . ' ' . $tagLabel;
- echo '<div class="breadcrumb">' . implode( ' / ', $parts ) . '</div>';
+ if( $main ) {
+ echo ', ';
+
+ $this->git->history( 'HEAD', 1, function( $c ) use ( $repo ) {
+ $renderer = new HtmlFileRenderer( $repo['safe_name'] );
+ $renderer->renderTime( $c->date );
+ } );
+ }
+
+ echo '</p>';
+
+ $descPath = $repo['path'] . '/description';
+
+ if( file_exists( $descPath ) ) {
+ $description = trim( file_get_contents( $descPath ) );
+
+ if( $description !== '' ) {
+ echo '<p style="margin-top: 1.5em;">' .
+ htmlspecialchars( $description ) . '</p>';
+ }
+ }
+
+ echo '</a>';
}
}
Delta64 lines added, 101 lines removed, 37-line decrease