mirror of
https://github.com/Unkn0wnCat/KevinK.dev.js.git
synced 2025-05-10 07:26:57 +02:00
Add RSS feed
This commit is contained in:
parent
324d816c0a
commit
9c39458524
4 changed files with 142 additions and 158 deletions
177
gatsby-node.js
177
gatsby-node.js
|
@ -1,6 +1,5 @@
|
|||
/* eslint-disable no-undef */
|
||||
const path = require(`path`);
|
||||
const fs = require("fs");
|
||||
const { paginate } = require("gatsby-awesome-pagination");
|
||||
|
||||
exports.createPages = async ({ actions, graphql, reporter }) => {
|
||||
|
@ -45,27 +44,26 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
|
|||
}
|
||||
|
||||
result.data.allProjectsJson.nodes.forEach((node) => {
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log(
|
||||
"Creating Page: ",
|
||||
`/${node.lang}/projects/${node.urlname}`
|
||||
if (node.lang === "ignoreme") return;
|
||||
|
||||
reporter.info(
|
||||
"Creating Page: " + `/${node.lang}/projects/${node.urlname}`
|
||||
);
|
||||
|
||||
if (node.lang !== "ignoreme")
|
||||
createPage({
|
||||
path: `/${node.lang}/projects/${node.urlname}`,
|
||||
component: projectTemplate,
|
||||
context: {
|
||||
lang: node.lang,
|
||||
urlname: node.urlname,
|
||||
},
|
||||
});
|
||||
createPage({
|
||||
path: `/${node.lang}/projects/${node.urlname}`,
|
||||
component: projectTemplate,
|
||||
context: {
|
||||
lang: node.lang,
|
||||
urlname: node.urlname,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const blogListingTemplate = path.resolve(`src/templates/blogListing.js`);
|
||||
const blogTemplate = path.resolve(`src/templates/blogPost.js`);
|
||||
|
||||
console.log("Creating blog listing...");
|
||||
reporter.info("Creating blog listings...");
|
||||
|
||||
["en", "de"].forEach((lang) =>
|
||||
paginate({
|
||||
|
@ -92,7 +90,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
|
|||
) {
|
||||
processedSections.push(node.childMdx.frontmatter.section);
|
||||
|
||||
console.log(
|
||||
reporter.info(
|
||||
"Creating section listing for " +
|
||||
node.childMdx.frontmatter.section +
|
||||
"..."
|
||||
|
@ -117,12 +115,11 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
|
|||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
console.log(
|
||||
"Creating Page: ",
|
||||
`/${node.childMdx.frontmatter.language}/blog/${
|
||||
node.childMdx.frontmatter.section ?? "blog"
|
||||
}/${node.childMdx.frontmatter.url}`
|
||||
reporter.info(
|
||||
"Creating Page: " +
|
||||
`/${node.childMdx.frontmatter.language}/blog/${
|
||||
node.childMdx.frontmatter.section ?? "blog"
|
||||
}/${node.childMdx.frontmatter.url}`
|
||||
);
|
||||
|
||||
createPage({
|
||||
|
@ -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}`,
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue