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'} -

-
-
- - {childMdx.body} - +
+

+ {teamMember?.frontmatter?.name || name} + , {teamMember?.frontmatter?.jobTitle || 'Contributor'} + +

+
+ + {childMdx.body} + +
+
) } -export default function Question({ question }) { +export default function Question({ question, id }) { const components = { inlineCode: InlineCode, blockquote: Blockquote, pre: CodeBlock, img: ZoomImage, } - const { avatar, childMdx, name } = question[0] + const { avatar, childMdx, name, ts } = question[0] return (
@@ -49,8 +65,12 @@ export default function Question({ question }) { {childMdx.body}
-

by {name}

- {question.length > 1 && question.slice(1).map((reply, index) => )} +

+ by {name}{' '} + +

+ {question.length > 1 && + question.slice(1).map((reply, index) => )}
) diff --git a/src/components/CommunityQuestions/index.js b/src/components/CommunityQuestions/index.js index 167f88696..337a7764a 100644 --- a/src/components/CommunityQuestions/index.js +++ b/src/components/CommunityQuestions/index.js @@ -13,7 +13,7 @@ export default function CommunityQuestions({ questions }) { return ( question.childrenReply && question.childrenReply.length > 0 && ( - + ) ) })} diff --git a/src/components/PostLayout/index.js b/src/components/PostLayout/index.js index 2cb6cef5d..9a02bc988 100644 --- a/src/components/PostLayout/index.js +++ b/src/components/PostLayout/index.js @@ -42,7 +42,7 @@ const A = (props) => {title}} {children} @@ -97,7 +97,20 @@ export const Contributor = ({ image, name }) => { return ( <>
- + {image ? ( + + ) : ( + + + + + )}
{name} @@ -131,7 +144,14 @@ export const Text = ({ children }) => { return

{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" >
-
+
{children}
{questions && questions}
-