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

@ -28,7 +28,8 @@ const {
</main> </main>
<Footer /> <Footer />
<script is:inline> <script is:inline>
window.getTopicColor = function(topicName) { window.getTopicColor = function (topicName) {
console.log(topicName);
switch (topicName) { switch (topicName) {
case "software": case "software":
return "#0073e6"; return "#0073e6";

View file

@ -11,19 +11,17 @@ interface Props {
useD3?: boolean; useD3?: boolean;
scripts?: string[]; scripts?: string[];
}; };
post?: { id?: string };
} }
const { frontmatter, post } = Astro.props; const { frontmatter, post } = Astro.props as Props;
const { title, description, useKatex = false, useD3 = false } = frontmatter; const { title, description, useKatex = false, useD3 = false } = frontmatter;
const filePath = post?.id || ""; const topicColor = getTopicColor(post.collection);
const category = filePath.split("/")[0];
const topicColor = getTopicColor(category);
--- ---
<BaseLayout title={title} description={description} useKatex={useKatex}, useD3={useD3}> <BaseLayout title={title} description={description}>
<slot name="head" slot="head"> <Fragment slot="head">
<link rel="stylesheet" href="/styles/posts.css" /> <link rel="stylesheet" href="/styles/posts.css" />
<link rel="stylesheet" href="/styles/graph.css" /> <link rel="stylesheet" href="/styles/graph.css" />
{ {
@ -36,12 +34,8 @@ const topicColor = getTopicColor(category);
/> />
) )
} }
{ <slot name="head" />
useD3 && ( </Fragment>
<script src="https://d3js.org/d3.v7.min.js"></script>
)
}
</slot>
<div class="post-container" style={`--topic-color: ${topicColor};`}> <div class="post-container" style={`--topic-color: ${topicColor};`}>
<header class="post-header"> <header class="post-header">
@ -54,11 +48,10 @@ const topicColor = getTopicColor(category);
</article> </article>
</div> </div>
<slot name="scripts" slot="scripts"> <Fragment slot="scripts">
<script src="/scripts/index.js" is:inline></script> <script type="module" src="/scripts/index.js"></script>
<script src="/scripts/centerKatex.js" is:inline></script> <script src="/scripts/centerKatex.js" is:inline></script>
{frontmatter.scripts?.map(script => ( {frontmatter.scripts?.map((src) => <script type="module" src={src} />)}
<script src={script} type="module"></script> <slot name="scripts" />
))} </Fragment>
</slot>
</BaseLayout> </BaseLayout>

View file

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

View file

@ -2,12 +2,6 @@
import BaseLayout from "../../layouts/BaseLayout.astro"; import BaseLayout from "../../layouts/BaseLayout.astro";
import { getCollection } from "astro:content"; 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 category = Astro.params.category;
const title = "Barrett Ruth"; const title = "Barrett Ruth";

View file

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

View file

@ -1,4 +1,5 @@
export function getTopicColor(topicName) { export function getTopicColor(topicName) {
console.log(topicName);
switch (topicName) { switch (topicName) {
case "software": case "software":
return "#0073e6"; return "#0073e6";