feat: some cleanups
This commit is contained in:
parent
60aea94006
commit
7b6b0b4176
6 changed files with 29 additions and 59 deletions
|
|
@ -28,7 +28,8 @@ const {
|
|||
</main>
|
||||
<Footer />
|
||||
<script is:inline>
|
||||
window.getTopicColor = function(topicName) {
|
||||
window.getTopicColor = function (topicName) {
|
||||
console.log(topicName);
|
||||
switch (topicName) {
|
||||
case "software":
|
||||
return "#0073e6";
|
||||
|
|
|
|||
|
|
@ -11,19 +11,17 @@ interface Props {
|
|||
useD3?: boolean;
|
||||
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 filePath = post?.id || "";
|
||||
const category = filePath.split("/")[0];
|
||||
|
||||
const topicColor = getTopicColor(category);
|
||||
const topicColor = getTopicColor(post.collection);
|
||||
---
|
||||
|
||||
<BaseLayout title={title} description={description} useKatex={useKatex}, useD3={useD3}>
|
||||
<slot name="head" slot="head">
|
||||
<BaseLayout title={title} description={description}>
|
||||
<Fragment slot="head">
|
||||
<link rel="stylesheet" href="/styles/posts.css" />
|
||||
<link rel="stylesheet" href="/styles/graph.css" />
|
||||
{
|
||||
|
|
@ -36,12 +34,8 @@ const topicColor = getTopicColor(category);
|
|||
/>
|
||||
)
|
||||
}
|
||||
{
|
||||
useD3 && (
|
||||
<script src="https://d3js.org/d3.v7.min.js"></script>
|
||||
)
|
||||
}
|
||||
</slot>
|
||||
<slot name="head" />
|
||||
</Fragment>
|
||||
|
||||
<div class="post-container" style={`--topic-color: ${topicColor};`}>
|
||||
<header class="post-header">
|
||||
|
|
@ -54,11 +48,10 @@ const topicColor = getTopicColor(category);
|
|||
</article>
|
||||
</div>
|
||||
|
||||
<slot name="scripts" slot="scripts">
|
||||
<script src="/scripts/index.js" is:inline></script>
|
||||
<Fragment slot="scripts">
|
||||
<script type="module" src="/scripts/index.js"></script>
|
||||
<script src="/scripts/centerKatex.js" is:inline></script>
|
||||
{frontmatter.scripts?.map(script => (
|
||||
<script src={script} type="module"></script>
|
||||
))}
|
||||
</slot>
|
||||
{frontmatter.scripts?.map((src) => <script type="module" src={src} />)}
|
||||
<slot name="scripts" />
|
||||
</Fragment>
|
||||
</BaseLayout>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
|
|
@ -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>> {cloneCommand}</code>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
<Content />
|
||||
</GitLayout>
|
||||
</PostLayout>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
export function getTopicColor(topicName) {
|
||||
console.log(topicName);
|
||||
switch (topicName) {
|
||||
case "software":
|
||||
return "#0073e6";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue