Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Rewrite Gatsby API from gatsby folder to TS #369

Merged
merged 9 commits into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract this to const

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it in one place, so extracting is unnecessary.

// 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