From cb4a1f179bce25d9c9b88b0152072529ce46b717 Mon Sep 17 00:00:00 2001 From: Frankie B Date: Wed, 12 Jul 2023 01:16:52 +0100 Subject: Add recent site updates (from git) --- resources/views/components/git.blade.php | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 resources/views/components/git.blade.php (limited to 'resources/views/components/git.blade.php') diff --git a/resources/views/components/git.blade.php b/resources/views/components/git.blade.php new file mode 100644 index 0000000..f87a00f --- /dev/null +++ b/resources/views/components/git.blade.php @@ -0,0 +1,48 @@ +@php +$api_root = app('config')->get('app')['api_root']; + +$commits = json_decode(file_get_contents($api_root.'/gitdata')); +$count = 0; + +function formatRelativeTime(DateTime $dateTime) { + $currentTimestamp = time(); + $dateTimeTimestamp = $dateTime->getTimestamp(); + $difference = $currentTimestamp - $dateTimeTimestamp; + + if ($difference < 60) { + return "just now"; + } elseif ($difference < 3600) { + $minutes = floor($difference / 60); + $suffix = ($minutes > 1) ? "s" : ""; + return $minutes . " minute" . $suffix . " ago"; + } elseif ($difference < 86400) { + $hours = floor($difference / 3600); + $suffix = ($hours > 1) ? "s" : ""; + return $hours . " hour" . $suffix . " ago"; + } elseif ($difference < 604800) { + $days = floor($difference / 86400); + $suffix = ($days > 1) ? "s" : ""; + return $days . " day" . $suffix . " ago"; + } else { + return $dateTime->format('Y-m-d H:i:s'); // Fallback to a specific format if desired + } +} +@endphp +

Recent Site Updates

+ +@foreach ($commits as $commit) + + @if ($count >= 5) +
+ @break + @endif + @php + $date = DateTime::createFromFormat("Y-m-d\TH:i:s\Z", $commit->author->date) + @endphp + + • + {{ formatRelativeTime($date) }} + {{ $commit->message }} + +@php $count++ @endphp +@endforeach -- cgit v1.2.3-54-g00ecf