Add read time
This commit is contained in:
parent
85ffece367
commit
9dbdcf2493
4 changed files with 68 additions and 2 deletions
|
|
@ -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: [
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
54
pnpm-lock.yaml
generated
54
pnpm-lock.yaml
generated
|
|
@ -152,6 +152,9 @@ importers:
|
|||
remark-math:
|
||||
specifier: ^3.0.1
|
||||
version: 3.0.1
|
||||
remark-reading-time:
|
||||
specifier: ^2.0.1
|
||||
version: 2.0.1
|
||||
remark-wiki-link:
|
||||
specifier: ^2.0.1
|
||||
version: 2.0.1
|
||||
|
|
@ -1346,6 +1349,13 @@ packages:
|
|||
engines: {node: '>=4'}
|
||||
hasBin: true
|
||||
|
||||
estree-util-is-identifier-name@2.1.0:
|
||||
resolution: {integrity: sha512-bEN9VHRyXAUOjkKVQVvArFym08BTWB0aJPppZZr0UNyAqWsLaVfAqP7hbaTJjzHifmB5ebnR8Wm7r7yGN/HonQ==}
|
||||
|
||||
estree-util-value-to-estree@1.3.0:
|
||||
resolution: {integrity: sha512-Y+ughcF9jSUJvncXwqRageavjrNPAI+1M/L3BI3PyLp1nmgYTGUXU6t5z1Y7OWuThoDdhPME07bQU+d5LxdJqw==}
|
||||
engines: {node: '>=12.0.0'}
|
||||
|
||||
estree-walker@2.0.2:
|
||||
resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==}
|
||||
|
||||
|
|
@ -1536,6 +1546,10 @@ packages:
|
|||
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
|
||||
engines: {node: '>=0.12.0'}
|
||||
|
||||
is-plain-obj@3.0.0:
|
||||
resolution: {integrity: sha512-gwsOE28k+23GP1B6vFl1oVh/WOzmawBrKwo5Ev6wMKzPkaXaCDIQKzLnvsA42DRlbVTWorkgTKIviAKCWkfUwA==}
|
||||
engines: {node: '>=10'}
|
||||
|
||||
is-plain-obj@4.1.0:
|
||||
resolution: {integrity: sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==}
|
||||
engines: {node: '>=12'}
|
||||
|
|
@ -1925,6 +1939,9 @@ packages:
|
|||
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
|
||||
engines: {node: '>=8.10.0'}
|
||||
|
||||
reading-time@1.5.0:
|
||||
resolution: {integrity: sha512-onYyVhBNr4CmAxFsKS7bz+uTLRakypIe4R+5A824vBSkQy/hB3fZepoVEf8OVAxzLvK+H/jm9TzpI3ETSm64Kg==}
|
||||
|
||||
reduce-flatten@2.0.0:
|
||||
resolution: {integrity: sha512-EJ4UNY/U1t2P/2k6oqotuX2Cc3T6nxJwsM0N0asT7dhrtH1ltUxDn4NalSYmPE2rCkVpcf/X6R0wDwcFpzhd4w==}
|
||||
engines: {node: '>=6'}
|
||||
|
|
@ -1966,6 +1983,9 @@ packages:
|
|||
remark-parse@11.0.0:
|
||||
resolution: {integrity: sha512-FCxlKLNGknS5ba/1lmpYijMUzX2esxW5xQqjWxw2eHFfS2MSdaHVINFmhjo+qN1WhZhNimq0dZATN9pH0IDrpA==}
|
||||
|
||||
remark-reading-time@2.0.1:
|
||||
resolution: {integrity: sha512-fy4BKy9SRhtYbEHvp6AItbRTnrhiDGbqLQTSYVbQPGuRCncU1ubSsh9p/W5QZSxtYcUXv8KGL0xBgPLyNJA1xw==}
|
||||
|
||||
remark-stringify@11.0.0:
|
||||
resolution: {integrity: sha512-1OSmLd3awB/t8qdoEOMazZkNsfVTeY4fTsgzcQFdXNq8ToTN4ZGwrMnlda4K6smTFKD+GRV6O48i6Z4iKgPPpw==}
|
||||
|
||||
|
|
@ -2360,6 +2380,9 @@ packages:
|
|||
unist-util-visit-parents@3.1.1:
|
||||
resolution: {integrity: sha512-1KROIZWo6bcMrZEwiH2UrXDyalAa0uqzWCxCJj6lPOvTve2WkfgCytoDTPaMnodXh1WrXOq0haVYHj99ynJlsg==}
|
||||
|
||||
unist-util-visit-parents@4.1.1:
|
||||
resolution: {integrity: sha512-1xAFJXAKpnnJl8G7K5KgU7FY55y3GcLIXqkzUj5QF/QVP7biUm0K0O2oqVkYsdjzJKifYeWn9+o6piAK2hGSHw==}
|
||||
|
||||
unist-util-visit-parents@5.1.3:
|
||||
resolution: {integrity: sha512-x6+y8g7wWMyQhL1iZfhIPhDAs7Xwbn9nRosDXl7qoPTSCy0yNxnKc+hWokFifWQIDGi154rdUqKvbCa4+1kLhg==}
|
||||
|
||||
|
|
@ -2369,6 +2392,9 @@ packages:
|
|||
unist-util-visit@2.0.3:
|
||||
resolution: {integrity: sha512-iJ4/RczbJMkD0712mGktuGpm/U4By4FfDonL7N/9tATGIF4imikjOuagyMY53tnZq3NP6BcmlrHhEKAfGWjh7Q==}
|
||||
|
||||
unist-util-visit@3.1.0:
|
||||
resolution: {integrity: sha512-Szoh+R/Ll68QWAyQyZZpQzZQm2UPbxibDvaY8Xc9SUtYgPsDzx5AWSk++UUt2hJuow8mvwR+rG+LQLw+KsuAKA==}
|
||||
|
||||
unist-util-visit@4.1.1:
|
||||
resolution: {integrity: sha512-n9KN3WV9k4h1DxYR1LoajgN93wpEi/7ZplVe02IoB4gH5ctI1AaF2670BLHQYbwj+pY83gFtyeySFiyMHJklrg==}
|
||||
|
||||
|
|
@ -3568,6 +3594,12 @@ snapshots:
|
|||
|
||||
esprima@4.0.1: {}
|
||||
|
||||
estree-util-is-identifier-name@2.1.0: {}
|
||||
|
||||
estree-util-value-to-estree@1.3.0:
|
||||
dependencies:
|
||||
is-plain-obj: 3.0.0
|
||||
|
||||
estree-walker@2.0.2: {}
|
||||
|
||||
estree-walker@3.0.3:
|
||||
|
|
@ -3786,6 +3818,8 @@ snapshots:
|
|||
|
||||
is-number@7.0.0: {}
|
||||
|
||||
is-plain-obj@3.0.0: {}
|
||||
|
||||
is-plain-obj@4.1.0: {}
|
||||
|
||||
is-reference@1.2.1:
|
||||
|
|
@ -4362,6 +4396,8 @@ snapshots:
|
|||
dependencies:
|
||||
picomatch: 2.3.1
|
||||
|
||||
reading-time@1.5.0: {}
|
||||
|
||||
reduce-flatten@2.0.0: {}
|
||||
|
||||
regenerator-runtime@0.14.1: {}
|
||||
|
|
@ -4436,6 +4472,13 @@ snapshots:
|
|||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
remark-reading-time@2.0.1:
|
||||
dependencies:
|
||||
estree-util-is-identifier-name: 2.1.0
|
||||
estree-util-value-to-estree: 1.3.0
|
||||
reading-time: 1.5.0
|
||||
unist-util-visit: 3.1.0
|
||||
|
||||
remark-stringify@11.0.0:
|
||||
dependencies:
|
||||
'@types/mdast': 4.0.4
|
||||
|
|
@ -4868,6 +4911,11 @@ snapshots:
|
|||
'@types/unist': 2.0.10
|
||||
unist-util-is: 4.1.0
|
||||
|
||||
unist-util-visit-parents@4.1.1:
|
||||
dependencies:
|
||||
'@types/unist': 2.0.10
|
||||
unist-util-is: 5.2.1
|
||||
|
||||
unist-util-visit-parents@5.1.3:
|
||||
dependencies:
|
||||
'@types/unist': 2.0.10
|
||||
|
|
@ -4884,6 +4932,12 @@ snapshots:
|
|||
unist-util-is: 4.1.0
|
||||
unist-util-visit-parents: 3.1.1
|
||||
|
||||
unist-util-visit@3.1.0:
|
||||
dependencies:
|
||||
'@types/unist': 2.0.10
|
||||
unist-util-is: 5.2.1
|
||||
unist-util-visit-parents: 4.1.1
|
||||
|
||||
unist-util-visit@4.1.1:
|
||||
dependencies:
|
||||
'@types/unist': 2.0.10
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue