forked from capire/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.data.ts
More file actions
65 lines (57 loc) · 1.83 KB
/
Copy pathproperties.data.ts
File metadata and controls
65 lines (57 loc) · 1.83 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
import { defineLoader } from 'vitepress'
import AdmZip from 'adm-zip'
const { themeConfig: { capire }} = global.VITEPRESS_CONFIG.site
const version = capire.versions.java_services
const url = `https://repo1.maven.org/maven2/com/sap/cds/cds-services-api/${version}/cds-services-api-${version}-sources.jar`
export default defineLoader({
async load() {
let props = await fetchProperties()
const properties = massageProperties(props)
return { properties, version }
}
})
async function fetchProperties(): Promise<JavaSdkProperties[]> {
// console.debug(`\n fetching properties of CDS Java ${version}`)
const resp = await fetch(url)
const jar = await resp.arrayBuffer()
return new Promise((res, rej) => {
const zip = new AdmZip(Buffer.from(jar))
zip.readAsTextAsync('properties.json', (data, err) => {
if (err) return rej(err)
res(JSON.parse(data).properties)
})
})
}
function massageProperties(properties: JavaSdkProperties[]): OurProperties[] {
return properties.map(({ name, header, type, default:defaultValue, doc }) => ({
// @ts-ignore
name: name.replaceAll(/<(index|key)>/g, '<i><$1></i>'), // decorate special <key> and <index> names
type,
description: md2Html(doc),
defaultValue: defaultValue ? `<code>${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,
anchor: string
}