mirror of
https://github.com/mastermindzh/rickvanlieshout.com
synced 2025-07-26 20:22:32 +02:00
added read time on index and post pages
This commit is contained in:
@@ -52,7 +52,7 @@ const createPages: GatsbyNode["createPages"] = async ({ graphql, actions }) => {
|
||||
createPage({
|
||||
path: node.fields.slug,
|
||||
component: constants.templates.postTemplate,
|
||||
context: { slug: node.fields.slug },
|
||||
context: { slug: node.fields.slug, readingTime: node?.fields?.readingTime },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@@ -1,15 +1,12 @@
|
||||
import { GatsbyNode } from "gatsby";
|
||||
import { createFilePath } from "gatsby-source-filesystem";
|
||||
import readingTime from "reading-time";
|
||||
|
||||
import * as constants from "./constants";
|
||||
import * as types from "./types";
|
||||
import * as utils from "./utils";
|
||||
|
||||
const onCreateNode: GatsbyNode["onCreateNode"] = ({
|
||||
node,
|
||||
actions,
|
||||
getNode,
|
||||
}) => {
|
||||
const onCreateNode: GatsbyNode["onCreateNode"] = ({ node, actions, getNode }) => {
|
||||
const { createNodeField } = actions;
|
||||
|
||||
if (node.internal.type === "MarkdownRemark") {
|
||||
@@ -31,12 +28,7 @@ const onCreateNode: GatsbyNode["onCreateNode"] = ({
|
||||
|
||||
if (tags) {
|
||||
const value = tags.map((tag) =>
|
||||
utils.concat(
|
||||
constants.routes.tagRoute,
|
||||
"/",
|
||||
utils.toKebabCase(tag),
|
||||
"/",
|
||||
),
|
||||
utils.concat(constants.routes.tagRoute, "/", utils.toKebabCase(tag), "/")
|
||||
);
|
||||
|
||||
createNodeField({ node, name: "tagSlugs", value });
|
||||
@@ -47,11 +39,17 @@ const onCreateNode: GatsbyNode["onCreateNode"] = ({
|
||||
constants.routes.categoryRoute,
|
||||
"/",
|
||||
utils.toKebabCase(category),
|
||||
"/",
|
||||
"/"
|
||||
);
|
||||
|
||||
createNodeField({ node, name: "categorySlug", value });
|
||||
}
|
||||
|
||||
createNodeField({
|
||||
node,
|
||||
name: "readingTime",
|
||||
value: readingTime(node.rawMarkdownBody as string),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -19,6 +19,9 @@ const pagesQuery = async (graphql: CreatePagesArgs["graphql"]) => {
|
||||
}
|
||||
fields {
|
||||
slug
|
||||
readingTime {
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,9 @@ const postsQuery = async (graphql: CreatePagesArgs["graphql"]) => {
|
||||
node {
|
||||
fields {
|
||||
slug
|
||||
readingTime {
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -13,6 +13,9 @@ interface Fields {
|
||||
slug?: string;
|
||||
categorySlug?: string;
|
||||
tagSlugs?: Array<string>;
|
||||
readingTime?: {
|
||||
text: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface Node extends GatsbyNode {
|
||||
|
Reference in New Issue
Block a user