Skip to content

Commit 4f8fc83

Browse files
committed
Use frontmatter instead of JSON file
1 parent 88d9021 commit 4f8fc83

File tree

122 files changed

+1736
-898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+1736
-898
lines changed

data/code.json

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

gatsby-node.js

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const path = require("path")
2-
const { readFileSync } = require("fs")
32
const sortLibs = require("./scripts/sort-libraries")
3+
const globby = require('globby');
4+
const frontmatterParser = require('parser-front-matter');
5+
const { readFile } = require("fs-extra");
6+
const { promisify } = require('util');
47

58
exports.onCreatePage = async ({ page, actions }) => {
69
const { createPage, deletePage } = actions
@@ -10,27 +13,83 @@ exports.onCreatePage = async ({ page, actions }) => {
1013
sourcePath: path.relative(__dirname, page.componentPath),
1114
}
1215
if (page.path === "/code" || page.path === "/code/") {
13-
const codeData = JSON.parse(readFileSync("./data/code.json", "utf8"));
14-
const languageList = [];
15-
let sortedTools = [];
16+
const markdownFilePaths = await globby('src/content/code/**/*.md');
17+
const codeData = {}
18+
const slugMap = require('./src/content/code/slug-map.json');
19+
const parse$ = promisify(frontmatterParser.parse);
20+
await Promise.all(markdownFilePaths.map(async markdownFilePath => {
21+
22+
const markdownFileContent = await readFile(markdownFilePath, "utf-8")
23+
let {
24+
data: { name, description, url, github, npm, gem },
25+
content: howto,
26+
} = await parse$(markdownFileContent, undefined)
27+
howto = howto.trim();
28+
const pathArr = markdownFilePath.split("/")
29+
if (markdownFilePath.includes("language-support")) {
30+
const languageSupportDirIndex = pathArr.indexOf("language-support")
31+
const languageNameSlugIndex = languageSupportDirIndex + 1
32+
const languageNameSlug = pathArr[languageNameSlugIndex]
33+
const languageName = slugMap[languageNameSlug]
34+
codeData.Languages = codeData.Languages || {}
35+
codeData.Languages[languageName] =
36+
codeData.Languages[languageName] || {}
37+
38+
const categoryNameSlugIndex = languageSupportDirIndex + 2
39+
const categoryNameSlug = pathArr[categoryNameSlugIndex]
40+
const categoryName = slugMap[categoryNameSlug]
41+
codeData.Languages[languageName][categoryName] =
42+
codeData.Languages[languageName][categoryName] || []
43+
codeData.Languages[languageName][categoryName].push({
44+
name,
45+
description,
46+
howto,
47+
url,
48+
github,
49+
npm,
50+
gem,
51+
sourcePath: markdownFilePath,
52+
})
53+
} else {
54+
const codeDirIndex = pathArr.indexOf("code")
55+
const categoryNameSlugIndex = codeDirIndex + 1
56+
const categoryNameSlug = pathArr[categoryNameSlugIndex]
57+
const categoryName = slugMap[categoryNameSlug]
58+
codeData[categoryName] = codeData[categoryName] || []
59+
codeData[categoryName].push({
60+
name,
61+
description,
62+
howto,
63+
url,
64+
github,
65+
npm,
66+
gem,
67+
sourcePath: markdownFilePath,
68+
})
69+
}
70+
}))
71+
const languageList = []
72+
let sortedTools = []
1673
await Promise.all([
17-
Promise.all(Object.keys(codeData.Libraries).map(async languageName => {
18-
const libraryCategoryMap = codeData.Libraries[languageName];
19-
let languageTotalStars = 0;
20-
await Promise.all(
21-
Object.keys(libraryCategoryMap).map(async libraryCategoryName => {
22-
const libraries = libraryCategoryMap[libraryCategoryName]
23-
const { sortedLibs, totalStars } = await sortLibs(libraries)
24-
libraryCategoryMap[libraryCategoryName] = sortedLibs;
25-
languageTotalStars += totalStars || 0
74+
Promise.all(
75+
Object.keys(codeData.Languages).map(async languageName => {
76+
const libraryCategoryMap = codeData.Languages[languageName]
77+
let languageTotalStars = 0
78+
await Promise.all(
79+
Object.keys(libraryCategoryMap).map(async libraryCategoryName => {
80+
const libraries = libraryCategoryMap[libraryCategoryName]
81+
const { sortedLibs, totalStars } = await sortLibs(libraries)
82+
libraryCategoryMap[libraryCategoryName] = sortedLibs
83+
languageTotalStars += totalStars || 0
84+
})
85+
)
86+
languageList.push({
87+
name: languageName,
88+
totalStars: languageTotalStars,
89+
categoryMap: libraryCategoryMap,
2690
})
27-
)
28-
languageList.push({
29-
name: languageName,
30-
totalStars: languageTotalStars,
31-
categoryMap: libraryCategoryMap,
3291
})
33-
})),
92+
),
3493
sortLibs(codeData.Tools).then(({ sortedLibs }) => {
3594
sortedTools = sortedLibs
3695
}),
@@ -41,7 +100,7 @@ exports.onCreatePage = async ({ page, actions }) => {
41100
otherLibraries: {
42101
Services: codeData.Services,
43102
Tools: sortedTools,
44-
'More Stuff': codeData['More Stuff']
103+
"More Stuff": codeData["More Stuff"],
45104
},
46105
languageList: languageList.sort((a, b) => {
47106
if (a.totalStars > b.totalStars) {
@@ -111,7 +170,10 @@ exports.createPages = async ({ graphql, actions }) => {
111170
parent: { relativeDirectory, sourceInstanceName },
112171
} = node
113172

114-
if (sourceInstanceName !== "content") {
173+
if (
174+
sourceInstanceName !== "content" ||
175+
relativeDirectory.includes("code")
176+
) {
115177
return
116178
}
117179

@@ -223,7 +285,7 @@ exports.createPages = async ({ graphql, actions }) => {
223285
categoriesMap[currentCategory.name] = currentCategory
224286
}
225287

226-
sideBardata[folder] = Object.values(categoriesMap);
288+
sideBardata[folder] = Object.values(categoriesMap)
227289
})
228290
)
229291

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
"gatsby-plugin-webfonts": "1.1.3",
2525
"gatsby-source-filesystem": "2.4.0",
2626
"gatsby-transformer-remark": "2.9.0",
27+
"globby": "11.0.1",
2728
"graphql": "15.4.0",
2829
"marked": "1.2.2",
2930
"numbro": "2.3.2",
31+
"parser-front-matter": "1.6.4",
3032
"prism-react-renderer": "1.1.1",
3133
"prismjs": "1.22.0",
3234
"react": "17.0.1",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: libgraphqlparser
3+
description: A GraphQL query language parser in C++ with C and C++ APIs.
4+
url: https://github.com/graphql/libgraphqlparser
5+
github: graphql/libgraphqlparser
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: GraphQL.Client
3+
description: A GraphQL Client for .NET.
4+
url: https://github.com/graphql-dotnet/graphql-client
5+
github: graphql-dotnet/graphql-client
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: graphql-net-client
3+
description: Basic example GraphQL client for .NET.
4+
url: https://github.com/bkniffler/graphql-net-client
5+
github: bkniffler/graphql-net-client
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: SAHB.GraphQLClient
3+
description: GraphQL client which supports generating queries from C# classes
4+
url: https://github.com/sahb1239/SAHB.GraphQLClient
5+
github: sahb1239/SAHB.GraphQLClient
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: Entity GraphQL
3+
description: .NET Core GraphQL library. Compiles to IQueryable to easily expose a schema from an existing data model (E.g. from an Entity Framework data model)
4+
url: https://github.com/lukemurray/EntityGraphQL
5+
github: lukemurray/EntityGraphQL
6+
---
7+
8+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: graphql-dotnet
3+
description: GraphQL for .NET
4+
url: https://github.com/graphql-dotnet/graphql-dotnet
5+
github: graphql-dotnet/graphql-dotnet
6+
---
7+
8+
```csharp
9+
using System;
10+
using System.Threading.Tasks;
11+
using GraphQL;
12+
using GraphQL.Types;
13+
using GraphQL.SystemTextJson; // First add PackageReference to GraphQL.SystemTextJson
14+
15+
public class Program
16+
{
17+
public static async Task Main(string[] args)
18+
{
19+
var schema = Schema.For(@"
20+
type Query {
21+
hello: String
22+
}
23+
");
24+
25+
var json = await schema.ExecuteAsync(_ =>
26+
{
27+
_.Query = "{ hello }";
28+
_.Root = new { Hello = "Hello World!" };
29+
});
30+
31+
Console.WriteLine(json);
32+
}
33+
}
34+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: graphql-net
3+
description: Convert GraphQL to IQueryable
4+
url: https://github.com/ckimes89/graphql-net
5+
github: chkimes/graphql-net
6+
---
7+
8+

0 commit comments

Comments
 (0)