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 18 deletions
Showing only changes of commit fc58241813 - Show all commits

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; 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 { .single-column {
grid-template-columns: 1fr !important; grid-template-columns: 1fr !important;
} }
@ -51,7 +72,6 @@
align-content: center; align-content: center;
justify-content: center; justify-content: center;
justify-items: center; justify-items: center;
align-items: center;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr; grid-template-rows: 1fr;
} }
@ -62,6 +82,12 @@
margin: 5px; margin: 5px;
} }
.index-column {
display: grid;
grid-template-rows: 10em 1fr;
}
@media only screen and (max-width: 768px){ @media only screen and (max-width: 768px){
.index-item { .index-item {
grid-template-columns: 1fr; grid-template-columns: 1fr;

View File

@ -2,6 +2,8 @@
<html lang="en"> <html lang="en">
<head> <head>
<?php include 'common/include.php' ?> <?php include 'common/include.php' ?>
<?php include 'common/git.php' ?>
<title>Tyler Perkins - Home</title> <title>Tyler Perkins - Home</title>
<link rel="stylesheet" href="index.css"> <link rel="stylesheet" href="index.css">
</head> </head>
@ -20,19 +22,38 @@
$home_addr = gethostbyname("gluttony.clortox.com"); $home_addr = gethostbyname("gluttony.clortox.com");
if($remote_addr == $home_addr) if($remote_addr == $home_addr)
echo "<p>Hello from within the home network!</p>" echo "<p>Hello from within the home network!</p>"
?> ?>
</div> </div>
<!--</a>--> <!--</a>-->
</div> </div>
<div class="centered"> <div class="centered">
<div class="index-item soft-background articles-box"> <div class="index-item soft-background articles-box">
<div class="index-column">
<h3>Projects</h3>
<div> <div>
<h3>Articles</h3> <?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> </div>
<p>To be implemented...</p> <div class="index-column">
<h3>Articles</h3>
<p>To be implemented</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,17 +1,8 @@
<?php <?php
$curl = curl_init(); include 'common/git.php';
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); $parsed = json_decode(getResumeReleases(), true);
if(!$result){
header('HTTP/1.1 500 Internal Server Error');
die();
}
curl_close($curl);
$parsed = json_decode($result, true);
$url = $parsed[0]["assets"][0]["browser_download_url"]; $url = $parsed[0]["assets"][0]["browser_download_url"];
if(!$url){ if(!$url){