Skip to content

Commit b0228b3

Browse files
committed
Fix title not being correct when several top level items are in a library
1 parent 09d4ef6 commit b0228b3

File tree

3 files changed

+103
-78
lines changed

3 files changed

+103
-78
lines changed

.lune/generate.luau

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,62 @@ local writeMarkdown = require("./writer")
99
local typedefsFile = fs.readFile("temp/moonwave.json")
1010
local items: { moonwave.Item } = serde.decode("json", typedefsFile)
1111

12-
-- Generate markdown for all of the libraries
13-
local generatedFiles = {} :: { [number]: {
14-
displayName: string,
12+
-- Sort all of the extracted files & items, making sure that
13+
-- the item that matches the library name always comes first,
14+
-- which will prevent for example ChildProcessWriter from
15+
-- becoming the title for the Process standard library
16+
local parsedFiles = {} :: { [number]: {
17+
path: string,
1518
name: string,
16-
content: string,
19+
item: moonwave.Item,
1720
} }
1821
for _, item in items do
19-
local file = item.source.path
20-
local name = string.match(file, "lune%-std%-(.+)/types%.d%.luau")
21-
assert(name ~= nil, "Failed to remove luau suffix from file name")
22+
local rawPath = item.source.path
23+
24+
local path = string.match(rawPath, "lune%-std%-(.+)/types%.d%.luau")
25+
assert(path ~= nil, "Failed to match standard library path")
26+
27+
table.insert(parsedFiles, {
28+
path = string.lower(path),
29+
name = item.name,
30+
item = item,
31+
})
32+
end
33+
table.sort(parsedFiles, function(a, b)
34+
local aIsExact = a.path == string.lower(a.name)
35+
local bIsExact = b.path == string.lower(b.name)
36+
if aIsExact ~= bIsExact then
37+
return aIsExact
38+
end
39+
return a.path < b.path
40+
end)
2241

42+
-- Generate all of the markdown
43+
local generatedFiles = {} :: { [number]: {
44+
path: string,
45+
name: string,
46+
content: string,
47+
} }
48+
for _, parsed in parsedFiles do
2349
-- If we have an existing entry, such as when we have multiple
2450
-- classes within the same library (Regex, RegexCaptures, ...)
2551
-- we want to append to the existing entry instead of creating
2652
local existing = nil
2753
for _, info in generatedFiles do
28-
if info.name == string.lower(name) then
54+
if info.path == string.lower(parsed.path) then
2955
existing = info
3056
break
3157
end
3258
end
3359

3460
if existing then
35-
existing.content ..= writeMarkdown(item, false)
61+
existing.content ..= writeMarkdown(parsed.item, false)
3662
else
37-
local content = `---\ntitle: {item.name}\n---\n\n`
38-
content ..= writeMarkdown(item, true)
63+
local content = `---\ntitle: {parsed.item.name}\n---\n\n`
64+
content ..= writeMarkdown(parsed.item, true)
3965
table.insert(generatedFiles, {
40-
displayName = item.name,
41-
name = string.lower(name),
66+
path = string.lower(parsed.path),
67+
name = parsed.name,
4268
content = content,
4369
})
4470
end
@@ -50,8 +76,7 @@ if fs.isDir("src/content/docs/api-reference") then
5076
end
5177
fs.writeDir("src/content/docs/api-reference")
5278
for _, file in generatedFiles do
53-
print(file)
54-
fs.writeFile(`src/content/docs/api-reference/{file.name}.md`, file.content)
79+
fs.writeFile(`src/content/docs/api-reference/{file.path}.md`, file.content)
5580
end
5681

5782
-- Finally, call out to prettier to ensure that our

src/content/docs/api-reference/process.md

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,7 @@
11
---
2-
title: ChildProcessReader
2+
title: Process
33
---
44

5-
A reader class to read data from a child process' streams in realtime.
6-
7-
## Functions
8-
9-
### read
10-
11-
Reads a chunk of data up to the specified length, or a default of 1KB at a time.
12-
13-
Returns nil if there is no more data to read.
14-
15-
This function may yield until there is new data to read from reader, if all data
16-
till present has already been read, and the process has not exited.
17-
18-
#### Parameters
19-
20-
- `chunkSize` number?
21-
22-
#### Returns
23-
24-
- The string containing the data read from the reader
25-
26-
---
27-
28-
### readToEnd
29-
30-
Reads all the data currently present in the reader as a string.
31-
This function will yield until the process exits.
32-
33-
#### Returns
34-
35-
- The string containing the data read from the reader
36-
37-
---
38-
39-
# ChildProcessWriter
40-
41-
A writer class to write data to a child process' streams in realtime.
42-
43-
## Functions
44-
45-
### write
46-
47-
Writes a buffer or string of data to the writer.
48-
49-
#### Parameters
50-
51-
- `data` The data to write to the writer
52-
53-
---
54-
55-
### close
56-
57-
Closes the underlying I/O stream for the writer.
58-
59-
---
60-
61-
# Process
62-
635
Built-in functions for the current process & child processes
646

657
#### Example usage
@@ -319,3 +261,61 @@ This is a dictionary containing the following values:
319261
- `stderr` - The full contents written to stderr by the child process, or an empty string if nothing was written
320262

321263
---
264+
265+
# ChildProcessReader
266+
267+
A reader class to read data from a child process' streams in realtime.
268+
269+
## Functions
270+
271+
### read
272+
273+
Reads a chunk of data up to the specified length, or a default of 1KB at a time.
274+
275+
Returns nil if there is no more data to read.
276+
277+
This function may yield until there is new data to read from reader, if all data
278+
till present has already been read, and the process has not exited.
279+
280+
#### Parameters
281+
282+
- `chunkSize` number?
283+
284+
#### Returns
285+
286+
- The string containing the data read from the reader
287+
288+
---
289+
290+
### readToEnd
291+
292+
Reads all the data currently present in the reader as a string.
293+
This function will yield until the process exits.
294+
295+
#### Returns
296+
297+
- The string containing the data read from the reader
298+
299+
---
300+
301+
# ChildProcessWriter
302+
303+
A writer class to write data to a child process' streams in realtime.
304+
305+
## Functions
306+
307+
### write
308+
309+
Writes a buffer or string of data to the writer.
310+
311+
#### Parameters
312+
313+
- `data` The data to write to the writer
314+
315+
---
316+
317+
### close
318+
319+
Closes the underlying I/O stream for the writer.
320+
321+
---

src/content/docs/api-reference/regex.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ Replaces all matches in the given text with the given replacer string.
152152

153153
---
154154

155-
# RegexCaptures
156-
157-
Captures from a regular expression.
158-
159155
# RegexMatch
160156

161157
A match from a regular expression.
@@ -166,3 +162,7 @@ Contains the following values:
166162
- `finish` -- The end index of the match in the original string.
167163
- `text` -- The text that was matched.
168164
- `len` -- The length of the text that was matched.
165+
166+
# RegexCaptures
167+
168+
Captures from a regular expression.

0 commit comments

Comments
 (0)