Skip to content

Commit 409a7cd

Browse files
authored
Merge pull request #53 from codewars/replace-category-with-kind
Replace Category with Kind
2 parents f40645c + c5d6830 commit 409a7cd

File tree

20 files changed

+182
-183
lines changed

20 files changed

+182
-183
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@
66

77
Documents are classified with the following:
88

9-
- `Category` (`category`): Document belongs to a category
10-
- `Tag` (`tags`): Document can have multiple tags
9+
- `Kind` (`kind`): By kind of documentation (`recipe`, `reference`, `tutorial`, etc.) See [kinds.yml].
10+
- `Tag` (`tags`): By tags associated with the documentation. See [tags.yml].
1111
- `Language` (`languages`): A special kind of `Tag` that is used to collect documents to show on the language page
1212

1313
## Routes
1414

15+
- `/tutorials/`: All docs with kind `tutorial`
16+
- `/recipes/`: All docs with kind `recipe`
17+
- `/references/`: All docs with kind `reference`
18+
- `/tags/`: List of all tags
19+
- `/tags/:id`: List of docs with tag `id`
1520
- `/languages/`: List of supported languages
1621
- `/languages/:id`: Show language information
17-
- Sidebar lists all pages referencing the language, grouped by `category`
18-
- `/tags/`: List of tags
19-
- `/tags/:id`: List of pages with tag `id`
20-
- `/categories/`: List of documentation categories
21-
- `/categories/:id`: List of pages in the category
22+
- Sidebar lists all pages referencing the language, grouped by `kind`
2223

2324
Markdown files matching `content/**/*.md` generates matching routes. For example, `content/foo/bar.md` generates `/foo/bar/`.
2425

2526
---
2627

