Skip to content

Commit c92c199

Browse files
committed
Read blog articles, remove redundant JSON files
1 parent 16c1457 commit c92c199

25 files changed

+73
-121
lines changed

src/pages/community/resources/blogs-and-newsletters.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Here are a list of notable blog posts to help you better understand GraphQL:
3535
- [Your First GraphQL Server](https://medium.com/the-graphqlhub/your-first-graphql-server-3c766ab4f0a2#.ovn0y19k4) - Clay Allsopp
3636
- [Tutorial: Kick start a JS API with Apollo-server, Dataloader and Knex](https://bamtech.gitbook.io/dev-standards/backend/graphql-js/getting-started-with-apollo-server-dataloader-knex.mo) - Thomas Pucci
3737
- [Tutorial: How to Build a GraphQL Server](https://medium.com/apollo-stack/tutorial-building-a-graphql-server-cddaa023c035#.bu6sdnst4) - Jonas Helfer
38-
- [Designing Powerful APIs with GraphQL Query Parameters](https://www.graph.cool/docs/tutorials/designing-powerful-apis-with-graphql-query-parameters-aing7uech3/) - Johannes Schickling
3938
- [GraphQL and the amazing Apollo Client](https://medium.com/google-developer-experts/graphql-and-the-amazing-apollo-client-fe57e162a70c) - Gerard Sans
4039
- [GraphQL Server Basics (Part I): The Schema](https://www.prisma.io/blog/graphql-server-basics-the-schema-ac5e2950214e) - Nikolas Burk
4140
- [GraphQL Server Basics (Part II): The Network Layer](https://www.prisma.io/blog/graphql-server-basics-the-network-layer-51d97d21861) - Nikolas Burk

src/resources/data.ts

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { readFile } from "node:fs/promises"
44
import { cache } from "react"
55
import matter from "gray-matter"
66

7-
import { ResourceMetadata, type ResourceTag } from "./types"
7+
import { ResourceMetadata, type ResourceTag, topics } from "./types"
88

99
const dataGlob = "src/resources/data/*.json"
1010
const codeGlob = "src/code/**/*.md"
11+
const blogGlob = "src/pages/blog/**/*.mdx"
1112

1213
export const readResources = cache(async () => {
1314
const resources: ResourceMetadata[] = []
@@ -18,6 +19,67 @@ export const readResources = cache(async () => {
1819
resources.push(ResourceMetadata.assert(parsed))
1920
}
2021

22+
for await (const file of glob(blogGlob)) {
23+
const raw = await readFile(file, "utf8")
24+
const { data, content } = matter(raw)
25+
26+
const title: string | undefined = data.title
27+
if (!title) continue
28+
29+
const slug = blogSlug(file)
30+
31+
const bodyLines = content
32+
.split(/\r?\n/)
33+
.map(line => line.trim())
34+
.map(line =>
35+
line
36+
.replace(/!\[[^\]]*\]\([^)]+\)/g, "")
37+
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
38+
.replace(/`+/g, "")
39+
.replace(/[*_~]+/g, "")
40+
.replace(/^#+\s*/, "")
41+
.replace(/<\/?[^>]+>/g, "")
42+
.trim(),
43+
)
44+
.filter(line => line.length > 0)
45+
46+
const excerpt = bodyLines.slice(0, 2).join(" ")
47+
48+
const description =
49+
typeof data.description === "string" && data.description.length > 0
50+
? data.description
51+
: excerpt || undefined
52+
53+
const topicsFromFrontmatter: ResourceTag[] = Array.isArray(data.topics)
54+
? data.topics.filter((tag): tag is ResourceTag =>
55+
topics.includes(tag as (typeof topics)[number]),
56+
)
57+
: []
58+
59+
const topicTagsFromTags: ResourceTag[] = Array.isArray(data.tags)
60+
? data.tags.filter((tag): tag is ResourceTag =>
61+
topics.includes(tag as (typeof topics)[number]),
62+
)
63+
: []
64+
65+
const tags: ResourceTag[] = [
66+
"blog",
67+
...topicsFromFrontmatter,
68+
...topicTagsFromTags,
69+
]
70+
71+
resources.push(
72+
ResourceMetadata.assert({
73+
title,
74+
url: slug,
75+
author: data.byline,
76+
description,
77+
kind: "blog",
78+
tags,
79+
}),
80+
)
81+
}
82+
2183
for await (const file of glob(codeGlob)) {
2284
const raw = await readFile(file, "utf8")
2385
const { data } = matter(raw)
@@ -53,3 +115,13 @@ export async function getResourcesByTag(tag: ResourceTag) {
53115
const resources = await readResources()
54116
return resources.filter(resource => resource.tags.includes(tag))
55117
}
118+
119+
function blogSlug(file: string) {
120+
const relative = path.relative("src/pages", file)
121+
const withoutExt = relative.replace(/\.mdx$/, "")
122+
const normalized = withoutExt.split(path.sep).join("/")
123+
const clean = normalized.endsWith("/index")
124+
? normalized.slice(0, -"index".length - 1)
125+
: normalized
126+
return `/${clean}`
127+
}

src/resources/data/announcing-graphql-js-org.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/resources/data/announcing-new-graphql-website.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/resources/data/announcing-the-composite-schemas-working-group.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/resources/data/generating-type-safe-clients-using-code-generation.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/resources/data/graphiql-4-1-is-released.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/resources/data/graphiql-5-released-press-f1.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/resources/data/graphql-a-data-query-language.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/resources/data/graphql-custom-scalar-specifications.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)