Many many changes

This commit is contained in:
Henry Hiles 2023-06-19 10:57:04 -04:00
commit c0a63a4a97
3 changed files with 405 additions and 20 deletions

View file

@ -0,0 +1,20 @@
---
import Layout from "../../layouts/Layout.astro"
import { getCollection } from "astro:content"
import BlogPost from "../../components/BlogPost.astro"
export const getStaticPaths = async () => {
const blogEntries = await getCollection("blog")
return blogEntries.map((post) => ({
params: { slug: post.slug },
props: { post }
}))
}
const { post } = Astro.props
const { data } = post
---
<Layout page={data.title} description={data.overview}>
<BlogPost post={post} />
</Layout>

View file

@ -0,0 +1,62 @@
---
import Layout from "../../layouts/Layout.astro"
import BlogPost from "../../components/BlogPost.astro"
import styles from "../../styles/Blog.module.css"
import { getCollection } from "astro:content"
import Divider from "../../components/Divider.astro"
const posts = await getCollection("blog")
---
<Layout page="Blog" description="The blog of Henry Hiles">
<div class={styles.container}>
<aside class={styles.sidebar}>
<input type="text" placeholder="Search..." id="search" />
</aside>
<div class={styles.right}>
<article class={styles.description}>
<h1>Welcome to the blog!</h1>
<Divider />
<p>
Hello, and welcome to my blog. I post about Discord Bot
Development, Web Development, Linux, and other Tech-related
subjects. You can filter and search in the sidebar.
</p>
</article>
{
posts.map((post) => (
<a
class={styles.link}
href={`/blog/${post.slug}`}
data-title={post.data.title}
data-tags=""
>
<BlogPost post={post} />
</a>
))
}
</div>
</div>
</Layout>
<script>
const searchBar = document.querySelector("#search") as HTMLInputElement
const posts = document.querySelectorAll(
"[data-title]"
) as NodeListOf<HTMLElement>
const search = () =>
posts.forEach((post) =>
post.setAttribute(
"aria-hidden",
post.dataset.title
?.toLowerCase()
?.includes(searchBar.value.toLowerCase())
? "false"
: "true"
)
)
searchBar?.addEventListener("input", search)
addEventListener("load", search)
</script>

24
src/pages/blog/rss.xml.js Normal file
View file

@ -0,0 +1,24 @@
import rss from "@astrojs/rss"
import { getCollection } from "astro:content"
import { marked } from "marked"
export const get = async (context) => {
const blog = await getCollection("blog")
return rss({
title: "Henry Hiles' Blog",
description:
"A blog about Linux, Web Development, Discord Bots, and more.",
site: context.site,
items: blog.map((post) => ({
link: `/blog/${post.slug}/`,
content: marked.parse(post.body, {
mangle: false,
headerIds: false
}),
...post.data
})),
customData: "<language>en-us</language>",
trailingSlash: false,
stylesheet: "/rss.xsl"
})
}