Add RSS feed

This commit is contained in:
Kevin Kandlbinder 2021-11-07 14:42:34 +00:00 committed by GitHub
parent 324d816c0a
commit 9c39458524
4 changed files with 142 additions and 158 deletions

View file

@ -139,5 +139,89 @@ module.exports = {
generateMatchPathRewrites: false, generateMatchPathRewrites: false,
}, },
}, },
{
resolve: `gatsby-plugin-feed`,
options: {
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize: ({ query: { site, blog } }) => {
return blog.nodes.map((node) => {
if (!node.childMdx) return null;
return {
title: node.childMdx.frontmatter.title,
description: node.childMdx.excerpt,
date: node.childMdx.frontmatter.date,
url:
site.siteMetadata.siteUrl +
`/${
node.childMdx.frontmatter.language
}/blog/${
node.childMdx.frontmatter.section
? node.childMdx.frontmatter
.section + "/"
: ""
}${
node.childMdx.frontmatter.published
}/${node.childMdx.frontmatter.url}`,
guid:
site.siteMetadata.siteUrl +
`/${
node.childMdx.frontmatter.language
}/blog/${
node.childMdx.frontmatter.section
? node.childMdx.frontmatter
.section + "/"
: ""
}${
node.childMdx.frontmatter.published
}/${node.childMdx.frontmatter.url}`,
section: node.childMdx.frontmatter.section,
};
});
},
query: `
{
blog: allFile(
filter: { sourceInstanceName: { eq: "blogContent" } }
) {
nodes {
childMdx {
id
body
excerpt
frontmatter {
platform
tags
title
url
section
language
published(formatString: "YYYY/MM")
date: published
}
}
}
}
}
`,
output: "/blog/feed.xml",
title: extConfig.siteName + " Blog",
},
],
},
},
], ],
}; };

View file

