Prettier config
This commit is contained in:
+46
-46
@@ -1,64 +1,64 @@
|
||||
---
|
||||
import { getCollection } from "astro:content";
|
||||
const sortParam = Astro.url.search.split("=")[1];
|
||||
import { getCollection } from 'astro:content'
|
||||
const sortParam = Astro.url.search.split('=')[1]
|
||||
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import FormattedDate from "@components/FormattedDate.astro";
|
||||
import Layout from '@layouts/Layout.astro'
|
||||
import FormattedDate from '@components/FormattedDate.astro'
|
||||
|
||||
const posts = await getCollection("blog");
|
||||
const posts = await getCollection('blog')
|
||||
|
||||
switch (sortParam) {
|
||||
case "date-des":
|
||||
posts.sort(
|
||||
(a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate)
|
||||
);
|
||||
break;
|
||||
case "date-asc":
|
||||
posts.sort(
|
||||
(a, b) => Date.parse(a.data.pubDate) - Date.parse(b.data.pubDate)
|
||||
);
|
||||
break;
|
||||
case "title":
|
||||
posts.sort((a, b) => a.data.title - b.data.title);
|
||||
default:
|
||||
break;
|
||||
case 'date-des':
|
||||
posts.sort(
|
||||
(a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate)
|
||||
)
|
||||
break
|
||||
case 'date-asc':
|
||||
posts.sort(
|
||||
(a, b) => Date.parse(a.data.pubDate) - Date.parse(b.data.pubDate)
|
||||
)
|
||||
break
|
||||
case 'title':
|
||||
posts.sort((a, b) => a.data.title - b.data.title)
|
||||
default:
|
||||
break
|
||||
}
|
||||
---
|
||||
|
||||
<Layout title="Blog Archive">
|
||||
<div class="archive-options">
|
||||
<div class="select-container">
|
||||
<select name="sort by" id="sort-by">
|
||||
<option value="title">Title (Alphabetically)</option>
|
||||
<option value="date-des">Publish Date (Newest First)</option>
|
||||
<option value="date-asc">Publish Date (Oldest First)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{
|
||||
posts.map(({ slug, data }) => (
|
||||
<div>
|
||||
<a href={`/posts/${slug}`}>{data.title}</a> -{" "}
|
||||
<FormattedDate date={data.pubDate} />
|
||||
</div>
|
||||
))
|
||||
}
|
||||
<div class="archive-options">
|
||||
<div class="select-container">
|
||||
<select name="sort by" id="sort-by">
|
||||
<option value="title">Title (Alphabetically)</option>
|
||||
<option value="date-des">Publish Date (Newest First)</option>
|
||||
<option value="date-asc">Publish Date (Oldest First)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{
|
||||
posts.map(({ slug, data }) => (
|
||||
<div>
|
||||
<a href={`/posts/${slug}`}>{data.title}</a> -{' '}
|
||||
<FormattedDate date={data.pubDate} />
|
||||
</div>
|
||||
))
|
||||
}
|
||||
</Layout>
|
||||
|
||||
<script is:inline>
|
||||
const sort = location.search.split("=")[1];
|
||||
const sortEl = document.querySelector("#sort-by");
|
||||
const sort = location.search.split('=')[1]
|
||||
const sortEl = document.querySelector('#sort-by')
|
||||
|
||||
sortEl.value = sort || "title";
|
||||
sortEl.value = sort || 'title'
|
||||
|
||||
sortEl.addEventListener(
|
||||
"change",
|
||||
() => (window.location.href = `/archive?sort=${sortEl.value}`)
|
||||
);
|
||||
sortEl.addEventListener(
|
||||
'change',
|
||||
() => (window.location.href = `/archive?sort=${sortEl.value}`)
|
||||
)
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.archive-options {
|
||||
padding: 10px 0 20px;
|
||||
}
|
||||
.archive-options {
|
||||
padding: 10px 0 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
+23
-23
@@ -1,33 +1,33 @@
|
||||
---
|
||||
export const prerender = true;
|
||||
import { getCollection } from "astro:content";
|
||||
export const prerender = true
|
||||
import { getCollection } from 'astro:content'
|
||||
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import PostPreview from "@components/PostPreview.astro";
|
||||
import Layout from '@layouts/Layout.astro'
|
||||
import PostPreview from '@components/PostPreview.astro'
|
||||
|
||||
const posts = await getCollection("blog");
|
||||
const posts = await getCollection('blog')
|
||||
---
|
||||
|
||||
<Layout title="Home">
|
||||
{
|
||||
posts
|
||||
.sort((a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate))
|
||||
.slice(0, 5)
|
||||
.map((post) => <PostPreview post={post} />)
|
||||
}
|
||||
{
|
||||
posts.length < 5 ? null : (
|
||||
<div class="more-posts">
|
||||
<a class="link-button blue-btn" href="/archive">
|
||||
All Posts
|
||||
</a>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
{
|
||||
posts
|
||||
.sort((a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate))
|
||||
.slice(0, 5)
|
||||
.map((post) => <PostPreview post={post} />)
|
||||
}
|
||||
{
|
||||
posts.length < 5 ? null : (
|
||||
<div class="more-posts">
|
||||
<a class="link-button blue-btn" href="/archive">
|
||||
All Posts
|
||||
</a>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</Layout>
|
||||
|
||||
<style>
|
||||
.more-posts {
|
||||
text-align: center;
|
||||
}
|
||||
.more-posts {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,37 +1,40 @@
|
||||
---
|
||||
export const prerender = true;
|
||||
import { getCollection } from "astro:content";
|
||||
export const prerender = true
|
||||
import { getCollection } from 'astro:content'
|
||||
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import BlogHeader from "@components/BlogHeader.astro";
|
||||
import Layout from '@layouts/Layout.astro'
|
||||
import BlogHeader from '@components/BlogHeader.astro'
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection("blog");
|
||||
return posts.map((post) => ({
|
||||
params: { slug: post.slug },
|
||||
props: { post },
|
||||
}));
|
||||
const posts = await getCollection('blog')
|
||||
return posts.map((post) => ({
|
||||
params: { slug: post.slug },
|
||||
props: { post },
|
||||
}))
|
||||
}
|
||||
|
||||
const { post } = Astro.props;
|
||||
const { post } = Astro.props
|
||||
|
||||
const { data } = post;
|
||||
const { data } = post
|
||||
|
||||
const { Content } = await post.render();
|
||||
const { Content } = await post.render()
|
||||
---
|
||||
|
||||
<Layout title={data.title}>
|
||||
<BlogHeader title={data.title} date={data.pubDate} />
|
||||
<article>
|
||||
<Content />
|
||||
</article>
|
||||
<BlogHeader title={data.title} date={data.pubDate} />
|
||||
<article>
|
||||
<Content />
|
||||
</article>
|
||||
</Layout>
|
||||
|
||||
<style is:global>
|
||||
article img {
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
article img {
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
.no-shadow {
|
||||
box-shadow: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
+20
-20
@@ -1,23 +1,23 @@
|
||||
import rss from "@astrojs/rss";
|
||||
import { getCollection } from "astro:content";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import MarkdownIt from "markdown-it";
|
||||
const parser = new MarkdownIt({ html: true });
|
||||
import rss from '@astrojs/rss'
|
||||
import { getCollection } from 'astro:content'
|
||||
import sanitizeHtml from 'sanitize-html'
|
||||
import MarkdownIt from 'markdown-it'
|
||||
const parser = new MarkdownIt({ html: true })
|
||||
|
||||
export async function get(context) {
|
||||
const blog = await getCollection("blog");
|
||||
console.log(blog);
|
||||
return rss({
|
||||
title: "ghall.blog",
|
||||
description:
|
||||
"My personal blog about life, gaming, tech, and whatever else I feel like writing about.",
|
||||
site: "https://ghall.blog",
|
||||
items: blog
|
||||
.sort((a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate))
|
||||
.map((post) => ({
|
||||
link: `/posts/${post.slug}/`,
|
||||
content: sanitizeHtml(parser.render(post.body)),
|
||||
...post.data,
|
||||
})),
|
||||
});
|
||||
const blog = await getCollection('blog')
|
||||
console.log(blog)
|
||||
return rss({
|
||||
title: 'ghall.blog',
|
||||
description:
|
||||
'My personal blog about life, gaming, tech, and whatever else I feel like writing about.',
|
||||
site: 'https://ghall.blog',
|
||||
items: blog
|
||||
.sort((a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate))
|
||||
.map((post) => ({
|
||||
link: `/posts/${post.slug}/`,
|
||||
content: sanitizeHtml(parser.render(post.body)),
|
||||
...post.data,
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user