IDK why I didn't do this... using server islands :')
This commit is contained in:
@@ -1,43 +1,9 @@
|
||||
---
|
||||
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";
|
||||
import ProjectsIsland from "../components/ProjectsIsland.astro";
|
||||
import ProjectsLoader from "../components/ProjectsLoader.astro";
|
||||
|
||||
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;
|
||||
});
|
||||
export const prerender = false;
|
||||
---
|
||||
|
||||
<Layout>
|
||||
@@ -47,18 +13,9 @@ const sortedProjects = projectsWithGiteaInfo.sort((a, b) => {
|
||||
>
|
||||
Projects
|
||||
</h1>
|
||||
<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>
|
||||
)
|
||||
}
|
||||
<ProjectsIsland server:defer>
|
||||
<ProjectsLoader slot="fallback" />
|
||||
</ProjectsIsland>
|
||||
</div>
|
||||
</Layout>
|
||||
|
||||
Reference in New Issue
Block a user