Skip to content

Commit 47fe7d6

Browse files
committed
feat: add resource doc template and mise task
Add template and tooling for creating new resource reference docs: - templates/resource.md with standard structure - tools/new-resource-doc.sh generator script - mise new:resource task - shellspec tests Signed-off-by: Marcin Skalski <skalskimarcin33@gmail.com>
1 parent cc8a4ad commit 47fe7d6

File tree

6 files changed

+179
-0
lines changed

6 files changed

+179
-0
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ jobs:
153153
.filter(d => d.status != "removed")
154154
.filter(d => !d.filename.includes("/generated/"))
155155
.filter(d => !d.filename.includes("/raw/"))
156+
.filter(d => !d.filename.startsWith("templates/"))
156157
.map(d => d.filename);
157158
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
158159
- uses: errata-ai/vale-action@d89dee975228ae261d22c15adcd03578634d429c # v2.1.1

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ mise vale:branch # Run Vale linter only
7474
mise vale:version-urls # Run version URL checker only
7575
```
7676

77+
#### Creating new resource docs
78+
79+
To create a new resource reference doc from template:
80+
81+
```sh
82+
mise new:resource MeshService
83+
```
84+
85+
This creates `app/_src/resources/meshservice.md` from the template. Update the nav file after creation.
86+
7787
#### Page metadata
7888

7989
All documentation pages should include frontmatter metadata for SEO and search:

mise.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ git diff --name-only --diff-filter=d origin/master...HEAD | \
106106
grep -E '\\.(md|markdown)$' | \
107107
grep -v '/generated/' | \
108108
grep -v '/raw/' | \
109+
grep -v '^templates/' | \
109110
xargs -r vale
110111
"""
111112

@@ -128,3 +129,7 @@ run = "shellcheck tools/*.sh"
128129
[tasks.check]
129130
description = "Run necessary checks"
130131
depends = ["vale:branch", "vale:version-urls", "frontmatter:validate"]
132+
133+
[tasks."new:resource"]
134+
description = "Create new resource reference doc (usage: mise new:resource ResourceName)"
135+
run = "tools/new-resource-doc.sh \"$@\""

templates/resource.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: RESOURCE_TITLE
3+
description: RESOURCE_DESCRIPTION
4+
# Use exactly 3 keywords for optimal Algolia search performance
5+
keywords:
6+
- KEYWORD1
7+
- KEYWORD2
8+
- KEYWORD3
9+
content_type: reference
10+
---
11+
12+
RESOURCE_INTRO
13+
14+
## Spec fields
15+
16+
<!-- Document each spec field with:
17+
### fieldName
18+
19+
Description of field purpose and behavior.
20+
21+
**Type:** `type` | **Required:** Yes/No | **Default:** `value`
22+
23+
#### nestedField (if applicable)
24+
-->
25+
26+
## Examples
27+
28+
### Basic RESOURCE_NAME
29+
30+
{% tabs %}
31+
{% tab Kubernetes %}
32+
33+
```yaml
34+
apiVersion: kuma.io/v1alpha1
35+
kind: RESOURCE_NAME
36+
metadata:
37+
name: example
38+
```
39+
40+
{% endtab %}
41+
{% tab Universal %}
42+
43+
```yaml
44+
type: RESOURCE_NAME
45+
name: example
46+
```
47+
48+
{% endtab %}
49+
{% endtabs %}
50+
51+
## See also
52+
53+
- [Related doc](/docs/{{ page.release }}/path)
54+
55+
## All options
56+
57+
{% json_schema RESOURCE_NAME type=proto %}

tools/new-resource-doc.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
# Creates new resource reference doc from template
4+
# Usage: tools/new-resource-doc.sh <ResourceName>
5+
6+
RESOURCE_NAME="${1:-}"
7+
if [ -z "$RESOURCE_NAME" ]; then
8+
echo "Usage: $0 <ResourceName>" >&2
9+
exit 1
10+
fi
11+
12+
LOWERCASE=$(echo "$RESOURCE_NAME" | tr '[:upper:]' '[:lower:]')
13+
OUTPUT="app/_src/resources/${LOWERCASE}.md"
14+
15+
if [ -f "$OUTPUT" ]; then
16+
echo "Error: $OUTPUT already exists" >&2
17+
exit 1
18+
fi
19+
20+
mkdir -p app/_src/resources
21+
sed "s/RESOURCE_NAME/$RESOURCE_NAME/g; \
22+
s/RESOURCE_TITLE/$RESOURCE_NAME/g; \
23+
s/RESOURCE_DESCRIPTION/TODO: Add description/g; \
24+
s/RESOURCE_INTRO/TODO: Add introduction/g; \
25+
s/KEYWORD1/$RESOURCE_NAME/g; \
26+
s/KEYWORD2/resource/g; \
27+
s/KEYWORD3/reference/g" \
28+
templates/resource.md > "$OUTPUT"
29+
30+
echo "Created $OUTPUT"
31+
echo "TODO: Update nav in latest app/_data/docs_nav_kuma_2.x.x.yml"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Describe 'new-resource-doc.sh'
2+
ORIG_DIR="$PWD"
3+
SCRIPT_UNDER_TEST="$ORIG_DIR/tools/new-resource-doc.sh"
4+
5+
setup_workspace() {
6+
TEST_DIR=$(mktemp -d)
7+
cd "$TEST_DIR"
8+
mkdir -p templates
9+
cat > templates/resource.md << 'TEMPLATE'
10+
---
11+
title: RESOURCE_TITLE
12+
description: RESOURCE_DESCRIPTION
13+
keywords:
14+
- KEYWORD1
15+
content_type: reference
16+
---
17+
18+
## Examples
19+
20+
### Basic RESOURCE_NAME
21+
22+
{% json_schema RESOURCE_NAME type=proto %}
23+
TEMPLATE
24+
}
25+
26+
cleanup_workspace() {
27+
cd "$ORIG_DIR"
28+
rm -rf "$TEST_DIR"
29+
}
30+
31+
BeforeEach 'setup_workspace'
32+
AfterEach 'cleanup_workspace'
33+
34+
Describe 'argument validation'
35+
It 'fails when no resource name provided'
36+
When run "$SCRIPT_UNDER_TEST"
37+
The status should be failure
38+
The stderr should include "Usage:"
39+
End
40+
End
41+
42+
Describe 'file creation'
43+
It 'creates resource doc with lowercase filename'
44+
When run "$SCRIPT_UNDER_TEST" MeshService
45+
The status should be success
46+
The output should include "Created app/_src/resources/meshservice.md"
47+
The file "app/_src/resources/meshservice.md" should be exist
48+
End
49+
50+
It 'replaces placeholders correctly'
51+
"$SCRIPT_UNDER_TEST" MeshGateway
52+
When run cat app/_src/resources/meshgateway.md
53+
The output should include "title: MeshGateway"
54+
The output should include "description: TODO: Add description"
55+
The output should include "- MeshGateway"
56+
The output should include "### Basic MeshGateway"
57+
The output should include "{% json_schema MeshGateway type=proto %}"
58+
End
59+
60+
It 'fails when file already exists'
61+
mkdir -p app/_src/resources
62+
echo "existing" > app/_src/resources/mesh.md
63+
When run "$SCRIPT_UNDER_TEST" Mesh
64+
The status should be failure
65+
The stderr should include "already exists"
66+
End
67+
End
68+
69+
Describe 'output messages'
70+
It 'shows TODO reminder for nav update'
71+
When run "$SCRIPT_UNDER_TEST" TestResource
72+
The output should include "TODO: Update nav"
73+
End
74+
End
75+
End

0 commit comments

Comments
 (0)