All checks were successful
Docker Deploy / build-and-push (push) Successful in 5m7s
64 lines
1.7 KiB
Plaintext
64 lines
1.7 KiB
Plaintext
---
|
|
import ProjectCard from "./ProjectCard.astro";
|
|
import { config } from "../config";
|
|
import { fetchGiteaInfoFromUrl } from "../utils/gitea";
|
|
import type { Project } from "../types";
|
|
|
|
Astro.response.headers.set(
|
|
"Cache-Control",
|
|
"public, max-age=300, s-maxage=300, stale-while-revalidate=60",
|
|
);
|
|
|
|
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.gitLink &&
|
|
!project.giteaInfo &&
|
|
isGiteaDomain(project.gitLink)
|
|
) {
|
|
const giteaInfo = await fetchGiteaInfoFromUrl(project.gitLink);
|
|
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;
|
|
});
|
|
---
|
|
|
|
<div
|
|
class="flex flex-row flex-wrap justify-center gap-4 sm:gap-6 max-w-6xl mx-auto"
|
|
>
|
|
{sortedProjects.map((project) => <ProjectCard project={project} />)}
|
|
</div>
|
|
|
|
{
|
|
sortedProjects.length === 0 && (
|
|
<p class="text-center text-gray-500 mt-12">
|
|
No projects available yet. Check back soon!
|
|
</p>
|
|
)
|
|
}
|