-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojects.ts
55 lines (51 loc) · 1.37 KB
/
projects.ts
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 { Tag } from './tags'
import yaml from 'yaml'
import glob from 'glob'
import path from 'path'
import fs from 'fs'
import getConfig from 'next/config'
const { serverRuntimeConfig } = getConfig()
export interface ProjectItemBase {
id: number
logo: string
logoAlt?: string
title: string
description: string
descriptionLong?: string
tags: Tag[]
link: string,
telegram?: string
partner?: boolean
}
export interface ProjectItem extends ProjectItemBase {
id: number
byLang: {
[key: string]: ProjectItemBase
}
}
export const loadProjects = () => {
const files = glob.sync(path.join(serverRuntimeConfig.PROJECT_ROOT, 'donations/**/ua.yml'))
const data = files
.map((file) => {
const id = parseInt(path.basename(path.dirname(file)), 10)
const byLang: any = glob
.sync(path.join(path.dirname(file), '*.yml'))
.reduce((obj, langFile) => {
const lang = path.basename(langFile).replace('.yml', '')
try {
return { ...obj, [lang]: yaml.parse(fs.readFileSync(langFile, 'utf-8')) }
} catch (err) {
console.error('Failed to load lang', lang, 'for', id, err)
return { ...obj }
}
}, {})
return {
...byLang.ua,
logo: `/logos/${id}.png`,
id,
byLang,
}
})
.sort((a, b) => a.id - b.id)
return data as ProjectItem[]
}