203 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-05-20 23:21:44 +02:00
/* eslint-disable @typescript-eslint/no-empty-interface */
import merge from 'lodash.merge'
2024-05-20 12:23:41 +02:00
2024-05-20 23:21:44 +02:00
import type { MetaData } from 'types'
2024-05-20 12:23:41 +02:00
2024-05-20 23:21:44 +02:00
interface Config {
site?: SiteConfig
metadata?: MetaDataConfig
i18n?: I18NConfig
2024-05-20 12:23:41 +02:00
apps?: {
2024-05-20 23:21:44 +02:00
blog?: AppBlogConfig
}
ui?: unknown
analytics?: unknown
}
2024-05-20 12:23:41 +02:00
export interface SiteConfig {
2024-05-20 23:21:44 +02:00
name: string
site?: string
base?: string
trailingSlash?: boolean
googleSiteVerificationId?: string
2024-05-20 12:23:41 +02:00
}
export interface MetaDataConfig extends Omit<MetaData, 'title'> {
title?: {
2024-05-20 23:21:44 +02:00
default: string
template: string
}
2024-05-20 12:23:41 +02:00
}
export interface I18NConfig {
2024-05-20 23:21:44 +02:00
language: string
textDirection: string
dateFormatter?: Intl.DateTimeFormat
2024-05-20 12:23:41 +02:00
}
export interface AppBlogConfig {
2024-05-20 23:21:44 +02:00
isEnabled: boolean
postsPerPage: number
isRelatedPostsEnabled: boolean
relatedPostsCount: number
2024-05-20 12:23:41 +02:00
post: {
2024-05-20 23:21:44 +02:00
isEnabled: boolean
permalink: string
2024-05-20 12:23:41 +02:00
robots: {
2024-05-20 23:21:44 +02:00
index: boolean
follow: boolean
}
}
2024-05-20 12:23:41 +02:00
list: {
2024-05-20 23:21:44 +02:00
isEnabled: boolean
pathname: string
2024-05-20 12:23:41 +02:00
robots: {
2024-05-20 23:21:44 +02:00
index: boolean
follow: boolean
}
}
2024-05-20 12:23:41 +02:00
category: {
2024-05-20 23:21:44 +02:00
isEnabled: boolean
pathname: string
2024-05-20 12:23:41 +02:00
robots: {
2024-05-20 23:21:44 +02:00
index: boolean
follow: boolean
}
}
2024-05-20 12:23:41 +02:00
tag: {
2024-05-20 23:21:44 +02:00
isEnabled: boolean
pathname: string
2024-05-20 12:23:41 +02:00
robots: {
2024-05-20 23:21:44 +02:00
index: boolean
follow: boolean
}
}
2024-05-20 12:23:41 +02:00
}
export interface AnalyticsConfig {
vendors: {
googleAnalytics: {
2024-05-20 23:21:44 +02:00
id?: string
partytown?: boolean
}
}
2024-05-20 12:23:41 +02:00
}
export interface UIConfig {}
2024-05-20 23:21:44 +02:00
const DEFAULT_SITE_NAME = 'Website'
2024-05-20 12:23:41 +02:00
const getSite = (config: Config) => {
2024-05-20 23:21:44 +02:00
const _default = {
name: DEFAULT_SITE_NAME,
site: undefined,
base: '/',
trailingSlash: false,
2024-05-20 12:23:41 +02:00
2024-05-20 23:21:44 +02:00
googleSiteVerificationId: '',
}
2024-05-20 12:23:41 +02:00
2024-05-20 23:21:44 +02:00
return merge({}, _default, config?.site ?? {}) as SiteConfig
}
2024-05-20 12:23:41 +02:00
const getMetadata = (config: Config) => {
2024-05-20 23:21:44 +02:00
const siteConfig = getSite(config)
const _default = {
title: {
default: siteConfig?.name || DEFAULT_SITE_NAME,
template: '%s',
},
description: '',
robots: {
index: false,
follow: false,
},
openGraph: {
type: 'website',
},
}
return merge({}, _default, config?.metadata ?? {}) as MetaDataConfig
}
2024-05-20 12:23:41 +02:00
const getI18N = (config: Config) => {
2024-05-20 23:21:44 +02:00
const _default = {
language: 'en',
textDirection: 'ltr',
}
2024-05-20 12:23:41 +02:00
2024-05-20 23:21:44 +02:00
const value = merge({}, _default, config?.i18n ?? {})
2024-05-20 12:23:41 +02:00
2024-05-20 23:21:44 +02:00
return value as I18NConfig
}
2024-05-20 12:23:41 +02:00
const getAppBlog = (config: Config) => {
2024-05-20 23:21:44 +02:00
const _default = {
isEnabled: false,
postsPerPage: 6,
isRelatedPostsEnabled: false,
relatedPostsCount: 4,
post: {
isEnabled: true,
permalink: '/blog/%slug%',
robots: {
index: true,
follow: true,
},
},
list: {
isEnabled: true,
pathname: 'blog',
robots: {
index: true,
follow: true,
},
},
category: {
isEnabled: true,
pathname: 'category',
robots: {
index: true,
follow: true,
},
},
tag: {
isEnabled: true,
pathname: 'tag',
robots: {
index: false,
follow: true,
},
},
}
return merge({}, _default, config?.apps?.blog ?? {}) as AppBlogConfig
}
2024-05-20 12:23:41 +02:00
const getUI = (config: Config) => {
2024-05-20 23:21:44 +02:00
const _default = {
theme: 'system',
}
2024-05-20 12:23:41 +02:00
2024-05-20 23:21:44 +02:00
return merge({}, _default, config?.ui ?? {})
}
2024-05-20 12:23:41 +02:00
const getAnalytics = (config: Config) => {
2024-05-20 23:21:44 +02:00
const _default = {
vendors: {
googleAnalytics: {
id: undefined,
partytown: true,
},
},
}
return merge({}, _default, config?.analytics ?? {}) as AnalyticsConfig
}
2024-05-20 12:23:41 +02:00
export default (config: Config) => ({
2024-05-20 23:21:44 +02:00
SITE: getSite(config),
I18N: getI18N(config),
METADATA: getMetadata(config),
APP_BLOG: getAppBlog(config),
UI: getUI(config),
ANALYTICS: getAnalytics(config),
})