-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformat-entity.ts
More file actions
26 lines (24 loc) · 770 Bytes
/
Copy pathformat-entity.ts
File metadata and controls
26 lines (24 loc) · 770 Bytes
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
import { isFunction } from "lodash"
interface IFormatEntry {
data: { [key: string]: unknown }
locale?: string
gatsbyNodeType: string
gatsbyImageCdn: string
}
export const formatEntity = ({ data, locale, gatsbyNodeType, gatsbyImageCdn }: IFormatEntry, context?: any) => {
const res = {
...data,
gatsbyNodeType,
...(locale && { locale: locale }),
...(gatsbyImageCdn && { gatsbyImageCdn: gatsbyImageCdn }),
}
const transformedRes: { [key: string]: any } = {}
Object.keys(res).forEach((value) => {
if (isFunction(context.pluginOptions.nodeTransform[value])) {
transformedRes[value] = context.pluginOptions.nodeTransform[value](res[value])
} else {
transformedRes[value] = res[value]
}
})
return transformedRes
}