Add git feed to main page

This commit is contained in:
Tyler Perkins 2022-12-02 14:20:15 -05:00
parent 54da426874
commit fc58241813
4 changed files with 108 additions and 18 deletions

52
src/common/git.php Normal file
View File

@ -0,0 +1,52 @@
<?php
function getResumeReleases() {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/repos/tyler/Resume/releases?per_page=1&access_token=" . getenv("GITEA_TOKEN"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if(!$result){
header('HTTP/1.1 500 Internal Server Error');
die();
}
curl_close($curl);
return $result;
}
function getRecentProjects() {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/user/repos?page=1&limit=100&access_token=" . getenv("GITEA_TOKEN"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if(!$result){
header('HTTP/1.1 500 Internal Server Error');
die();
}
curl_close($curl);
//now we need to parse out the results into a nice array containing the
//5 most recently modified projects
$parsed = json_decode($result, true);
$ret = array();
foreach($parsed as $item){
array_push($ret, $item);
}
usort($ret, "datecmp");
return $ret;
}
function datecmp($lhs, $rhs) {
return $lhs["updated_at"] < $rhs["updated_at"];
}
?>

View File

@ -31,6 +31,27 @@
text-decoration: none;
}
.git-clickable-div {
display: block;
width: calc(100% - 10px - 3px);
height: auto;
text-decoration: underline 0.15em rgba(255,255,255,0);
transition: 300ms;
border: dashed;
border-radius: 5px;
background-color: rgba(0,0,0,0.6);
margin: 5px;
}
.git-clickable-div p {
margin: 15px 5px;
}
.git-clickable-div:hover {
text-decoration: underline 0.15em rgba(255,255,255,1);
background-color: rgba(0,0,0,1);
}
.single-column {
grid-template-columns: 1fr !important;
}
@ -51,7 +72,6 @@
align-content: center;
justify-content: center;
justify-items: center;
align-items: center;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr;
}
@ -62,6 +82,12 @@
margin: 5px;
}
.index-column {
display: grid;
grid-template-rows: 10em 1fr;
}
@media only screen and (max-width: 768px){
.index-item {
grid-template-columns: 1fr;

View File

@ -2,6 +2,8 @@
<html lang="en">
<head>
<?php include 'common/include.php' ?>
<?php include 'common/git.php' ?>
<title>Tyler Perkins - Home</title>
<link rel="stylesheet" href="index.css">
</head>
@ -20,19 +22,38 @@
$home_addr = gethostbyname("gluttony.clortox.com");
if($remote_addr == $home_addr)
echo "<p>Hello from within the home network!</p>"
?>
</div>
<!--</a>-->
</div>
<div class="centered">
<div class="index-item soft-background articles-box">
<div>
<h3>Articles</h3>
<div class="index-column">
<h3>Projects</h3>
<div>
<?php
$result = getRecentProjects();
array_splice($result, 6, -1);
foreach($result as $item){
if($item["private"])
continue;
$name = $item["name"];
$url = $item["html_url"];
$lang = $item["language"];
$description = $item["description"];
//build out the html
echo '<a class="git-clickable-div" href="' . $url . '">';
echo '<p>' . $name . ' - ' . $description . '</p>';
echo '</a>';
}
?>
</div>
</div>
<div>
<p>To be implemented...</p>
<div class="index-column">
<h3>Articles</h3>
<p>To be implemented</p>
</div>
</div>
</div>

View File

@ -1,17 +1,8 @@
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://git.clortox.com/api/v1/repos/tyler/Resume/releases?per_page=1&access_token=" . getenv("GITEA_TOKEN"));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
include 'common/git.php';
$result = curl_exec($curl);
if(!$result){
header('HTTP/1.1 500 Internal Server Error');
die();
}
curl_close($curl);
$parsed = json_decode($result, true);
$parsed = json_decode(getResumeReleases(), true);
$url = $parsed[0]["assets"][0]["browser_download_url"];
if(!$url){