diff options
author | 2024-04-30 03:08:51 +0100 | |
---|---|---|
committer | 2024-04-30 03:08:51 +0100 | |
commit | d8fcc5bf2d8c323c4a5c0f900088b595cbe38b90 (patch) | |
tree | bc9706f92c470ef54a81f4ff933c407728a65393 | |
parent | Add packages for JSON outputs (diff) |
Add JSON feed output
-rw-r--r-- | gatsby-config.ts | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/gatsby-config.ts b/gatsby-config.ts index c15a445..6b032e6 100644 --- a/gatsby-config.ts +++ b/gatsby-config.ts @@ -1,9 +1,11 @@ import type { GatsbyConfig } from "gatsby"; +const siteURL = "https://ops.pydis.wtf"; + const config: GatsbyConfig = { siteMetadata: { title: `PyDis Ops`, - siteUrl: `https://ops.pydis.wtf` + siteUrl: siteURL, }, // More easily incorporate content into your pages through automatic TypeScript type generation and better GraphQL IntelliSense. // If you use VSCode you can also use the GraphQL plugin @@ -43,7 +45,53 @@ const config: GatsbyConfig = { options: { path: `./data/`, }, - },], + }, { + resolve: `gatsby-plugin-json-output`, + options: { + siteUrl: siteURL, + graphQLQuery: ` + { + services: allServicesYaml { + nodes { + slug + name + description + url + tags + } + + tags: distinct(field: {tags: SELECT}) + } + + images: allFile(filter: {sourceInstanceName: {eq: "service_images"}}) { + nodes { + name + childImageSharp { + resize(height: 256, quality: 100) { + src + } + } + } + } + } + `, + serializeFeed: ({ data }: { data: any }) => { + const serviceImageMap: { [key: string]: string } = {}; + data.images.nodes.forEach((node: any) => { + serviceImageMap[node.name] = node.childImageSharp.resize.src; + }); + + const services = data.services.nodes.map((service: any) => ({ + ...service, + image: serviceImageMap[service.slug] ? serviceImageMap[service.slug] : serviceImageMap["unknown"], + })); + + return services; + }, + feedFilename: "services", + nodesPerFeedFile: 100, + } + }], headers: [ { source: "/*", |