-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathproperties.data.ts
More file actions
55 lines (49 loc) · 1.64 KB
/
properties.data.ts
File metadata and controls
55 lines (49 loc) · 1.64 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
import { defineLoader } from 'vitepress'
const { themeConfig: { capire }} = global.VITEPRESS_CONFIG.site
const version = capire.versions.java_services
export default defineLoader({
async load() {
const props = (await import('./properties.json')).default.properties as unknown as JavaSdkProperties[]
const properties = massageProperties(props)
return { properties, version }
}
})
function massageProperties(properties: JavaSdkProperties[]): OurProperties[] {
return properties.map(({ name, header, type, default:defaultValue, doc }) => {
if (defaultValue && type?.startsWith('List')) { // split list default values into multiple lines for better readability
defaultValue = defaultValue.replace(/, ?/g, ',<br>')
}
return {
name: name.replaceAll(/<(index|key)>/g, '<i><$1></i>'), // decorate special <key> and <index> names
type: type?.replaceAll(/<(.*)>/g, ''), // remove generics for display
typeFull: type,
description: md2Html(doc),
defaultValue: defaultValue ? `<code class="no-bg">${defaultValue}</code>` : '',
header,
// @ts-ignore
anchor: name.replaceAll('.', '-')
}
})
}
function md2Html(string:string) {
return string
// @ts-ignore
.replaceAll(/`(.*?)`/g, '<code>$1</code>')
.replaceAll(/(https?:\/\/.*?)(\s)/g, '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>$2')
}
type JavaSdkProperties = {
name: string,
header: string,
type: string,
default: string,
doc: string
}
type OurProperties = {
name: string,
header: string,
type: string,
description: string,
defaultValue: string,
typeFull: string,
anchor: string
}