Add calendar tile

This commit is contained in:
Meierschlumpf
2022-12-11 14:11:25 +01:00
parent 65970d3a2f
commit c2571190f6
13 changed files with 391 additions and 416 deletions

View 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);
};

View File

@@ -0,0 +1,4 @@
import path from 'path';
export const generateConfigPath = (configName: string) =>
path.join(process.cwd(), 'data/configs', `${configName}.json`);

View 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);
};

View 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: [],
});

View 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
View 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()
);
};