Skip to content

Commit

Permalink
feat: add RSS feed!!! #110 #108
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyabrain committed Aug 19, 2023
1 parent 09e70de commit d0effd0
Show file tree
Hide file tree
Showing 4 changed files with 1,098 additions and 114 deletions.
60 changes: 60 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
siteMetadata: {
title: `Tattle`,
siteUrl: "https://tattle.co.in/", // looks like gatsby-plugin-feed requires this to be the field name
description: `We build tools and datasets to understand and respond to misinformation in India.`,
author: `@tattlemade`,
base_url: "https://tattle.co.in",
Expand Down Expand Up @@ -106,5 +107,64 @@ module.exports = {
},
},
`gatsby-plugin-styled-components`,
{
resolve: `gatsby-plugin-feed`,
options: {
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize: ({ query: { site, allMdx } }) => {
return allMdx.nodes.map(node => {
return Object.assign({}, node.frontmatter, {
title: node.frontmatter.name,
description: node.frontmatter.excerpt,
url: site.siteMetadata.siteUrl + "/" + node.slug,
guid: site.siteMetadata.siteUrl + "/" + node.slug,
date: node.frontmatter.date,
author: node.frontmatter.author,
})
})
},
query: `
{
allMdx(
filter: {fileAbsolutePath: {regex: "/.*/src/blog/"}}
sort: {fields: frontmatter___date, order: DESC}
) {
nodes {
slug
frontmatter {
name
excerpt
author
project
date
tags
cover
}
fileAbsolutePath
}
}
}
`,
output: "/rss.xml",
title:
"Tattle - Civic Tech intervention for Misinformation, Content Moderation and Media Literacy",
},
],
},
},
],
}
184 changes: 98 additions & 86 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const path = require("path")
const QRCode = require("qrcode")
const fs = require("fs/promises")
const { createFilePath } = require(`gatsby-source-filesystem`)

exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions
const { createPage } = actions

// create pages for people
const result = await graphql(`
// create pages for people
const result = await graphql(`
query {
allMdx {
nodes {
Expand All @@ -24,85 +23,98 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
}
`)

if (result.errors) {
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query for Projects')
}

const nodes = result.data.allMdx.nodes

// create folder for user avatar
// try {
// await fs.access("./src/people/avatar")
// } catch {
// await fs.mkdir("./src/people/avatar")
// }

nodes.forEach(async node => {
const { fileAbsolutePath, id } = node
// console.log(`------ : ${id}`)

if (fileAbsolutePath.indexOf("/src/people/") !== -1) {
// create QR code avatar

// await QRCode.toFile(
// `./src/people/avatar/${node.slug}.png`,
// "/people/${node.slug}"
// )

// create Page
await createPage({
path: `/people/${node.slug}`,
component: path.resolve(`./src/components/default-people-layout.js`),
context: { id },
})
}

// if (fileAbsolutePath.indexOf("/src/project/") !== -1) {
// createPage({
// path: `/project/${node.slug}`,
// component: path.resolve(`./src/components/default-page-layout.js`),
// context: { id: node.id },
// })
// }

// CREATE BLOGS
if (fileAbsolutePath.indexOf("/src/blog/") !== -1) {
createPage({
path: `/blog/${node.slug}`,
component: path.resolve(`./src/components/default-blog-layout.js`),
context: { id: node.id },
})
}

createPage({
path: `/blog/`,
component: path.resolve(`./src/components/default-blog-index-layout.js`),
})

// CREATE TAGS PAGE
const tags_set = new Set()
const tags_arr = node.frontmatter.tags ? node.frontmatter.tags.split(',').map(tag => tag.trim()) : [];
result.data.allMdx.nodes.forEach(node => {
if (tags_arr) {
tags_arr.forEach(tag => tags_set.add(tag))
}
})

tags_set.forEach(tag => {
createPage({
path: `/blog/tags/${tag}`,
component: path.resolve('./src/components/default-tag-page-layout.js'),
context: { tag },
})
})

// CREATE PROJECTS
if (fileAbsolutePath.indexOf("/src/project/") !== -1) {
createPage({
path: `/project/${node.slug}`,
component: path.resolve(`./src/components/default-blog-layout.js`),
context: { id: node.id },
})
}
})
if (result.errors) {
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query for Projects')
}

const nodes = result.data.allMdx.nodes

// create folder for user avatar
// try {
// await fs.access("./src/people/avatar")
// } catch {
// await fs.mkdir("./src/people/avatar")
// }

nodes.forEach(async node => {
const { fileAbsolutePath, id } = node
// console.log(`------ : ${id}`)

if (fileAbsolutePath.indexOf("/src/people/") !== -1) {
// create QR code avatar

// await QRCode.toFile(
// `./src/people/avatar/${node.slug}.png`,
// "/people/${node.slug}"
// )

// create Page
await createPage({
path: `/people/${node.slug}`,
component: path.resolve(`./src/components/default-people-layout.js`),
context: { id },
})
}

// if (fileAbsolutePath.indexOf("/src/project/") !== -1) {
// createPage({
// path: `/project/${node.slug}`,
// component: path.resolve(`./src/components/default-page-layout.js`),
// context: { id: node.id },
// })
// }

// CREATE BLOGS
if (fileAbsolutePath.indexOf("/src/blog/") !== -1) {
createPage({
path: `/blog/${node.slug}`,
component: path.resolve(`./src/components/default-blog-layout.js`),
context: { id: node.id },
})
}

createPage({
path: `/blog/`,
component: path.resolve(`./src/components/default-blog-index-layout.js`),
})

// CREATE TAGS PAGE
const tags_set = new Set()
const tags_arr = node.frontmatter.tags
? node.frontmatter.tags.split(",").map(tag => tag.trim())
: []
result.data.allMdx.nodes.forEach(node => {
if (tags_arr) {
tags_arr.forEach(tag => tags_set.add(tag))
}
})

tags_set.forEach(tag => {
createPage({
path: `/blog/tags/${tag}`,
component: path.resolve("./src/components/default-tag-page-layout.js"),
context: { tag },
})
})

// CREATE PROJECTS
if (fileAbsolutePath.indexOf("/src/project/") !== -1) {
createPage({
path: `/project/${node.slug}`,
component: path.resolve(`./src/components/default-blog-layout.js`),
context: { id: node.id },
})
}
})
}

exports.onCreateNode = ({ node, actions, getNode }) => {
if (node.internal.type === `MarkdownRemark`) {
const value = createFilePath({ node, getNode })
createNodeField({
name: `slug`,
node,
value,
})
}
}
Loading

0 comments on commit d0effd0

Please sign in to comment.