Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b1ed37

Browse files
committed
Write manifest file
1 parent 87689fc commit 9b1ed37

File tree

2 files changed

+144
-58
lines changed

2 files changed

+144
-58
lines changed

docs/manifest.json

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
2-
"versions": ["main", "v0.8.1", "v0.7.12"],
2+
"versions": [
3+
"main",
4+
"v0.8.1",
5+
"v0.7.12"
6+
],
37
"routes": [
48
{
59
"title": "About",
@@ -10,16 +14,16 @@
1014
{
1115
"title": "Architecture",
1216
"description": "Learn how Coder works",
13-
"icon_path": "./images/icons/protractor.svg",
14-
"path": "./about/architecture.md"
17+
"path": "./about/architecture.md",
18+
"icon_path": "./images/icons/protractor.svg"
1519
}
1620
]
1721
},
1822
{
1923
"title": "Installation",
2024
"description": "How to install and deploy Coder",
21-
"icon_path": "./images/icons/download.svg",
2225
"path": "./install/index.md",
26+
"icon_path": "./images/icons/download.svg",
2327
"children": [
2428
{
2529
"title": "Install script",
@@ -66,32 +70,32 @@
6670
{
6771
"title": "Quickstart",
6872
"description": "Create your first template and workspace",
69-
"icon_path": "./images/icons/star.svg",
7073
"path": "./quickstart.md",
74+
"icon_path": "./images/icons/star.svg",
7175
"children": [
7276
{
7377
"title": "Docker",
7478
"description": "Setup Coder with Docker",
75-
"icon_path": "./images/icons/docker.svg",
76-
"path": "./quickstart/docker.md"
79+
"path": "./quickstart/docker.md",
80+
"icon_path": "./images/icons/docker.svg"
7781
},
7882
{
7983
"title": "Google Cloud Platform",
8084
"description": "Setup Coder on a GCP Compute Engine VM",
81-
"icon_path": "./images/google-cloud.svg",
82-
"path": "./quickstart/google-cloud-platform.md"
85+
"path": "./quickstart/google-cloud-platform.md",
86+
"icon_path": "./images/google-cloud.svg"
8387
},
8488
{
8589
"title": "AWS",
8690
"description": "Setup Coder on an AWS EC2 VM",
87-
"icon_path": "./images/aws.svg",
88-
"path": "./quickstart/aws.md"
91+
"path": "./quickstart/aws.md",
92+
"icon_path": "./images/aws.svg"
8993
},
9094
{
9195
"title": "Azure",
9296
"description": "Setup Coder on an Azure VM",
93-
"icon_path": "./images/azure.svg",
94-
"path": "./quickstart/azure.md"
97+
"path": "./quickstart/azure.md",
98+
"icon_path": "./images/azure.svg"
9599
}
96100
]
97101
},
@@ -105,8 +109,7 @@
105109
"title": "Resource Persistence",
106110
"description": "Learn how resource persistence works in Coder",
107111
"path": "./templates/resource-persistence.md",
108-
"icon_path": "./images/icons/infinity.svg",
109-
"last_updated": "2022-10-23"
112+
"icon_path": "./images/icons/infinity.svg"
110113
},
111114
{
112115
"title": "Provider Authentication",
@@ -137,8 +140,8 @@
137140
{
138141
"title": "Workspaces",
139142
"description": "Learn about Coder workspaces.",
140-
"icon_path": "./images/icons/layers.svg",
141-
"path": "./workspaces.md"
143+
"path": "./workspaces.md",
144+
"icon_path": "./images/icons/layers.svg"
142145
},
143146
{
144147
"title": "IDEs",
@@ -184,46 +187,44 @@
184187
{
185188
"title": "Dotfiles",
186189
"description": "Learn how to personalize your workspace",
187-
"icon_path": "./images/icons/art-pad.svg",
188-
"path": "./dotfiles.md"
190+
"path": "./dotfiles.md",
191+
"icon_path": "./images/icons/art-pad.svg"
189192
},
190193
{
191194
"title": "Secrets",
192195
"description": "Learn how to use secrets in your workspace",
193-
"icon_path": "./images/icons/secrets.svg",
194-
"path": "./secrets.md"
196+
"path": "./secrets.md",
197+
"icon_path": "./images/icons/secrets.svg"
195198
},
196199
{
197200
"title": "Administration",
198201
"description": "How to install and deploy Coder",
199-
"icon_path": "./images/icons/wrench.svg",
200202
"path": "./admin/index.md",
203+
"icon_path": "./images/icons/wrench.svg",
201204
"children": [
202205
{
203206
"title": "Authentication",
204207
"description": "Learn how to set up authentication using GitHub or OpenID Connect",
205-
"icon_path": "./images/icons/key.svg",
206-
"path": "./admin/auth.md"
208+
"path": "./admin/auth.md",
209+
"icon_path": "./images/icons/key.svg"
207210
},
208211
{
209212
"title": "Users",
210213
"description": "Learn about user roles available in Coder and how to create and manage users",
211-
"icon_path": "./images/icons/users.svg",
212-
"path": "./admin/users.md"
214+
"path": "./admin/users.md",
215+
"icon_path": "./images/icons/users.svg"
213216
},
214217
{
215218
"title": "Groups",
216219
"description": "Learn how to manage user groups",
217-
"icon_path": "./images/icons/group.svg",
218220
"path": "./admin/groups.md",
219-
"state": "enterprise"
221+
"icon_path": "./images/icons/group.svg"
220222
},
221223
{
222224
"title": "RBAC",
223225
"description": "Learn how to use the role based access control",
224-
"icon_path": "./images/icons/rbac.svg",
225226
"path": "./admin/rbac.md",
226-
"state": "enterprise"
227+
"icon_path": "./images/icons/rbac.svg"
227228
},
228229
{
229230
"title": "Configuration",
@@ -234,74 +235,70 @@
234235
{
235236
"title": "Git Providers",
236237
"description": "Learn how connect Coder with external git providers",
237-
"icon_path": "./images/icons/git.svg",
238-
"path": "./admin/git-providers.md"
238+
"path": "./admin/git-providers.md",
239+
"icon_path": "./images/icons/git.svg"
239240
},
240241
{
241242
"title": "Upgrading",
242243
"description": "Learn how to upgrade Coder",
243-
"icon_path": "./images/icons/upgrade.svg",
244-
"path": "./admin/upgrade.md"
244+
"path": "./admin/upgrade.md",
245+
"icon_path": "./images/icons/upgrade.svg"
245246
},
246247
{
247248
"title": "Automation",
248249
"description": "Learn how to automate Coder with the CLI and API",
249-
"icon_path": "./images/icons/plug.svg",
250-
"path": "./admin/automation.md"
250+
"path": "./admin/automation.md",
251+
"icon_path": "./images/icons/plug.svg"
251252
},
252253
{
253254
"title": "Audit Logs",
254255
"description": "Learn how to use Audit Logs in your Coder deployment",
255-
"icon_path": "./images/icons/radar.svg",
256256
"path": "./admin/audit-logs.md",
257-
"state": "enterprise"
257+
"icon_path": "./images/icons/radar.svg"
258258
},
259259
{
260260
"title": "Quotas",
261261
"description": "Learn how to use Workspace Quotas in Coder",
262-
"icon_path": "./images/icons/dollar.svg",
263262
"path": "./admin/quotas.md",
264-
"state": "enterprise"
263+
"icon_path": "./images/icons/dollar.svg"
265264
},
266265
{
267266
"title": "High Availability",
268267
"description": "Learn how to configure Coder for High Availability",
269-
"icon_path": "./images/icons/hydra.svg",
270268
"path": "./admin/high-availability.md",
271-
"state": "enterprise"
269+
"icon_path": "./images/icons/hydra.svg"
272270
},
273271
{
274272
"title": "Prometheus",
275273
"description": "Learn how to collect Prometheus metrics",
276-
"icon_path": "./images/icons/speed.svg",
277-
"path": "./admin/prometheus.md"
274+
"path": "./admin/prometheus.md",
275+
"icon_path": "./images/icons/speed.svg"
278276
},
279277
{
280278
"title": "Service Banners",
281279
"description": "Learn how to configure Service Banners",
282-
"icon_path": "./images/icons/info.svg",
283280
"path": "./admin/service-banners.md",
284-
"state": "enterprise"
281+
"icon_path": "./images/icons/info.svg"
285282
},
286283
{
287284
"title": "Telemetry",
288285
"description": "Learn what usage telemetry Coder collects",
289-
"icon_path": "./images/icons/science.svg",
290-
"path": "./admin/telemetry.md"
286+
"path": "./admin/telemetry.md",
287+
"icon_path": "./images/icons/science.svg"
291288
}
292289
]
293290
},
294291
{
295292
"title": "Enterprise",
296293
"description": "Learn how to enable Enterprise features",
297-
"icon_path": "./images/icons/group.svg",
298-
"path": "./enterprise.md"
294+
"path": "./enterprise.md",
295+
"icon_path": "./images/icons/group.svg"
299296
},
300297
{
301298
"title": "Contributing",
302299
"description": "Learn how to contribute to Coder",
303-
"icon_path": "./images/icons/contributing.svg",
304300
"path": "./CONTRIBUTING.md",
301+
"icon_path": "./images/icons/contributing.svg",
305302
"children": [
306303
{
307304
"title": "Code of Conduct",
@@ -323,9 +320,26 @@
323320
{
324321
"title": "API",
325322
"description": "Learn how to use Coderd API",
326-
"icon_path": "./images/icons/api.svg",
327323
"path": "./api/index.md",
328-
"children": []
324+
"icon_path": "./images/icons/api.svg",
325+
"children": [
326+
{
327+
"title": "Authentication",
328+
"path": "./docs/authentication.md"
329+
},
330+
{
331+
"title": "Templates",
332+
"path": "./docs/templates.md"
333+
},
334+
{
335+
"title": "Workspaces",
336+
"path": "./docs/workspaces.md"
337+
},
338+
{
339+
"title": "Schemas",
340+
"path": "./docs/schemas.md"
341+
}
342+
]
329343
}
330344
]
331-
}
345+
}

scripts/apidocgen/postprocess/main.go

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bufio"
55
"bytes"
6+
"encoding/json"
67
"flag"
78
"log"
89
"os"
@@ -14,8 +15,7 @@ import (
1415
)
1516

1617
const (
17-
apiSubdir = "api"
18-
18+
apiSubdir = "api"
1919
apiIndexFile = "index.md"
2020
apiIndexContent = `Get started with Coderd API:
2121
@@ -106,19 +106,87 @@ func writeDocs(sections [][]byte) error {
106106
return xerrors.Errorf(`can't write the index file: %w`, err)
107107
}
108108

109+
type mdFile struct {
110+
title string
111+
path string
112+
}
113+
var mdFiles []mdFile
114+
115+
// Write .md files for grouped API method (Templates, Workspaces, etc.)
109116
for _, section := range sections {
110117
sectionName, err := extractSectionName(section)
111118
if err != nil {
112119
return xerrors.Errorf("can't extract section name: %w", err)
113120
}
114121
log.Printf("Write section: %s", sectionName)
115122

116-
docPath := path.Join(apiDir, sectionName)
123+
mdFilename := toMdFilename(sectionName)
124+
docPath := path.Join(apiDir, mdFilename)
117125
err = os.WriteFile(docPath, section, 0644) // #nosec
118126
if err != nil {
119127
return xerrors.Errorf(`can't write doc file "%s": %w`, docPath, err)
120128
}
129+
mdFiles = append(mdFiles, mdFile{
130+
title: sectionName,
131+
path: "./docs/" + mdFilename,
132+
})
133+
}
134+
135+
// Update manifest.json
136+
type route struct {
137+
Title string `json:"title,omitempty"`
138+
Description string `json:"description,omitempty"`
139+
Path string `json:"path,omitempty"`
140+
IconPath string `json:"icon_path,omitempty"`
141+
Children []route `json:"children,omitempty"`
142+
}
143+
144+
type manifest struct {
145+
Versions []string `json:"versions,omitempty"`
146+
Routes []route `json:"routes,omitempty"`
121147
}
148+
149+
manifestPath := path.Join(docsDirectory, "manifest.json")
150+
manifestFile, err := os.ReadFile(manifestPath)
151+
if err != nil {
152+
return xerrors.Errorf("can't read manifest file: %w", err)
153+
}
154+
log.Printf("Read manifest file: %dB", len(manifestFile))
155+
156+
var m manifest
157+
err = json.Unmarshal(manifestFile, &m)
158+
if err != nil {
159+
return xerrors.Errorf("json.Unmarshal failed: %w", err)
160+
}
161+
162+
for i, r := range m.Routes {
163+
if r.Title != "API" {
164+
continue
165+
}
166+
167+
var children []route
168+
for _, mdf := range mdFiles {
169+
docRoute := route{
170+
Title: mdf.title,
171+
Path: mdf.path,
172+
}
173+
children = append(children, docRoute)
174+
}
175+
176+
m.Routes[i].Children = children
177+
break
178+
}
179+
180+
manifestFile, err = json.MarshalIndent(m, "", " ")
181+
if err != nil {
182+
return xerrors.Errorf("json.Marshal failed: %w", err)
183+
}
184+
185+
err = os.WriteFile(manifestPath, manifestFile, 0644) // #nosec
186+
if err != nil {
187+
return xerrors.Errorf("can't write manifest file: %w", err)
188+
}
189+
log.Printf("Write manifest file: %dB", len(manifestFile))
122190
return nil
123191
}
124192

@@ -129,5 +197,9 @@ func extractSectionName(section []byte) (string, error) {
129197
}
130198

131199
header := scanner.Text()[2:] // Skip #<space>
132-
return nonAlphanumericRegex.ReplaceAllLiteralString(strings.ToLower(strings.TrimSpace(header)), "-") + ".md", nil
200+
return strings.TrimSpace(header), nil
201+
}
202+
203+
func toMdFilename(sectionName string) string {
204+
return nonAlphanumericRegex.ReplaceAllLiteralString(strings.ToLower(sectionName), "-") + ".md"
133205
}

0 commit comments

Comments
 (0)