Skip to content

Commit

Permalink
Rewrite Gatsby API from gatsby folder to TS (kyma-project#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu authored and m00g3n committed Oct 8, 2019
1 parent 5988a69 commit a7d770e
Show file tree
Hide file tree
Showing 52 changed files with 1,419 additions and 664 deletions.
175 changes: 2 additions & 173 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,174 +1,3 @@
const siteMetadata = require("./config.json").siteMetadata;
const { config } = require("./gatsby");

module.exports = {
siteMetadata,
plugins: [
"gatsby-plugin-react-helmet",
{
resolve: "gatsby-plugin-styled-components",
options: {
ssr: false,
displayName: true,
},
},
"gatsby-plugin-lodash",
"gatsby-plugin-typescript",
{
resolve: "gatsby-source-filesystem",
options: {
name: "content",
path: `${__dirname}/content/`,
},
},
{
resolve: "gatsby-plugin-copy-files",
options: {
source: `${__dirname}/content`,
destination: "/assets",
extensions: ["jpeg", "jpg", "gif", "png", "svg", "json", "yaml", "yml"],
// add regex possibility
excludeDirs: ["i18n"],
excludeFiles: [
"docs/versions.json",
"docs.config.json",
"manifest.yaml",
"events.yaml",
],
},
},
{
resolve: "gatsby-plugin-anchor-behavior",
options: {
paths: {
"/docs/": {
defaultOffset: 16,
mobileOffset: 74,
},
"/roadmap/": {
defaultOffset: 0,
mobileOffset: 0,
},
},
defaultOffset: 16,
mobileOffset: 74,
mobileOffsetInclude: ["/docs"],
},
},
"gatsby-plugin-banner-slides-yml",
"gatsby-plugin-early-adopters-yml",
{
resolve: "gatsby-transformer-remark",
options: {
excerpt_separator: `<!-- overview -->`,
},
},
{
resolve: "gatsby-plugin-manifest",
options: {
name: "Kyma",
short_name: "Kyma",
start_url: "/",
background_color: "#fff",
theme_color: "#0073e6",
display: "standalone",
icon: "static/android-chrome-512x512.png",
},
},
{
resolve: `gatsby-plugin-gtag`,
options: {
trackingId: "UA-122665881-1",
head: true,
anonymize: true,
},
},
`gatsby-plugin-sitemap`,
`gatsby-plugin-netlify`,
`gatsby-plugin-netlify-cache`,
{
resolve: `gatsby-plugin-env-variables`,
options: {
whitelist: ["GOOGLE_CSE", "ALGOLIA_API_KEY", "ALGOLIA_INDEX_NAME"],
},
},
{
resolve: `gatsby-plugin-feed`,
options: {
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize: ({ query: { site, allMarkdownRemark } }) => {
return allMarkdownRemark.edges
.filter(arg => arg.node.fields.slug.startsWith("/blog/"))
.map(edge => {
const getAuthor = arg => {
if (
arg.node.frontmatter.author &&
!!arg.node.frontmatter.author.name
) {
return arg.node.frontmatter.author.name;
}
return null;
};

const host = site.siteMetadata.siteUrl;
const link = `${
host.endsWith("/") ? host : host + "/"
}${edge.node.fields.slug.slice(1)}`;

return {
...edge.node.frontmatter,
date: edge.node.frontmatter.date,
url: link,
guid: link,
author: getAuthor(edge),
description: edge.node.excerpt,
custom_elements: [{ "content:encoded": edge.node.html }],
};
});
},
query: `
{
allMarkdownRemark(sort: {order: DESC, fields: [fields___date]}) {
edges {
node {
excerpt
html
fields {
slug
date
}
frontmatter {
title
author {
name
}
}
}
}
}
}
`,
output: `${
siteMetadata.feedUrl.startsWith("/")
? siteMetadata.feedUrl
: "/" + siteMetadata.feedUrl
}`,
},
],
},
},
],
pathPrefix: "/website",
};
module.exports = config;
17 changes: 13 additions & 4 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
exports.onCreateWebpackConfig = require("./gatsby/onCreateWebpackConfig");
exports.createPages = require("./gatsby/createPages");
exports.onCreateNode = require("./gatsby/onCreateNode");
exports.onCreatePage = require("./gatsby/onCreatePage");
const {
onCreateWebpackConfig,
createPages,
onCreateNode,
onCreatePage,
} = require("./gatsby");

module.exports = {
onCreateWebpackConfig,
createPages,
onCreateNode,
onCreatePage,
};
9 changes: 9 additions & 0 deletions gatsby/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { GatsbyConfig } from "gatsby";
import { siteMetadata } from "./sitemetadata";
import { plugins } from "./plugins";

export const config: GatsbyConfig = {
siteMetadata: siteMetadata as Record<string, any>,
plugins,
pathPrefix: "/website",
};
94 changes: 94 additions & 0 deletions gatsby/config/plugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { rssFeed } from "./rss-feed";
import { Plugins } from "./types";

export const plugins: Plugins = [
"gatsby-plugin-react-helmet",
{
resolve: "gatsby-plugin-styled-components",
options: {
ssr: false,
displayName: true,
},
},
"gatsby-plugin-lodash",
"gatsby-plugin-typescript",
{
resolve: "gatsby-source-filesystem",
options: {
name: "content",
path: `${__dirname}/../../content/`,
},
},
{
resolve: "gatsby-plugin-copy-files",
options: {
source: `${__dirname}/../../content`,
destination: "/assets",
extensions: ["jpeg", "jpg", "gif", "png", "svg", "json", "yaml", "yml"],
// add regex possibility
excludeDirs: ["i18n"],
excludeFiles: [
"docs/versions.json",
"docs.config.json",
"manifest.yaml",
"events.yaml",
],
},
},
{
resolve: "gatsby-plugin-anchor-behavior",
options: {
paths: {
"/docs/": {
defaultOffset: 16,
mobileOffset: 74,
},
"/roadmap/": {
defaultOffset: 0,
mobileOffset: 0,
},
},
defaultOffset: 16,
mobileOffset: 74,
mobileOffsetInclude: ["/docs"],
},
},
"gatsby-plugin-banner-slides-yml",
"gatsby-plugin-early-adopters-yml",
{
resolve: "gatsby-transformer-remark",
options: {
excerpt_separator: `<!-- overview -->`,
},
},
{
resolve: "gatsby-plugin-manifest",
options: {
name: "Kyma",
short_name: "Kyma",
start_url: "/",
background_color: "#fff",
theme_color: "#0073e6",
display: "standalone",
icon: "static/android-chrome-512x512.png",
},
},
{
resolve: `gatsby-plugin-gtag`,
options: {
trackingId: "UA-122665881-1",
head: true,
anonymize: true,
},
},
`gatsby-plugin-sitemap`,
`gatsby-plugin-netlify`,
`gatsby-plugin-netlify-cache`,
{
resolve: `gatsby-plugin-env-variables`,
options: {
whitelist: ["GOOGLE_CSE", "ALGOLIA_API_KEY", "ALGOLIA_INDEX_NAME"],
},
},
rssFeed,
];
Loading

0 comments on commit a7d770e

Please sign in to comment.