diff --git a/astro.config.mjs b/astro.config.mjs index 7c52a4c..b7dceec 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1 +1,5 @@ import { defineConfig } from "astro/config"; + +export default defineConfig({ + output: "server", +}); diff --git a/src/components/BlogHeader.astro b/src/components/BlogHeader.astro index 7d97124..69a6f86 100644 --- a/src/components/BlogHeader.astro +++ b/src/components/BlogHeader.astro @@ -1,5 +1,4 @@ --- -import { format, add } from "date-fns"; import FormattedDate from "@components/FormattedDate.astro"; interface Props { diff --git a/src/components/FormattedDate.astro b/src/components/FormattedDate.astro index 4634c49..d83dd64 100644 --- a/src/components/FormattedDate.astro +++ b/src/components/FormattedDate.astro @@ -2,7 +2,7 @@ import { format, add } from "date-fns"; interface Props { - date: String; + date: Date; } const { date } = Astro.props; diff --git a/src/components/Header.astro b/src/components/Header.astro index 1128ec5..38e88d9 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -1,6 +1,5 @@ --- const { pathname } = Astro.url; -console.log(pathname); const navLinks = [ { label: "Blog", icon: "website-with-texticonImage24px", path: "/" }, diff --git a/src/layouts/About.astro b/src/layouts/About.astro index e98ce80..deb6c38 100644 --- a/src/layouts/About.astro +++ b/src/layouts/About.astro @@ -1,4 +1,5 @@ --- +export const prerender = true; import Layout from "@layouts/Layout.astro"; const styles = { diff --git a/src/pages/archive.astro b/src/pages/archive.astro index 333f6cb..7676b8e 100644 --- a/src/pages/archive.astro +++ b/src/pages/archive.astro @@ -1,13 +1,40 @@ --- import { getCollection } from "astro:content"; +const sortParam = Astro.url.search.split("=")[1]; import Layout from "@layouts/Layout.astro"; import FormattedDate from "@components/FormattedDate.astro"; 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; +} --- +
+
+ +
+
{ posts.map(({ slug, data }) => (
@@ -17,3 +44,21 @@ const posts = await getCollection("blog"); )) } + + + + diff --git a/src/pages/index.astro b/src/pages/index.astro index 0470b26..f864514 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,4 +1,5 @@ --- +export const prerender = true; import { getCollection } from "astro:content"; import Layout from "@layouts/Layout.astro"; diff --git a/src/pages/posts/[slug].astro b/src/pages/posts/[slug].astro index 1ff4411..2eabf69 100644 --- a/src/pages/posts/[slug].astro +++ b/src/pages/posts/[slug].astro @@ -1,5 +1,6 @@ --- -import { getCollection, getEntryBySlug } from "astro:content"; +export const prerender = true; +import { getCollection } from "astro:content"; import Layout from "@layouts/Layout.astro"; import BlogHeader from "@components/BlogHeader.astro"; @@ -28,6 +29,8 @@ const { Content } = await post.render();