2728
Built with [Gridsome](https://gridsome.org/) using [docc](https://github.com/mrcrmn/docc) starter.
29+
30+
[kinds.yml]: ./data/kinds.yml
31+
[tags.yml]: ./data/tags.yml

content/docs/deploying.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: ""
3-
category: docs
3+
kind: reference
44
sidebar: "docs"
55
prev: "/docs/writing-content/"
66
next: "/docs/settings/"

content/docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: ""
3-
category: docs
3+
kind: reference
44
sidebar: "docs"
55
next: "/docs/installation/"
66
tags:

content/docs/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: ""
3-
category: docs
3+
kind: reference
44
sidebar: "docs"
55
prev: "/docs/"
66
next: "/docs/writing-content/"

content/docs/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: ""
3-
category: docs
3+
kind: reference
44
sidebar: "docs"
55
prev: "/docs/deploying/"
66
next: "/docs/sidebar/"

content/docs/sidebar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: ""
3-
category: docs
3+
kind: reference
44
sidebar: "docs"
55
prev: "/docs/settings/"
66
tags:

content/docs/writing-content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: ""
3-
category: docs
3+
kind: reference
44
sidebar: "docs"
55
prev: "/docs/installation/"
66
next: "/docs/settings/"

content/languages/javascript/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
category: guides
2+
kind: recipe
33
tags:
44
- testing
55
languages:

content/languages/python/codewars-test-famework/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
category: references
2+
kind: reference
33
languages: [python]
44
tags:
55
- testing
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
category: references
2+
kind: reference
33
languages: [javascript]
44
sidebar: "language:javascript"
55
prev: /languages/javascript/
@@ -9,4 +9,4 @@ prev: /languages/javascript/
99

1010
> TODO Remove this file
1111
12-
This file exists to show how the sidebar on language pages are automatically populated and grouped by `category`.
12+
This file exists to show how the sidebar on language pages are automatically populated and grouped by `kind`.

data/categories.yml

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

data/kinds.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Fields
2+
# id: Must be unique. Used in URLs. Singular.
3+
# name: Display name. Capitalized plural for now.
4+
# description: Short description of the kind. Currently not used.
5+
# path: Required to create an index page and show on home.
6+
7+
# Main 4 kinds taken from https://documentation.divio.com
8+
9+
# keywords: lesson, newcomer, get started
10+
- id: tutorial
11+
name: Tutorials
12+
description: ""
13+
path: /tutorials/
14+
15+
# keywords: how to, problem oriented, one goal
16+
- id: recipe
17+
name: Recipes
18+
description: ""
19+
path: /recipes/
20+
21+
# keywords: describe, list, brief
22+
- id: reference
23+
name: References
24+
description: ""
25+
path: /references/
26+
27+
# keywords: explain, why, concepts, background, discussion, further reading
28+
- id: explanation
29+
name: Explanations
30+
description: ""
31+
32+
# Similar to Recipes, but focused on providing a copy pastable code.
33+
# Recipes can link to these to provide alternative solutions.
34+
- id: snippet
35+
name: Snippets
36+
description: ""

gridsome.config.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ module.exports = {
7070
plugins: ["@gridsome/remark-prismjs"],
7171
},
7272
refs: {
73-
// Each page is classified under a single category.
74-
category: {
75-
typeName: "Category",
73+
// Each documentation should belong to a single kind.
74+
kind: {
75+
typeName: "Kind",
7676
},
7777
// Can have multiple tags.
7878
tags: {
@@ -107,12 +107,6 @@ module.exports = {
107107
},
108108

109109
templates: {
110-
Category: [
111-
{
112-
path: "/categories/:id/",
113-
component: "@/templates/Category.vue",
114-
},
115-
],
116110
Tag: [
117111
{
118112
path: "/tags/:id/",

gridsome.server.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ module.exports = function (api) {
5858
const addNodesFromFile = async (collection, file, fn = (x) => x) => {
5959
const contents = await readFile(file, { encoding: "utf-8" });
6060
const items = YAML.parse(contents);
61-
for (const item of items) collection.addNode(fn(item));
61+
for (let i = 0; i < items.length; ++i) collection.addNode(fn(items[i], i));
6262
};
6363

6464
api.loadSource(async ({ addCollection, addSchemaTypes }) => {
6565
await addNodesFromFile(
66-
addCollection("Category"),
67-
path.join(__dirname, "data/categories.yml")
66+
addCollection("Kind"),
67+
path.join(__dirname, "data/kinds.yml"),
68+
(kind, i) => {
69+
// Add position so that it can be shown in the order declared.
70+
kind.position = i;
71+
return kind;
72+
}
6873
);
6974
await addNodesFromFile(
7075
addCollection("Tag"),
@@ -89,7 +94,31 @@ module.exports = function (api) {
8994
);
9095
});
9196

92-
api.createPages(({ createPage }) => {
97+
api.createPages(async ({ createPage, graphql, findPages }) => {
9398
// Use the Pages API here: https://gridsome.org/docs/pages-api/
99+
const { data } = await graphql(`
100+
{
101+
kinds: allKind {
102+
edges {
103+
node {
104+
id
105+
path
106+
}
107+
}
108+
}
109+
}
110+
`);
111+
112+
data.kinds.edges.forEach(({ node }) => {
113+
// Couldn't figure out proper filter `filter: { path: { nin: ["", null] } }` returns nodes with null path
114+
if (!node.path) return;
115+
createPage({
116+
path: node.path,
117+
component: "./src/templates/KindT.vue",
118+
context: {
119+
id: node.id,
120+
},
121+
});
122+
});
94123
});
95124
};

src/layouts/Default.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ query {
7171
languages {
7272
id
7373
}
74-
category {
74+
kind {
7575
id
7676
name
7777
}
@@ -129,7 +129,7 @@ export default {
129129
130130
const groups = {};
131131
for (const p of pages) {
132-
const key = p.category.name;
132+
const key = p.kind.name;
133133
if (!groups[key]) groups[key] = [];
134134
groups[key].push(p);
135135
}

src/pages/Categories.vue

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

0 commit comments

Comments
 (0)