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+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: Hot Chocolate
3+
description: GraphQL Server for .NET core and .NET classic
4+
url: https://github.com/ChilliCream/hotchocolate
5+
github: ChilliCream/hotchocolate
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: regraph
3+
description: A GraphQL client implemented in Clojurescript with support for websockets.
4+
url: https://github.com/oliyh/re-graph/
5+
github: oliyh/re-graph
6+
---
7+
8+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: alumbra
3+
description: A set of reusable GraphQL components for Clojure conforming to the data structures given in [alumbra.spec](https://github.com/alumbra/alumbra.spec).
4+
url: https://github.com/alumbra/alumbra
5+
github: alumbra/alumbra
6+
---
7+
8+
```clojure
9+
(require '[alumbra.core :as alumbra]
10+
'[claro.data :as data])
11+
12+
(def schema
13+
"type Person { name: String!, friends: [Person!]! }
14+
type QueryRoot { person(id: ID!): Person, me: Person! }
15+
schema { query: QueryRoot }")
16+
17+
(defrecord Person [id]
18+
data/Resolvable
19+
(resolve! [_ _]
20+
{:name (str "Person #" id)
21+
:friends (map ->Person (range (inc id) (+ id 3)))}))
22+
23+
(def QueryRoot
24+
{:person (map->Person {})
25+
:me (map->Person {:id 0})})
26+
27+
(def app
28+
(alumbra/handler
29+
{:schema schema
30+
:query QueryRoot}))
31+
32+
(defonce my-graphql-server
33+
(aleph.http/start-server #'app {:port 3000}))
34+
```
35+
36+
```bash
37+
$ curl -XPOST "http://0:3000" -H'Content-Type: application/json' -d'{
38+
"query": "{ me { name, friends { name } } }"
39+
}'
40+
{"data":{"me":{"name":"Person #0","friends":[{"name":"Person #1"},{"name":"Person #2"}]}}}
41+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: graphql-clj
3+
description: A Clojure library that provides a GraphQL implementation.
4+
url: https://github.com/tendant/graphql-clj
5+
github: tendant/graphql-clj
6+
---
7+
8+
Code that executes a hello world GraphQL query with `graphql-clj`:
9+
```clojure
10+
11+
(def schema "type QueryRoot {
12+
hello: String
13+
}")
14+
15+
(defn resolver-fn [type-name field-name]
16+
(get-in {"QueryRoot" {"hello" (fn [context parent & rest]
17+
"Hello world!")}}
18+
[type-name field-name]))
19+
20+
(require '[graphql-clj.executor :as executor])
21+
22+
(executor/execute nil schema resolver-fn "{ hello }")
23+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: lacinia
3+
description: A full implementation of the GraphQL specification that aims to maintain external compliance with the specification.
4+
url: https://github.com/walmartlabs/lacinia
5+
github: walmartlabs/lacinia
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: graphqld
3+
description: A GraphQL implementaiton for the D Programming Language.
4+
url: https://github.com/burner/graphqld
5+
github: burner/graphqld
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: common_graphql_client
3+
description: Elixir GraphQL Client with HTTP and WebSocket support
4+
url: https://github.com/annkissam/common_graphql_client
5+
github: annkissam/common_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: Neuron
3+
description: A GraphQL client for Elixir
4+
url: https://github.com/uesteibar/neuron
5+
github: uesteibar/neuron
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: absinthe
3+
description: GraphQL implementation for Elixir.
4+
url: https://github.com/absinthe-graphql/absinthe
5+
github: absinthe-graphql/absinthe
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-elixir
3+
description: An Elixir implementation of Facebook's GraphQL.
4+
url: https://github.com/graphql-elixir/graphql
5+
github: graphql-elixir/graphql
6+
---
7+
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
name: dillonkearns/elm-graphql
3+
description: Library and command-line code generator to create type-safe Elm code for a GraphQL endpoint.
4+
url: https://github.com/dillonkearns/elm-graphql
5+
github: dillonkearns/elm-graphql
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-erlang
3+
description: GraphQL implementation in Erlang.
4+
url: https://github.com/shopgun/graphql-erlang
5+
github: jlouis/graphql-erlang
6+
---
7+
8+

0 commit comments

Comments
 (0)