From 2b5302587645dcab7c012c550989b7a8e9bee72b Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Oct 2024 23:04:27 +0000 Subject: Update blog post metadata and styles --- src/content/blog/example-content.md | 1 + src/content/config.ts | 1 + src/pages/[...page].astro | 5 ++++- src/pages/blog/[...slug].astro | 32 ++++++++++++++++---------------- src/pages/feed.xml.js | 4 +++- src/scss/_framework.scss | 3 +-- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/content/blog/example-content.md b/src/content/blog/example-content.md index 68b09e5..64b214e 100644 --- a/src/content/blog/example-content.md +++ b/src/content/blog/example-content.md @@ -3,6 +3,7 @@ title: "Example Content" author: "Example User" pubDate: "2018-01-01" description: "Howdy! This is an example blog post that shows several types of HTML content supported in this theme." +draft: true --- Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. _Aenean eu leo quam._ Pellentesque ornare sem lacinia quam venenatis vestibulum. Sed posuere consectetur est at lobortis. Cras mattis consectetur purus sit amet fermentum. diff --git a/src/content/config.ts b/src/content/config.ts index 00f60c9..245f20e 100644 --- a/src/content/config.ts +++ b/src/content/config.ts @@ -5,6 +5,7 @@ const blog = defineCollection({ schema: z.object({ author: z.string(), description: z.string(), + draft: z.optional(z.boolean()), pubDate: z.coerce.date(), title: z.string(), }), diff --git a/src/pages/[...page].astro b/src/pages/[...page].astro index cd64d66..6d513b2 100644 --- a/src/pages/[...page].astro +++ b/src/pages/[...page].astro @@ -8,7 +8,10 @@ import PostSummary from "../components/PostSummary.astro"; type Props = InferGetStaticPropsType; export const getStaticPaths = (async ({ paginate }) => { - const posts = await getCollection("blog"); + const posts = await getCollection("blog", ({ data }) => { + return data.draft !== true; + }); + posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime()); return paginate(posts, { diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index bcd5eed..63d2c98 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -2,11 +2,14 @@ import { type CollectionEntry, getCollection } from "astro:content"; import Comments from "../../components/Comments.astro"; import Layout from "../../layouts/BaseLayout.astro"; +import dayjs from "dayjs"; type Props = CollectionEntry<"blog">; export async function getStaticPaths() { - const posts = await getCollection("blog"); + const posts = await getCollection("blog", ({ data }) => { + return data.draft !== true; + }); return posts.map((post) => ({ params: { slug: post.slug }, @@ -15,33 +18,30 @@ export async function getStaticPaths() { } const post = Astro.props; -const { Content, remarkPluginFrontmatter } = await post.render(); +const { Content } = await post.render(); +const formattedDate = dayjs(post.data.pubDate.toString()).format("MMMM DD, YYYY"); --- - -
-
+

{post.data.title}

+
+ +
+ +
+ +

Posted - -  by {post.data.author} ‐ - {remarkPluginFrontmatter.minutesRead} + + by {post.data.author}

-
- -
-
diff --git a/src/pages/feed.xml.js b/src/pages/feed.xml.js index c837202..d71a020 100644 --- a/src/pages/feed.xml.js +++ b/src/pages/feed.xml.js @@ -2,7 +2,9 @@ import { getCollection } from "astro:content"; import rss from "@astrojs/rss"; export async function GET(context) { - const posts = await getCollection("blog"); + const posts = await getCollection("blog", ({ data }) => { + return data.draft !== true; + }); return rss({ customData: `ru-ru`, diff --git a/src/scss/_framework.scss b/src/scss/_framework.scss index 549f9df..c95a71c 100644 --- a/src/scss/_framework.scss +++ b/src/scss/_framework.scss @@ -55,8 +55,7 @@ h5, h6 { font-weight: 700; line-height: 1.1; - margin-bottom: 1.5rem; - margin-top: 3rem; + margin: 3rem 0; overflow-wrap: break-word; word-break: break-word; word-wrap: break-word; -- cgit v1.2.3