Add git feed to main page #10

Merged
tyler merged 2 commits from add-git-feed into master 2022-12-02 19:23:36 +00:00
4 changed files with 108 additions and 19 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.4);
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,0.85);
}
.single-column {
grid-template-columns: 1fr !important;
}
@ -43,7 +64,6 @@
background: rgba(11,11,12, 0.3);
border-radius: 15px;
padding: 10px;
}
.index-item {
@ -51,7 +71,6 @@
align-content: center;
justify-content: center;
justify-items: center;
align-items: center;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr;
}
@ -62,6 +81,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){