diff --git a/gatsby-browser.js b/gatsby-browser.js index dc94b8424..b06fdf287 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -15,7 +15,9 @@ export const onRouteUpdate = ({ location, prevLocation }) => { // Checking for prevLocation prevents this from happening twice if (typeof window !== 'undefined' && prevLocation) { var slug = location.pathname.substring(1) - var theme = /^handbook|^docs|^blog|^integrations|^product|^tutorials/.test(slug) ? window.__theme : 'light' + var theme = /^handbook|^docs|^blog|^integrations|^product|^tutorials|^questions/.test(slug) + ? window.__theme + : 'light' document.body.className = theme } } diff --git a/gatsby-ssr.js b/gatsby-ssr.js index 308a8fdbd..3c2b060cc 100644 --- a/gatsby-ssr.js +++ b/gatsby-ssr.js @@ -36,7 +36,7 @@ export const onRenderBody = function ({ setPreBodyComponents }) { }) try { preferredTheme = - (/^handbook|^docs|^blog|^integrations|^product|^tutorials/.test(slug) && + (/^handbook|^docs|^blog|^integrations|^product|^tutorials|^questions/.test(slug) && (localStorage.getItem('theme') || (darkQuery.matches ? 'dark' : 'light'))) || 'light' } catch (err) {} diff --git a/gatsby/createPages.js b/gatsby/createPages.js index 4ce7ac484..66a7783e0 100644 --- a/gatsby/createPages.js +++ b/gatsby/createPages.js @@ -17,6 +17,7 @@ module.exports = exports.createPages = async ({ actions, graphql }) => { const TutorialsCategoryTemplate = path.resolve(`src/templates/TutorialsCategory.js`) const TutorialsAuthorTemplate = path.resolve(`src/templates/TutorialsAuthor.js`) const HostHogTemplate = path.resolve(`src/templates/HostHog.js`) + const Question = path.resolve(`src/templates/Question.js`) const result = await graphql(` { allMdx( @@ -178,6 +179,11 @@ module.exports = exports.createPages = async ({ actions, graphql }) => { slug } } + questions: allQuestion { + nodes { + id + } + } } `) @@ -416,4 +422,14 @@ module.exports = exports.createPages = async ({ actions, graphql }) => { }) } }) + result.data.questions.nodes.forEach((node) => { + const { id } = node + createPage({ + path: `questions/${id}`, + component: Question, + context: { + id, + }, + }) + }) } diff --git a/gatsby/sourceNodes.js b/gatsby/sourceNodes.js index a3c03d2f9..397eef861 100644 --- a/gatsby/sourceNodes.js +++ b/gatsby/sourceNodes.js @@ -181,6 +181,7 @@ module.exports = exports.sourceNodes = async ({ actions, createContentDigest, cr name, imageURL, fullName, + ts: new Date(ts * 1000), } createNode(replyNode) createParentChildLink({ parent: node, child: replyNode }) diff --git a/src/components/CommunityQuestions/Question.js b/src/components/CommunityQuestions/Question.js index b6b4f3da3..907df68b2 100644 --- a/src/components/CommunityQuestions/Question.js +++ b/src/components/CommunityQuestions/Question.js @@ -2,12 +2,25 @@ import { MDXProvider } from '@mdx-js/react' import { Blockquote } from 'components/BlockQuote' import { CodeBlock } from 'components/CodeBlock' import { InlineCode } from 'components/InlineCode' +import Link from 'components/Link' import { ZoomImage } from 'components/ZoomImage' import { MDXRenderer } from 'gatsby-plugin-mdx' import React from 'react' import Avatar from './Avatar' -const Reply = ({ avatar, name, childMdx, teamMember }) => { +export const Days = ({ ts, url }) => { + const days = Number(ts) + return ( + + {ts} day{days === 1 ? '' : 's'} ago + + ) +} + +export const Reply = ({ avatar, name, childMdx, teamMember, ts, parentId, id, className = '' }) => { const components = { inlineCode: InlineCode, blockquote: Blockquote, @@ -15,31 +28,34 @@ const Reply = ({ avatar, name, childMdx, teamMember }) => { img: ZoomImage, } return ( -
- {teamMember?.frontmatter?.name || name} - , {teamMember?.frontmatter?.jobTitle || 'Contributor'} -
-
+ {teamMember?.frontmatter?.name || name}
+ , {teamMember?.frontmatter?.jobTitle || 'Contributor'}
+
by {name}
- {question.length > 1 && question.slice(1).map((reply, index) =>
+ by {name}{' '}
+
{children}
} -export default function PostLayout({ tableOfContents, children, sidebar, contentWidth = 650, questions }) { +export default function PostLayout({ + tableOfContents, + children, + sidebar, + contentWidth = 650, + questions, + article = true, +}) { const { hash } = useLocation() const breakpoints = useBreakpoint() const [view, setView] = useState('Article') @@ -150,16 +170,16 @@ export default function PostLayout({ tableOfContents, children, sidebar, content className="w-full relative lg:grid lg:grid-flow-col items-start -mb-20" >