diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-22 15:08:37 +0300 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-22 15:08:37 +0300 |
| commit | fcc2f4704e39b0e69b377cc138f75027721dac22 (patch) | |
| tree | 732fc94b354a26c08fba9cc9059f9c6c900182be /vendor/integration/utils | |
Initial template
Diffstat (limited to 'vendor/integration/utils')
| -rw-r--r-- | vendor/integration/utils/configBuilder.ts | 203 | ||||
| -rw-r--r-- | vendor/integration/utils/loadConfig.ts | 16 |
2 files changed, 219 insertions, 0 deletions
diff --git a/vendor/integration/utils/configBuilder.ts b/vendor/integration/utils/configBuilder.ts new file mode 100644 index 0000000..1c60e9b --- /dev/null +++ b/vendor/integration/utils/configBuilder.ts @@ -0,0 +1,203 @@ +import merge from 'lodash.merge'; + +import type { MetaData } from '~/types'; + +export type Config = { + site?: SiteConfig; + metadata?: MetaDataConfig; + i18n?: I18NConfig; + apps?: { + blog?: AppBlogConfig; + }; + ui?: unknown; + analytics?: unknown; +}; + +export interface SiteConfig { + name: string; + site?: string; + base?: string; + trailingSlash?: boolean; + googleSiteVerificationId?: string; +} +export interface MetaDataConfig extends Omit<MetaData, 'title'> { + title?: { + default: string; + template: string; + }; +} +export interface I18NConfig { + language: string; + textDirection: string; + dateFormatter?: Intl.DateTimeFormat; +} +export interface AppBlogConfig { + isEnabled: boolean; + postsPerPage: number; + isRelatedPostsEnabled: boolean; + relatedPostsCount: number; + post: { + isEnabled: boolean; + permalink: string; + robots: { + index: boolean; + follow: boolean; + }; + }; + list: { + isEnabled: boolean; + pathname: string; + robots: { + index: boolean; + follow: boolean; + }; + }; + category: { + isEnabled: boolean; + pathname: string; + robots: { + index: boolean; + follow: boolean; + }; + }; + tag: { + isEnabled: boolean; + pathname: string; + robots: { + index: boolean; + follow: boolean; + }; + }; +} +export interface AnalyticsConfig { + vendors: { + googleAnalytics: { + id?: string; + partytown?: boolean; + }; + }; +} + +export interface UIConfig { + theme: string; +} + +const DEFAULT_SITE_NAME = 'Website'; + +const getSite = (config: Config) => { + const _default = { + name: DEFAULT_SITE_NAME, + site: undefined, + base: '/', + trailingSlash: false, + + googleSiteVerificationId: '', + }; + + return merge({}, _default, config?.site ?? {}) as SiteConfig; +}; + +const getMetadata = (config: Config) => { + 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; +}; + +const getI18N = (config: Config) => { + const _default = { + language: 'en', + textDirection: 'ltr', + }; + + const value = merge({}, _default, config?.i18n ?? {}); + + return value as I18NConfig; +}; + +const getAppBlog = (config: Config) => { + 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; +}; + +const getUI = (config: Config) => { + const _default = { + theme: 'system', + }; + + return merge({}, _default, config?.ui ?? {}); +}; + +const getAnalytics = (config: Config) => { + const _default = { + vendors: { + googleAnalytics: { + id: undefined, + partytown: true, + }, + }, + }; + + return merge({}, _default, config?.analytics ?? {}) as AnalyticsConfig; +}; + +export default (config: Config) => ({ + SITE: getSite(config), + I18N: getI18N(config), + METADATA: getMetadata(config), + APP_BLOG: getAppBlog(config), + UI: getUI(config), + ANALYTICS: getAnalytics(config), +}); diff --git a/vendor/integration/utils/loadConfig.ts b/vendor/integration/utils/loadConfig.ts new file mode 100644 index 0000000..8dfb435 --- /dev/null +++ b/vendor/integration/utils/loadConfig.ts @@ -0,0 +1,16 @@ +import fs from 'node:fs'; +import yaml from 'js-yaml'; + +const loadConfig = async (configPathOrData: string | object) => { + if (typeof configPathOrData === 'string') { + const content = fs.readFileSync(configPathOrData, 'utf8'); + if (configPathOrData.endsWith('.yaml') || configPathOrData.endsWith('.yml')) { + return yaml.load(content); + } + return content; + } + + return configPathOrData; +}; + +export default loadConfig; |
