Skip to content

Commit

Permalink
add blog
Browse files Browse the repository at this point in the history
  • Loading branch information
mudkipdev committed May 9, 2024
1 parent 135ed69 commit aa7d86b
Show file tree
Hide file tree
Showing 19 changed files with 356 additions and 51 deletions.
12 changes: 9 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { defineConfig } from 'astro/config'
import { defineConfig } from "astro/config";

export default defineConfig({
site: 'https://mudkip.dev',
compressHTML: true,
site: "https://mudkip.dev",
prefetch: {
defaultStrategy: "viewport",
prefetchAll: true
},
devToolbar: {
enabled: false
},
})
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"astro": "astro"
},
"dependencies": {
"astro": "^4.6.3",
"@astrojs/check": "^0.5.10",
"@astrojs/rss": "^4.0.5",
"astro": "^4.6.3",
"typescript": "^5.4.5"
}
}
}
75 changes: 75 additions & 0 deletions public/style.xsl

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions src/components/Card.astro
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
---
import Date from "@components/Date.astro";
interface Props {
title: string;
description: string;
url?: string;
date?: Date;
}
const { title, description, url } = Astro.props
const { title, description, url, date } = Astro.props
---
<div class="card">
{url == null
? <h2>{title}</h2>
: <a href={url} target="_blank">{title}</a>}
<p>{description}</p>
<h2>{
url == null
? title
: <a data-astro-prefetch="false" href={url} target="_blank">{title}</a>
}</h2>

<div>
<p>{description}</p>
{date != undefined && <Date date={date} />}
</div>
</div>

<style>
Expand All @@ -27,11 +36,13 @@ const { title, description, url } = Astro.props

.card * {
margin: 0;
font-size: 0.85em;
}

.card a {
color: var(--text);
font-size: 1.25em;
}

.card p {
font-size: 0.85em;
}
</style>
14 changes: 14 additions & 0 deletions src/components/Cards.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
---
<div class="cards">
<slot />
</div>

<style>
.cards {
margin: 1em auto;
gap: 0.75em;
display: flex;
flex-direction: column;
}
</style>
23 changes: 23 additions & 0 deletions src/components/Date.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
interface Props {
date: Date;
}
const { date } = Astro.props;
---
<time datetime={date.toISOString()}>
{
date.toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "numeric"
})
}
</time>

<style>
time {
color: var(--surface-2);
font-size: 0.85em;
}
</style>
8 changes: 8 additions & 0 deletions src/content/blog/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
date: 2024-05-09
title: Test
---
This is a demo of my blog. I can write for as long as I want, but eventually this description will be cut off at the 50 character limit.

# boop
helo
12 changes: 12 additions & 0 deletions src/content/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { z, defineCollection } from "astro:content";

export const collections = {
"blog": defineCollection({
type: "content",
schema: z.object({
title: z.string(),
date: z.date(),
tags: z.array(z.string()).default([])
})
})
};
10 changes: 8 additions & 2 deletions src/layouts/Page.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import "../style.css"
const { title } = Astro.props
import "@styles/global.css";
const { title } = Astro.props;
---
<html lang="en">
<head>
Expand All @@ -9,6 +9,12 @@ const { title } = Astro.props
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link
rel="alternate"
type="application/rss+xml"
title="mudkip's blog"
href="/rss.xml"
/>
</head>
<body>
<h1>{title}</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/404.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import Page from '../layouts/Page.astro'
import Page from "@layouts/Page.astro";
---
<Page title="404">
<p>page not found</p>
Expand Down
25 changes: 23 additions & 2 deletions src/pages/blog.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
---
import Page from '../layouts/Page.astro'
import Page from "@layouts/Page.astro";
import Card from "@components/Card.astro";
import Cards from "@components/Cards.astro";
import { getCollection } from "astro:content";
const posts = await getCollection("blog");
---
<Page title="blog">
<p>coming soon...</p>
{
posts.length != 0
? <p>there are currently no published posts</p>
: (
<Cards>
{posts.map(post => (
<Card
title={post.data.title}
description={post.body.substring(0, 100) + "..."}
url={"/blog/" + post.slug}
date={post.data.date}
/>
))}
</Cards>
)
}

</Page>
27 changes: 27 additions & 0 deletions src/pages/blog/[...slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
import type { InferGetStaticPropsType, GetStaticPaths } from "astro";
import { getCollection } from 'astro:content';
import Page from "@layouts/Page.astro";
import Date from '@components/Date.astro';
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
export const getStaticPaths = (async () => {
const posts = await getCollection("blog");
return posts.map(post => {
return {
params: { slug: post.slug },
props: { post, data: post.data },
};
});
}) satisfies GetStaticPaths;
const { post, data } = Astro.props;
const { Content } = await post.render();
---
<Page title="blog">
<h1>{data.title}</h1>
<Date date={data.date} />
<Content />
</Page>
2 changes: 1 addition & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
import Page from '../layouts/Page.astro'
import Page from "@layouts/Page.astro";
---
<Page title="mudkip">
<p>i use NixOS btw</p>
Expand Down
22 changes: 7 additions & 15 deletions src/pages/projects.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
import Page from '../layouts/Page.astro'
import Card from '../components/Card.astro'
import Page from "@layouts/Page.astro";
import Card from "@components/Card.astro";
import Cards from "@components/Cards.astro";
---
<Page title="projects">
<div class="cards">
<Cards>
<Card
title="website"
description="My personal website written with Astro and TypeScript."
Expand All @@ -13,16 +14,7 @@ import Card from '../components/Card.astro'
<Card
title="scnewsbot"
description="A bot for the r/starcitizen Discord server."
url="https://github.com/mudkipdev/scnewsbot"
url = "https://github.com/mudkipdev/scnewsbot"
/>
</div>
</Page>

<style>
.cards {
margin: 1em auto;
gap: 0.75em;
display: flex;
flex-direction: column;
}
</style>
</Cards>
</Page>
22 changes: 22 additions & 0 deletions src/pages/rss.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import rss from "@astrojs/rss";
import type { APIContext } from "astro";
import { getCollection } from "astro:content";

export async function GET(context: APIContext) {
const posts = await getCollection("blog");

return rss({
site: context.site!,
title: "mudkip's blog",
description: "Random thoughts and ramblings I have.",
stylesheet: "/style.xsl",
items: posts.map(post => ({
link: `/blog/${post.slug}`,
title: post.data.title,
pubDate: post.data.date,
content: post.body,
})),
customData: "<language>en-us</language>",
trailingSlash: false,
})
}
Loading

0 comments on commit aa7d86b

Please sign in to comment.