mirror of
https://github.com/BillyOutlast/posthog.com.git
synced 2026-02-04 03:11:21 +01:00
remove questions/replies from node creation
This commit is contained in:
@@ -146,30 +146,16 @@ module.exports = {
|
||||
path
|
||||
}
|
||||
}
|
||||
questions: allSqueakQuestion {
|
||||
nodes {
|
||||
permalink
|
||||
}
|
||||
}
|
||||
}`,
|
||||
resolveSiteUrl: ({ site }) => {
|
||||
return site.siteMetadata.siteUrl
|
||||
},
|
||||
resolvePages: async ({
|
||||
allSitePage: { nodes: allPages },
|
||||
site,
|
||||
questions: { nodes: allQuestions },
|
||||
}) => {
|
||||
resolvePages: async ({ allSitePage: { nodes: allPages }, site }) => {
|
||||
const transformedPages = allPages.map(({ path }) => {
|
||||
return {
|
||||
path: `${site.siteMetadata.siteUrl}${path}`,
|
||||
}
|
||||
})
|
||||
const transformedQuestionPages = allQuestions.map(({ permalink }) => {
|
||||
return {
|
||||
path: `${site.siteMetadata.siteUrl}/questions/${permalink}`,
|
||||
}
|
||||
})
|
||||
|
||||
let plugins = []
|
||||
try {
|
||||
@@ -185,7 +171,7 @@ module.exports = {
|
||||
path: `${site.siteMetadata.siteUrl}/plugins/` + plugin.name.toLowerCase().replace(/ /g, '-'),
|
||||
}))
|
||||
|
||||
return [...transformedPages, ...transformedQuestionPages, ...plugins]
|
||||
return [...transformedPages, ...plugins]
|
||||
},
|
||||
serialize: async ({ path }) => {
|
||||
let changefreq = 'monthly'
|
||||
|
||||
@@ -101,39 +101,6 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
query: `
|
||||
{
|
||||
questions: allSqueakQuestion(filter: {permalink: {ne: null}, archived: {ne: true}}) {
|
||||
nodes {
|
||||
id
|
||||
title: subject
|
||||
body
|
||||
resolvedBy {
|
||||
body
|
||||
}
|
||||
resolved
|
||||
permalink
|
||||
internal {
|
||||
contentDigest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
transformer: ({ data }) => {
|
||||
return data.questions.nodes.map(({ body, permalink, resolvedBy, ...question }) => {
|
||||
return {
|
||||
...question,
|
||||
excerpt: body,
|
||||
slug: `questions/${permalink || ''}`,
|
||||
type: 'question',
|
||||
path_ranking: 5,
|
||||
resolutionBody: resolvedBy?.body,
|
||||
}
|
||||
})
|
||||
},
|
||||
},
|
||||
{
|
||||
query: `{ query: sitePage { id } }`,
|
||||
transformer: () => {
|
||||
|
||||
@@ -100,12 +100,7 @@ export const onCreateNode: GatsbyNode['onCreateNode'] = async ({
|
||||
|
||||
if (node.internal.type === `MarkdownRemark` || node.internal.type === 'Mdx') {
|
||||
const parent = getNode(node.parent)
|
||||
if (
|
||||
parent?.internal.type === 'SqueakReply' ||
|
||||
parent?.internal.type === 'PostHogPull' ||
|
||||
parent?.internal.type === 'PostHogIssue'
|
||||
)
|
||||
return
|
||||
if (parent?.internal.type === 'PostHogPull' || parent?.internal.type === 'PostHogIssue') return
|
||||
|
||||
const imageFields = ['featuredImage', 'thumbnail', 'logo', 'logoDark', 'icon']
|
||||
imageFields.forEach((field) => {
|
||||
|
||||
@@ -69,89 +69,6 @@ export const sourceNodes: GatsbyNode['sourceNodes'] = async (
|
||||
page++
|
||||
}
|
||||
|
||||
// Fetch all questions
|
||||
page = 1
|
||||
while (true) {
|
||||
let questionQuery = qs.stringify({
|
||||
pagination: {
|
||||
page,
|
||||
pageSize: 100,
|
||||
},
|
||||
populate: {
|
||||
profile: {
|
||||
fields: ['id'],
|
||||
},
|
||||
replies: {
|
||||
populate: {
|
||||
profile: {
|
||||
fields: ['id'],
|
||||
},
|
||||
},
|
||||
},
|
||||
topics: {
|
||||
fields: ['id'],
|
||||
},
|
||||
resolvedBy: {
|
||||
fields: ['id'],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const questions = await fetch(`${apiHost}/api/questions?${questionQuery}`).then((res) => res.json())
|
||||
|
||||
for (let question of questions.data) {
|
||||
const { topics, replies, profile, resolvedBy, ...rest } = question.attributes
|
||||
|
||||
if (!profile.data?.id) {
|
||||
console.warn(`Question ${question.id} has no profile`)
|
||||
continue
|
||||
}
|
||||
|
||||
const filteredReplies = replies.data.filter((reply) => reply.attributes.profile.data?.id)
|
||||
|
||||
createNode({
|
||||
type: `SqueakQuestion`,
|
||||
id: createNodeId(`squeak-question-${question.id}`),
|
||||
squeakId: question.id,
|
||||
internal: {
|
||||
contentDigest: createContentDigest(question),
|
||||
type: `SqueakQuestion`,
|
||||
},
|
||||
...(profile.data && { profile: { id: createNodeId(`squeak-profile-${profile.data.id}`) } }),
|
||||
replies: filteredReplies.map((reply) => ({
|
||||
id: createNodeId(`squeak-reply-${reply.id}`),
|
||||
})),
|
||||
topics: topics.data.map((topic) => ({
|
||||
id: createNodeId(`squeak-topic-${topic.id}`),
|
||||
})),
|
||||
...rest,
|
||||
resolvedBy: createNodeId(`squeak-reply-${resolvedBy?.data?.id}`),
|
||||
})
|
||||
|
||||
for (let reply of filteredReplies) {
|
||||
const { profile, ...replyData } = reply.attributes
|
||||
|
||||
createNode({
|
||||
type: `SqueakReply`,
|
||||
id: createNodeId(`squeak-reply-${reply.id}`),
|
||||
squeakId: reply.id,
|
||||
internal: {
|
||||
contentDigest: createContentDigest(replyData.body),
|
||||
type: `SqueakReply`,
|
||||
content: replyData.body,
|
||||
},
|
||||
...(profile.data && { profile: { id: createNodeId(`squeak-profile-${profile.data.id}`) } }),
|
||||
...replyData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (questions.meta.pagination.page >= questions.meta.pagination.pageCount) {
|
||||
break
|
||||
}
|
||||
page++
|
||||
}
|
||||
|
||||
// Fetch all topic groups
|
||||
let query = qs.stringify({
|
||||
populate: {
|
||||
@@ -396,26 +313,6 @@ export const createSchemaCustomization: GatsbyNode['createSchemaCustomization']
|
||||
color: String
|
||||
}
|
||||
|
||||
type SqueakQuestion implements Node {
|
||||
id: ID!
|
||||
squeakId: Int!
|
||||
body: String!
|
||||
createdAt: Date! @dateformat
|
||||
profile: SqueakProfile! @link(by: "id", from: "profile.id")
|
||||
replies: [SqueakReply!] @link(by: "id", from: "replies.id")
|
||||
topics: [SqueakTopic!] @link(by: "id", from: "topics.id")
|
||||
resolvedBy: SqueakReply @link(by: "id")
|
||||
}
|
||||
|
||||
type SqueakReply implements Node {
|
||||
id: ID!
|
||||
squeakId: Int!
|
||||
body: String!
|
||||
createdAt: Date! @dateformat
|
||||
profile: SqueakProfile! @link(by: "id", from: "profile.id")
|
||||
question: SqueakQuestion! @link(from: "id", to: "question")
|
||||
}
|
||||
|
||||
type SqueakTopicGroup implements Node {
|
||||
id: ID!
|
||||
squeakId: Int!
|
||||
|
||||
Reference in New Issue
Block a user