@ -1,6 +1,5 @@
/* eslint-disable no-undef */ /* eslint-disable no-undef */
const path = require(`path`); const path = require(`path`);
const fs = require("fs");
const { paginate } = require("gatsby-awesome-pagination"); const { paginate } = require("gatsby-awesome-pagination");
exports.createPages = async ({ actions, graphql, reporter }) => { exports.createPages = async ({ actions, graphql, reporter }) => {
@ -45,13 +44,12 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
} }
result.data.allProjectsJson.nodes.forEach((node) => { result.data.allProjectsJson.nodes.forEach((node) => {
// eslint-disable-next-line no-undef if (node.lang === "ignoreme") return;
console.log(
"Creating Page: ", reporter.info(
`/${node.lang}/projects/${node.urlname}` "Creating Page: " + `/${node.lang}/projects/${node.urlname}`
); );
if (node.lang !== "ignoreme")
createPage({ createPage({
path: `/${node.lang}/projects/${node.urlname}`, path: `/${node.lang}/projects/${node.urlname}`,
component: projectTemplate, component: projectTemplate,
@ -65,7 +63,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
const blogListingTemplate = path.resolve(`src/templates/blogListing.js`); const blogListingTemplate = path.resolve(`src/templates/blogListing.js`);
const blogTemplate = path.resolve(`src/templates/blogPost.js`); const blogTemplate = path.resolve(`src/templates/blogPost.js`);
console.log("Creating blog listing..."); reporter.info("Creating blog listings...");
["en", "de"].forEach((lang) => ["en", "de"].forEach((lang) =>
paginate({ paginate({
@ -92,7 +90,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
) { ) {
processedSections.push(node.childMdx.frontmatter.section); processedSections.push(node.childMdx.frontmatter.section);
console.log( reporter.info(
"Creating section listing for " + "Creating section listing for " +
node.childMdx.frontmatter.section + node.childMdx.frontmatter.section +
"..." "..."
@ -117,9 +115,8 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
); );
} }
// eslint-disable-next-line no-undef reporter.info(
console.log( "Creating Page: " +
"Creating Page: ",
`/${node.childMdx.frontmatter.language}/blog/${ `/${node.childMdx.frontmatter.language}/blog/${
node.childMdx.frontmatter.section ?? "blog" node.childMdx.frontmatter.section ?? "blog"
}/${node.childMdx.frontmatter.url}` }/${node.childMdx.frontmatter.url}`
@ -179,139 +176,3 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
}); });
}); });
}; };
const config = require("./config.js");
exports.onPostBuild = async ({ graphql, reporter }) => {
console.log("Building static api...");
const apiPrefix = "./public/api";
if (!fs.existsSync(apiPrefix)) fs.mkdirSync(apiPrefix);
fs.writeFileSync(
`${apiPrefix}.json`,
JSON.stringify({
success: true,
endpoints: {
projects: [
{
name: "Projects Overview",
description:
"Returns overview of all available projects",
path: "/api/projects.json",
},
{
name: "Projects Overview for Language",
description:
"Returns overview of all available projects in a specified language",
path: "/api/projects/:lang.json",
},
{
name: "Get specific Project",
description:
"Returns specific project in specified language",
path: "/api/projects/:lang/:slug.json",
},
],
},
})
);
const projectsPrefix = apiPrefix + "/projects";
if (!fs.existsSync(projectsPrefix)) fs.mkdirSync(projectsPrefix);
await graphql(`
query {
allProjectsJson {
nodes {
urlname
shortDescription
name
links {
github
website
}
lang
image {
publicURL
}
featured
}
}
}
`).then((res) => {
if (res.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
let projects = res.data.allProjectsJson.nodes.filter((project) => {
return project.lang !== "ignoreme";
});
fs.writeFileSync(
`${projectsPrefix}.json`,
JSON.stringify({
success: true,
projects: projects.map((project) => {
return {
slug: project.urlname,
lang: project.lang,
api: `/api/projects/${project.lang}/${project.urlname}.json`,
};
}),
})
);
config.languages.forEach((lang) => {
if (!fs.existsSync(`${projectsPrefix}/${lang}`))
fs.mkdirSync(`${projectsPrefix}/${lang}`);
fs.writeFileSync(
`${projectsPrefix}/${lang}.json`,
JSON.stringify({
success: true,
projects: projects
.filter((project) => {
return project.lang == lang;
})
.map((project) => {
return {
slug: project.urlname,
lang: project.lang,
api: `/api/projects/${project.lang}/${project.urlname}.json`,
};
}),
})
);
});
projects.forEach((project) => {
fs.writeFileSync(
`${projectsPrefix}/${project.lang}/${project.urlname}.json`,
JSON.stringify({
success: true,
project: {
slug: project.urlname,
lang: project.lang,
name: project.name,
shortDescription: project.shortDescription,
longDescription: project.longDescription,
links:
project.links !== null
? {
github: project.links.github,
website: project.links.website,
}
: null,
image: project.image.publicURL,
featured: project.featured,
frontend: `/${project.lang}/projects/${project.urlname}`,
},
})
);
});
});
};

View file

@ -30,6 +30,7 @@
"gatsby-awesome-pagination": "0.3.8", "gatsby-awesome-pagination": "0.3.8",
"gatsby-cli": "4.1.0", "gatsby-cli": "4.1.0",
"gatsby-plugin-asset-path": "3.0.4", "gatsby-plugin-asset-path": "3.0.4",
"gatsby-plugin-feed": "^4.1.0",
"gatsby-plugin-image": "2.1.0", "gatsby-plugin-image": "2.1.0",
"gatsby-plugin-manifest": "4.1.0", "gatsby-plugin-manifest": "4.1.0",
"gatsby-plugin-mdx": "3.1.0", "gatsby-plugin-mdx": "3.1.0",

View file

@ -6043,6 +6043,19 @@ gatsby-plugin-eslint@4.0.1:
dependencies: dependencies:
webpack-merge "^5.8.0" webpack-merge "^5.8.0"
gatsby-plugin-feed@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/gatsby-plugin-feed/-/gatsby-plugin-feed-4.1.0.tgz#b560fa447935144bec2bdf4c874cdff62b9bf16f"
integrity sha512-6bJ+g+UbOBiaIHj1jFFHewaS3SDLBaldjwoZmslYfyoxKSXzW3Cl9S0xyEFwFbiXqjUbDJJeeifIjbsHauAKQQ==
dependencies:
"@babel/runtime" "^7.15.4"
"@hapi/joi" "^15.1.1"
common-tags "^1.8.0"
fs-extra "^10.0.0"
gatsby-plugin-utils "^2.1.0"
lodash.merge "^4.6.2"
rss "^1.2.2"
gatsby-plugin-image@2.1.0: gatsby-plugin-image@2.1.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/gatsby-plugin-image/-/gatsby-plugin-image-2.1.0.tgz#71f3568ce7558a84fbcf06ca5ea9b00a1cd9d41d" resolved "https://registry.yarnpkg.com/gatsby-plugin-image/-/gatsby-plugin-image-2.1.0.tgz#71f3568ce7558a84fbcf06ca5ea9b00a1cd9d41d"
@ -8952,6 +8965,18 @@ mime-db@1.49.0:
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.50.0.tgz#abd4ac94e98d3c0e185016c67ab45d5fde40c11f" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.50.0.tgz#abd4ac94e98d3c0e185016c67ab45d5fde40c11f"
integrity sha512-9tMZCDlYHqeERXEHO9f/hKfNXhre5dK2eE/krIvUjZbS2KPcqGDfNShIWS1uW9XOTKQKqK6qbeOci18rbfW77A== integrity sha512-9tMZCDlYHqeERXEHO9f/hKfNXhre5dK2eE/krIvUjZbS2KPcqGDfNShIWS1uW9XOTKQKqK6qbeOci18rbfW77A==
mime-db@~1.25.0:
version "1.25.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.25.0.tgz#c18dbd7c73a5dbf6f44a024dc0d165a1e7b1c392"
integrity sha1-wY29fHOl2/b0SgJNwNFloeexw5I=
mime-types@2.1.13:
version "2.1.13"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.13.tgz#e07aaa9c6c6b9a7ca3012c69003ad25a39e92a88"
integrity sha1-4HqqnGxrmnyjASxpADrSWjnpKog=
dependencies:
mime-db "~1.25.0"
mime-types@^2.1.12, mime-types@^2.1.27, mime-types@^2.1.30, mime-types@~2.1.24: mime-types@^2.1.12, mime-types@^2.1.27, mime-types@^2.1.30, mime-types@~2.1.24:
version "2.1.32" version "2.1.32"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.32.tgz#1d00e89e7de7fe02008db61001d9e02852670fd5" resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.32.tgz#1d00e89e7de7fe02008db61001d9e02852670fd5"
@ -11238,6 +11263,14 @@ rimraf@^3.0.0, rimraf@^3.0.2:
dependencies: dependencies:
glob "^7.1.3" glob "^7.1.3"
rss@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/rss/-/rss-1.2.2.tgz#50a1698876138133a74f9a05d2bdc8db8d27a921"
integrity sha1-UKFpiHYTgTOnT5oF0r3I240nqSE=
dependencies:
mime-types "2.1.13"
xml "1.0.1"
run-async@^2.4.0: run-async@^2.4.0:
version "2.4.1" version "2.4.1"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455" resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
@ -13459,6 +13492,11 @@ xml2js@^0.4.5:
sax ">=0.6.0" sax ">=0.6.0"
xmlbuilder "~11.0.0" xmlbuilder "~11.0.0"
xml@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=
xmlbuilder@~11.0.0: xmlbuilder@~11.0.0:
version "11.0.1" version "11.0.1"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"