feat: some cleanups

This commit is contained in:
Barrett Ruth 2025-10-08 19:25:10 -04:00
parent 60aea94006
commit 7b6b0b4176
6 changed files with 29 additions and 59 deletions

View file

@ -24,7 +24,7 @@ const pageTitle = `${category}/${post.data.title ?? post.slug}`;
const { Content } = await post.render();
---
<PostLayout frontmatter={post.data}>
<PostLayout frontmatter={post.data} post={post}>
<Fragment slot="head">
<title>{pageTitle}</title>
<script type="module" src="/scripts/index.js"></script>

View file

@ -2,12 +2,6 @@
import BaseLayout from "../../layouts/BaseLayout.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
const posts = await getCollection("posts");
const categories = Array.from(new Set(posts.map((p) => p.id.split("/")[0])));
return categories.map((category) => ({ params: { category } }));
}
const category = Astro.params.category;
const title = "Barrett Ruth";

View file

@ -1,43 +1,24 @@
---
import { getEntry } from "astro:content";
import GitLayout from "../../layouts/GitLayout.astro";
import { getCollection } from "astro:content";
import PostLayout from "../../layouts/PostLayout.astro";
export async function getStaticPaths() {
const res = await fetch("https://git.barrettruth.com/api/repositories");
const json = res.ok ? await res.json() : { repositories: [] };
const repos = (json.repositories || []).map((r) => r.replace(/\.git$/, ""));
return repos.map((slug) => ({ params: { slug } }));
const repos = await getCollection("git");
return repos.map((repo) => ({
params: { slug: repo.slug },
props: { repo },
}));
}
const { slug } = Astro.params;
const entry = await getEntry("git", slug);
if (!entry) return Astro.redirect("/404");
const { Content } = await entry.render();
const repoName = `${slug}.git`;
let cloneCommand = "";
try {
const res = await fetch("https://git.barrettruth.com/api/repositories");
const json = res.ok ? await res.json() : { repositories: [] };
const exists = json.repositories?.includes(repoName);
if (exists)
cloneCommand = `git clone https://git.barrettruth.com/${repoName}`;
} catch {}
const pageTitle = `git/${entry.data.title ?? slug}`;
const { repo } = Astro.props;
const { Content } = await repo.render();
const pageTitle = `git/${repo.data.title ?? repo.slug}`;
---
<GitLayout frontmatter={entry.data} post={entry}>
<PostLayout frontmatter={repo.data} post={repo}>
<Fragment slot="head">
<title>{pageTitle}</title>
<script type="module" src="/scripts/index.js"></script>
</Fragment>
{
cloneCommand && (
<div class="clone-line">
<code>&gt; {cloneCommand}</code>
</div>
)
}
<Content />
</GitLayout>
</PostLayout>