mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-12 00:15:48 +01:00
✨Add calendar tile
This commit is contained in:
7
src/tools/config/configExists.ts
Normal file
7
src/tools/config/configExists.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import { generateConfigPath } from './generateConfigPath';
|
||||
|
||||
export const configExists = (name: string) => {
|
||||
const path = generateConfigPath(name);
|
||||
return fs.existsSync(path);
|
||||
};
|
||||
4
src/tools/config/generateConfigPath.ts
Normal file
4
src/tools/config/generateConfigPath.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import path from 'path';
|
||||
|
||||
export const generateConfigPath = (configName: string) =>
|
||||
path.join(process.cwd(), 'data/configs', `${configName}.json`);
|
||||
9
src/tools/config/getConfig.ts
Normal file
9
src/tools/config/getConfig.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { ConfigType } from '../../types/config';
|
||||
import { configExists } from './configExists';
|
||||
import { getFallbackConfig } from './getFallbackConfig';
|
||||
import { readConfig } from './readConfig';
|
||||
|
||||
export const getConfig = (name: string): ConfigType => {
|
||||
if (!configExists(name)) return getFallbackConfig();
|
||||
return readConfig(name);
|
||||
};
|
||||
29
src/tools/config/getFallbackConfig.ts
Normal file
29
src/tools/config/getFallbackConfig.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { ConfigType } from '../../types/config';
|
||||
|
||||
export const getFallbackConfig = (name?: string): ConfigType => ({
|
||||
schemaVersion: '1.0.0',
|
||||
configProperties: {
|
||||
name: name ?? 'default',
|
||||
},
|
||||
categories: [],
|
||||
integrations: {},
|
||||
services: [],
|
||||
settings: {
|
||||
common: {
|
||||
searchEngine: {
|
||||
type: 'google',
|
||||
},
|
||||
},
|
||||
customization: {
|
||||
colors: {},
|
||||
layout: {
|
||||
enabledDocker: true,
|
||||
enabledLeftSidebar: true,
|
||||
enabledPing: true,
|
||||
enabledRightSidebar: true,
|
||||
enabledSearchbar: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
wrappers: [],
|
||||
});
|
||||
7
src/tools/config/readConfig.ts
Normal file
7
src/tools/config/readConfig.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import { generateConfigPath } from './generateConfigPath';
|
||||
|
||||
export function readConfig(name: string) {
|
||||
const path = generateConfigPath(name);
|
||||
return JSON.parse(fs.readFileSync(path, 'utf8'));
|
||||
}
|
||||
8
src/tools/isToday.ts
Normal file
8
src/tools/isToday.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export const isToday = (date: Date) => {
|
||||
const today = new Date();
|
||||
return (
|
||||
today.getDate() === date.getDate() &&
|
||||
today.getMonth() === date.getMonth() &&
|
||||
date.getFullYear() === date.getFullYear()
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user