aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/CanonicalURL.astro5
-rw-r--r--src/layouts/PostLayout.astro24
-rw-r--r--src/pages/blog/[...slug].astro21
-rw-r--r--src/pages/feed.xml.js2
-rw-r--r--src/pages/index.astro2
-rw-r--r--src/plugins/remarkReadingTime.ts11
6 files changed, 32 insertions, 33 deletions
diff --git a/src/components/CanonicalURL.astro b/src/components/CanonicalURL.astro
deleted file mode 100644
index 0081f71..0000000
--- a/src/components/CanonicalURL.astro
+++ /dev/null
@@ -1,5 +0,0 @@
----
-const canonicalURL = new URL(Astro.url.pathname, Astro.site);
----
-
-<link href={canonicalURL} rel="canonical" />
diff --git a/src/layouts/PostLayout.astro b/src/layouts/PostLayout.astro
deleted file mode 100644
index 37bbe37..0000000
--- a/src/layouts/PostLayout.astro
+++ /dev/null
@@ -1,24 +0,0 @@
----
-import BaseLayout from "../layouts/BaseLayout.astro";
----
-
-<style>
- .header {
- text-align: center;
- }
-</style>
-
-<BaseLayout>
- <div class="header">
- <h1>Title</h1>
- <p>
- <small>
- Posted
- <time datetime="#">#</time>
- &nbsp;by&nbsp;Valentin Popov&nbsp;‐
- <strong>1 min read</strong>
- </small>
- </p>
- </div>
- <slot />
-</BaseLayout>
diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro
index c94fe52..a142db4 100644
--- a/src/pages/blog/[...slug].astro
+++ b/src/pages/blog/[...slug].astro
@@ -1,6 +1,6 @@
---
import { type CollectionEntry, getCollection } from "astro:content";
-import Layout from "../../layouts/PostLayout.astro";
+import Layout from "../../layouts/PageLayout.astro";
export async function getStaticPaths() {
const posts = await getCollection("blog");
@@ -12,9 +12,26 @@ export async function getStaticPaths() {
type Props = CollectionEntry<"blog">;
const post = Astro.props;
-const { Content } = await post.render();
+const { Content, remarkPluginFrontmatter } = await post.render();
---
+<style>
+ .header {
+ text-align: center;
+ }
+</style>
+
<Layout>
+ <div class="header">
+ <h1>Title</h1>
+ <p>
+ <small>
+ Posted
+ <time datetime="#">#</time>
+ &nbsp;by&nbsp;Valentin Popov&nbsp;‐
+ <strong>{remarkPluginFrontmatter.minutesRead}</strong>
+ </small>
+ </p>
+ </div>
<Content />
</Layout>
diff --git a/src/pages/feed.xml.js b/src/pages/feed.xml.js
index 0fcc82f..a509386 100644
--- a/src/pages/feed.xml.js
+++ b/src/pages/feed.xml.js
@@ -1,5 +1,5 @@
-import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
+import rss from "@astrojs/rss";
export async function GET(context) {
const posts = await getCollection("blog");
diff --git a/src/pages/index.astro b/src/pages/index.astro
index bc98c67..c4f5577 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -1,6 +1,6 @@
---
-import Layout from "../layouts/PageLayout.astro";
import { getCollection } from "astro:content";
+import Layout from "../layouts/PageLayout.astro";
const posts = await getCollection("blog");
---
diff --git a/src/plugins/remarkReadingTime.ts b/src/plugins/remarkReadingTime.ts
new file mode 100644
index 0000000..93f7b00
--- /dev/null
+++ b/src/plugins/remarkReadingTime.ts
@@ -0,0 +1,11 @@
+import type { RemarkPlugin } from "@astrojs/markdown-remark";
+import { toString } from "mdast-util-to-string";
+import getReadingTime from "reading-time";
+
+export function remarkReadingTime(): RemarkPlugin {
+ return function (tree, { data }) {
+ const textOnPage = toString(tree);
+ const readingTime = getReadingTime(textOnPage);
+ data.astro.frontmatter.minutesRead = readingTime.text;
+ };
+}