mirror of
				https://github.com/valentineus/popov.link.git
				synced 2025-11-04 14:59:45 +03:00 
			
		
		
		
	Added reading time timer
This commit is contained in:
		@@ -1,5 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
<link href={canonicalURL} rel="canonical" />
 | 
			
		||||
@@ -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>
 | 
			
		||||
				 by Valentin Popov ‐
 | 
			
		||||
				<strong>1 min read</strong>
 | 
			
		||||
			</small>
 | 
			
		||||
		</p>
 | 
			
		||||
	</div>
 | 
			
		||||
	<slot />
 | 
			
		||||
</BaseLayout>
 | 
			
		||||
@@ -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>
 | 
			
		||||
				 by Valentin Popov ‐
 | 
			
		||||
				<strong>{remarkPluginFrontmatter.minutesRead}</strong>
 | 
			
		||||
			</small>
 | 
			
		||||
		</p>
 | 
			
		||||
	</div>
 | 
			
		||||
	<Content />
 | 
			
		||||
</Layout>
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
---
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								src/plugins/remarkReadingTime.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/plugins/remarkReadingTime.ts
									
									
									
									
									
										Normal file
									
								
							@@ -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;
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user