Add read time

This commit is contained in:
Jade Ellis
2024-07-16 22:24:34 +01:00
parent 85ffece367
commit 9dbdcf2493
4 changed files with 68 additions and 2 deletions
+12 -1
View File
@@ -15,6 +15,7 @@ import rehypeKatexSvelte from 'rehype-katex-svelte';
// import github from "remark-github";
import rehypeSlug from 'rehype-slug';
import remarkReadingTime from "remark-reading-time";
// import rehypeToc from '@jsdevtools/rehype-toc';
import { createHighlighter } from "@bitmachina/highlighter";
@@ -161,6 +162,14 @@ function add_toc_remark(opts) {
vFile.data.fm.headings = buildNestedHeadings(vFile.data.flattenedHeadings);
};
}
function add_data_to_fm(opts) {
return async function transformer(tree, vFile) {
if (!vFile.data.fm) vFile.data.fm = {};
vFile.data.fm.readingTime = vFile.data.readingTime;
};
}
import { toString as hast_tree_to_string } from 'hast-util-to-string'
/**
* Determines whether the given node is an HTML element.
@@ -242,7 +251,7 @@ function vite_images_rehype(opts) {
visit(tree, { tagName: "img" }, (node) => {
let url = node.properties.src;
url = (url.includes("?") ? url + "&" : url + "?") + "url";
node.properties.src = `{${transformUrl(url)}}`
// new URL('./img.png', import.meta.url).href
// vFile.data.headings.push({
@@ -359,6 +368,8 @@ const config = {
// }],
// [remarkBibliography, { bibliography }],
// [remarkMermaid, {}]
remarkReadingTime,
add_data_to_fm,
[add_toc_remark, { prefix: "h-" }]
],
rehypePlugins: [
+1
View File
@@ -34,6 +34,7 @@
"remark-gfm": "^4.0.0",
"remark-github": "^12.0.0",
"remark-math": "^3.0.1",
"remark-reading-time": "^2.0.1",
"remark-wiki-link": "^2.0.1",
"rollup": "^4.18.0",
"rollup-plugin-type-as-json-schema": "^0.2.6",
@@ -34,7 +34,7 @@
<aside>
<a class="u-url" href={canonical}>Published on <time class="dt-published" datetime={data.post.date}
>{new Date(data.post.date).toLocaleDateString()}</time
></a>
></a> · <span>{data.post.readingTime.text}</span>
</aside>
<Toc headings={data.post.headings} />
<!-- {#await GhReleasesDownload}