3.1.0 - Added Gitea integration for Projects page
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m25s
All checks were successful
Docker Deploy / build-and-push (push) Successful in 4m25s
This commit is contained in:
@@ -2,6 +2,42 @@
|
||||
import Layout from "../layouts/Layout.astro";
|
||||
import ProjectCard from "../components/ProjectCard.astro";
|
||||
import { config } from "../config";
|
||||
import { fetchGiteaInfoFromUrl } from "../utils/gitea";
|
||||
import type { Project } from "../types";
|
||||
|
||||
function isGiteaDomain(url: string): boolean {
|
||||
if (!config.siteConfig.giteaDomains) return true;
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
return config.siteConfig.giteaDomains.some(
|
||||
(domain) => urlObj.origin === new URL(domain).origin,
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const projectsWithGiteaInfo = await Promise.all(
|
||||
config.projects.map(async (project) => {
|
||||
if (project.link && !project.giteaInfo && isGiteaDomain(project.link)) {
|
||||
const giteaInfo = await fetchGiteaInfoFromUrl(project.link);
|
||||
if (giteaInfo) {
|
||||
return { ...project, giteaInfo } as Project;
|
||||
}
|
||||
}
|
||||
return project;
|
||||
}),
|
||||
);
|
||||
|
||||
const sortedProjects = projectsWithGiteaInfo.sort((a, b) => {
|
||||
const aTime = a.giteaInfo?.updatedAt
|
||||
? new Date(a.giteaInfo.updatedAt).getTime()
|
||||
: 0;
|
||||
const bTime = b.giteaInfo?.updatedAt
|
||||
? new Date(b.giteaInfo.updatedAt).getTime()
|
||||
: 0;
|
||||
return bTime - aTime;
|
||||
});
|
||||
---
|
||||
|
||||
<Layout>
|
||||
@@ -14,15 +50,11 @@ import { config } from "../config";
|
||||
<div
|
||||
class="flex flex-row flex-wrap justify-center gap-4 sm:gap-6 max-w-6xl mx-auto"
|
||||
>
|
||||
{
|
||||
config.projects.map((project) => (
|
||||
<ProjectCard project={project} />
|
||||
))
|
||||
}
|
||||
{sortedProjects.map((project) => <ProjectCard project={project} />)}
|
||||
</div>
|
||||
|
||||
{
|
||||
config.projects.length === 0 && (
|
||||
sortedProjects.length === 0 && (
|
||||
<p class="text-center text-gray-500 mt-12">
|
||||
No projects available yet. Check back soon!
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user