This repository was archived by the owner on Sep 9, 2022. It is now read-only.
forked from github/docs
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
90 lines (80 loc) · 2.76 KB
/
Copy pathindex.js
File metadata and controls
90 lines (80 loc) · 2.76 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {
readCompressedJsonFileFallbackLazily,
readCompressedJsonFileFallback,
} from '../../lib/read-json-file.js'
import { getAutomatedPageMiniTocItems } from '../get-mini-toc-items.js'
import languages from '../languages.js'
import { allVersions } from '../all-versions.js'
/* ADD LANGUAGE KEY */
let previews
let upcomingChanges
const changelog = new Map()
const graphqlSchema = new Map()
const miniTocs = new Map()
Object.keys(languages).forEach((language) => {
miniTocs.set(language, new Map())
})
export function getGraphqlSchema(version, type) {
const graphqlVersion = getGraphqlVersion(version)
if (!graphqlSchema.has(graphqlVersion)) {
graphqlSchema.set(
graphqlVersion,
readCompressedJsonFileFallback(`lib/graphql/static/schema-${graphqlVersion}.json`)
)
}
return graphqlSchema.get(graphqlVersion)[type]
}
export function getGraphqlChangelog() {
if (!changelog.has('schema')) {
changelog.set(
'schema',
readCompressedJsonFileFallbackLazily('./lib/graphql/static/changelog.json')()
)
}
return changelog.get('schema')
}
export function getGraphqlBreakingChanges(version) {
const graphqlVersion = getGraphqlVersion(version)
if (!upcomingChanges) {
upcomingChanges = readCompressedJsonFileFallbackLazily(
'./lib/graphql/static/upcoming-changes.json'
)()
}
return upcomingChanges[graphqlVersion]
}
export function getPreviews(version) {
const graphqlVersion = getGraphqlVersion(version)
if (!previews) {
previews = readCompressedJsonFileFallbackLazily('./lib/graphql/static/previews.json')()
}
return previews[graphqlVersion]
}
export async function getMiniToc(context, type, items, depth = 2, markdownHeading = '') {
const { currentLanguage, currentVersion } = context
const graphqlVersion = getGraphqlVersion(currentVersion)
if (!miniTocs.get(currentLanguage).has(graphqlVersion)) {
miniTocs.get(currentLanguage).set(graphqlVersion, new Map())
}
if (!miniTocs.get(currentLanguage).get(graphqlVersion).has(type)) {
const graphqlMiniTocItems = await getAutomatedPageMiniTocItems(
items,
context,
depth,
markdownHeading
)
miniTocs.get(currentLanguage).get(graphqlVersion).set(type, graphqlMiniTocItems)
}
return miniTocs.get(currentLanguage).get(graphqlVersion).get(type)
}
export async function getChangelogMiniTocs(items, context, depth = 2, markdownHeading = '') {
if (!changelog.has('toc')) {
changelog.set('toc', await getAutomatedPageMiniTocItems(items, context, depth, markdownHeading))
}
return changelog.get('toc')
}
function getGraphqlVersion(version) {
if (!(version in allVersions)) {
throw new Error(`Unrecognized version '${version}'. Not found in ${Object.keys(allVersions)}`)
}
return allVersions[version].miscVersionName
}