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 1 commit
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
2 changes: 1 addition & 1 deletion gatsby/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { siteMetadata } from "./sitemetadata";
import { plugins } from "./plugins";

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

interface Edge {
node: {
excerpt: string;
html: string;
fields: {
slug: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

slug: string?, at least from what you said to me

date: string;
};
frontmatter: {
title: string;
author: {
name: string;
};
};
};
}

interface QueryType {
query: {
site: {
siteMetadata: SiteMetadata;
};
allMarkdownRemark: {
edges: Edge[];
};
};
}

export const rssFeed = {
resolve: `gatsby-plugin-feed`,
Expand All @@ -17,11 +46,15 @@ export const rssFeed = {
`,
feeds: [
{
serialize: ({ query: { site, allMarkdownRemark } }) => {
serialize: ({ query: { site, allMarkdownRemark } }: QueryType) => {
return allMarkdownRemark.edges
.filter(arg => arg.node.fields.slug.startsWith("/blog/"))
.filter(arg =>
arg.node.fields.slug
? arg.node.fields.slug.startsWith("/blog/")
: false,
)
.map(edge => {
const getAuthor = arg => {
const getAuthor = (arg: Edge) => {
if (
arg.node.frontmatter.author &&
!!arg.node.frontmatter.author.name
Expand All @@ -38,7 +71,7 @@ export const rssFeed = {

return {
...edge.node.frontmatter,
date: edge.node.frontmatter.date,
date: edge.node.fields.date,
url: link,
guid: link,
author: getAuthor(edge),
Expand Down
2 changes: 1 addition & 1 deletion gatsby/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface SiteMetadata extends Record<string, unknown> {
export interface SiteMetadata {
siteUrl: string;
twitterUsername: string;
title: string;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"scripts": {
"start": "npm run clean && npm run develop",
"develop": "gatsby develop --port 5000",
"build": "npm run clear-cache && gatsby build",
"build:prod": "GATSBY_SITE_URL='https://kyma-project.io' gatsby build",
"build": "npm run clean && gatsby build",
"build:prod": "npm run clean && GATSBY_SITE_URL='https://kyma-project.io' gatsby build",
"serve": "gatsby serve",
"serve:out": "gatsby serve -H 0.0.0.0",
"clean": "gatsby clean",
Expand Down