Skip to content

Commit

Permalink
improve some more
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbloxhub committed Jul 23, 2023
1 parent d0c95d4 commit e610924
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
6 changes: 5 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from "astro/config"
import svelte from "@astrojs/svelte"
import UnoCSS from "unocss/astro"
import mdx from "@astrojs/mdx"
import { remarkReadingTime } from "./remark-reading-time.mjs"

// https://astro.build/config
export default defineConfig({
Expand All @@ -15,5 +16,8 @@ export default defineConfig({
experimental: {
viewTransitions: true
},
trailingSlash: "always"
trailingSlash: "always",
markdown: {
remarkPlugins: [remarkReadingTime]
}
})
41 changes: 40 additions & 1 deletion package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"@astrojs/rss": "^2.4.3",
"@astrojs/svelte": "^3.1.0",
"astro": "^2.9.1",
"mdast-util-to-string": "^4.0.0",
"reading-time": "^1.5.0",
"svelte": "^4.1.1"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions remark-reading-time.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import getReadingTime from "reading-time"
import { toString } from "mdast-util-to-string"

export function remarkReadingTime() {
return function (tree, { data }) {
const textOnPage = toString(tree)
const readingTime = getReadingTime(textOnPage)
// readingTime.text will give us minutes read as a friendly string,
// i.e. "3 min read"
data.astro.frontmatter.minutesRead = readingTime.text
}
}
7 changes: 5 additions & 2 deletions src/components/BlogPost.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
const { title, url } = Astro.props
const { title, url, minutesRead, pubDate } = Astro.props
---

<li><a href={url}>{title}</a></li>
<li>
<a href={url}>{title}</a> <br />
approximately {minutesRead}, published {pubDate.slice(0,10)}
</li>
3 changes: 2 additions & 1 deletion src/pages/blog.astro
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
import Layout from "../layouts/Layout.astro"
import BlogPost from "../components/BlogPost.astro"
const allPosts = await Astro.glob("../pages/posts/*.mdx")
const pageTitle = "bitbloxhub's blog"
---
<Layout title={pageTitle}>
<main class="m-auto p-6 max-w-6xl text-left">
<h1>bitbloxhub's blog!</h1>
<ul class="text-base">
{allPosts.map((post) => <li ><a href={post.url}>{post.frontmatter.title}</a></li>)}
{allPosts.map((post) => <BlogPost url={post.url} title={post.frontmatter.title} minutesRead={post.frontmatter.minutesRead} pubDate={post.frontmatter.pubDate} />)}
</ul>
</main>
</Layout>
3 changes: 0 additions & 3 deletions src/pages/posts/first-post.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ title: "I have a new blog!"
pubDate: 2023-07-22
description: "This is the first post of my new blog."
author: "bitbloxhub"
image:
url: "https://docs.astro.build/assets/full-logo-light.png"
alt: "The full Astro logo."
---
Welcome to my new blog i have built using astro!

0 comments on commit e610924

Please sign in to comment.