FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodejs.dev/util-node/createApiPages.js at main · nodejs/nodejs.dev · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
nodejs
/
nodejs.dev
Public archive
Notifications
You must be signed in to change notification settings
Fork
1k
Star
2.3k
Code
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
nodejs.dev
/
util-node
/
createApiPages.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
72 lines (56 loc) · 2.27 KB
Breadcrumbs
nodejs.dev
/
util-node
/
createApiPages.js
Copy path
File metadata and controls
72 lines (56 loc) · 2.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const
fs
=
require
(
'fs'
)
;
const
path
=
require
(
'path'
)
;
const
safeJSON
=
require
(
'./safeJSON'
)
;
const
{
iterateEdges
,
mapToNavigationData
}
=
require
(
'./createPageUtils'
)
;
const
{
apiPath
}
=
require
(
'../pathPrefixes'
)
;
function
createApiPages
(
apiEdges
,
apiTypes
,
nodeReleases
)
{
const
navigationData
=
{
}
;
const
apiPages
=
iterateEdges
(
apiEdges
,
node
=>
(
{
version
:
node
.
frontmatter
.
version
,
}
)
)
;
const
apiDocsPath
=
path
.
resolve
(
__dirname
,
`../content
${
apiPath
}
`
)
;
const
majorNodeReleases
=
[
// Gets all the major releae versions as Array [v18, v16, ...]
...
new
Set
(
nodeReleases
.
map
(
(
{
version
}
)
=>
version
)
)
,
]
;
const
navigationEntries
=
[
]
;
majorNodeReleases
.
forEach
(
version
=>
{
const
navigationFilePath
=
`
${
apiDocsPath
}
/
${
version
}
/navigation.json`
;
if
(
fs
.
existsSync
(
navigationFilePath
)
)
{
// Fetches the respective NavigationData for each major release
// If there's no file we ignore then, as we don't necessarily have all these versions indexed and parsed
// Check the `sync-api` script on package.json
const
navigationFile
=
fs
.
readFileSync
(
navigationFilePath
,
{
encoding
:
'utf8'
,
}
)
;
navigationEntries
.
push
(
safeJSON
.
parse
(
navigationFile
)
)
;
}
}
)
;
navigationEntries
.
forEach
(
entry
=>
{
navigationData
[
entry
.
version
]
=
{
}
;
apiTypes
.
forEach
(
(
{
slug
,
name
}
)
=>
{
const
entries
=
entry
.
items
.
filter
(
i
=>
i
.
type
===
name
)
.
map
(
item
=>
(
{
...
item
,
category
:
'api'
}
)
)
.
map
(
mapToNavigationData
)
;
// There might be small chances of duplication of entries, so we attempt
// to remove all the possible duplicates from the Navigation
// And then it sorts by the title of the entry
navigationData
[
entry
.
version
]
[
slug
]
=
[
...
new
Map
(
entries
.
map
(
v
=>
[
v
.
slug
,
v
]
)
)
.
values
(
)
,
]
.
sort
(
(
a
,
b
)
=>
a
.
title
.
localeCompare
(
b
.
title
)
)
;
}
)
;
}
)
;
// Get the Paths for the Latest API version
const
{
items
,
version
}
=
navigationEntries
[
0
]
;
const
defaultNavigationRedirects
=
items
.
filter
(
entry
=>
entry
.
type
===
'module'
)
.
map
(
(
{
name
}
)
=>
(
{
from
:
`
${
name
}
/`
,
to
:
`
${
version
}
/
${
name
}
/`
}
)
)
;
return
{
apiPages
,
navigationData
,
defaultNavigationRedirects
,
latestVersion
:
version
,
}
;
}
module
.
exports
=
createApiPages
;
Back
|
FazBrowse Home
|
New Git URL