diff --git a/src/pages/api/validate.js b/src/pages/api/validate.js
new file mode 100644
index 00000000..cdb28274
--- /dev/null
+++ b/src/pages/api/validate.js
@@ -0,0 +1,9 @@
+import checkAndCopyConfig from "utils/config";
+
+const configs = ["docker.yaml", "settings.yaml", "services.yaml", "bookmarks.yaml"];
+
+export default async function handler(req, res) {
+ const errors = configs.map((config) => checkAndCopyConfig(config)).filter((status) => status !== true);
+
+ res.send(errors);
+}
diff --git a/src/pages/api/widgets/openweathermap.js b/src/pages/api/widgets/openweathermap.js
index 28ff3dfa..93eeb93d 100644
--- a/src/pages/api/widgets/openweathermap.js
+++ b/src/pages/api/widgets/openweathermap.js
@@ -14,7 +14,7 @@ export default async function handler(req, res) {
}
if (!apiKey && provider) {
- const settings = await getSettings();
+ const settings = getSettings();
apiKey = settings?.providers?.openweathermap;
}
diff --git a/src/pages/api/widgets/weather.js b/src/pages/api/widgets/weather.js
index 8b96baed..5154a6dc 100644
--- a/src/pages/api/widgets/weather.js
+++ b/src/pages/api/widgets/weather.js
@@ -14,7 +14,7 @@ export default async function handler(req, res) {
}
if (!apiKey && provider) {
- const settings = await getSettings();
+ const settings = getSettings();
apiKey = settings?.providers?.weatherapi;
}
diff --git a/src/pages/index.jsx b/src/pages/index.jsx
index 3b161d45..1b20a020 100644
--- a/src/pages/index.jsx
+++ b/src/pages/index.jsx
@@ -4,6 +4,7 @@ import Head from "next/head";
import dynamic from "next/dynamic";
import { useTranslation } from "react-i18next";
import { useEffect, useContext } from "react";
+import { BiError } from "react-icons/bi";
import ServicesGroup from "components/services/group";
import BookmarksGroup from "components/bookmarks/group";
@@ -23,17 +24,54 @@ const ColorToggle = dynamic(() => import("components/color-toggle"), {
const rightAlignedWidgets = ["weatherapi", "openweathermap", "weather", "search", "datetime"];
-export async function getStaticProps() {
- const settings = await getSettings();
-
- return {
- props: {
- settings,
- },
- };
+export function getStaticProps() {
+ try {
+ const settings = getSettings();
+ return {
+ props: {
+ settings,
+ },
+ };
+ } catch (e) {
+ return {
+ props: {
+ settings: {},
+ },
+ };
+ }
}
-export default function Home({ settings }) {
+export default function Index({ settings }) {
+ const { data: errorsData } = useSWR("/api/validate");
+
+ if (errorsData && errorsData.length > 0) {
+ return (
+
+
+ {errorsData.map((error, i) => (
+
+
+
+ {error.config}
+
+
+
{error.reason}
+
{error.mark.snippet}
+
+
+ ))}
+
+
+ );
+ }
+
+ return
;
+}
+
+function Home({ settings }) {
const { i18n } = useTranslation();
const { theme, setTheme } = useContext(ThemeContext);
const { color, setColor } = useContext(ColorContext);
diff --git a/src/skeleton/bookmarks.yaml b/src/skeleton/bookmarks.yaml
index bf8a13e1..871e9134 100644
--- a/src/skeleton/bookmarks.yaml
+++ b/src/skeleton/bookmarks.yaml
@@ -1,3 +1,4 @@
+---
# For configuration options and examples, please see:
# https://github.com/benphelps/homepage/wiki/Bookmarks
diff --git a/src/skeleton/docker.yaml b/src/skeleton/docker.yaml
index a20926a7..724c2281 100644
--- a/src/skeleton/docker.yaml
+++ b/src/skeleton/docker.yaml
@@ -1,9 +1,10 @@
+---
# For configuration options and examples, please see:
# https://github.com/benphelps/homepage/wiki/Docker-Integration
-my-docker:
- host: 127.0.0.1
- port: 2375
+# my-docker:
+# host: 127.0.0.1
+# port: 2375
-other-docker:
- socket: /var/run/docker.sock
+# my-docker:
+# socket: /var/run/docker.sock
diff --git a/src/skeleton/services.yaml b/src/skeleton/services.yaml
index d6a010ab..9514f67e 100644
--- a/src/skeleton/services.yaml
+++ b/src/skeleton/services.yaml
@@ -1,3 +1,4 @@
+---
# For configuration options and examples, please see:
# https://github.com/benphelps/homepage/wiki/Services
diff --git a/src/skeleton/settings.yaml b/src/skeleton/settings.yaml
index c9f13888..623781c6 100644
--- a/src/skeleton/settings.yaml
+++ b/src/skeleton/settings.yaml
@@ -1,3 +1,4 @@
+---
# For configuration options and examples, please see:
# https://github.com/benphelps/homepage/wiki/Settings
diff --git a/src/skeleton/widgets.yaml b/src/skeleton/widgets.yaml
index 72094b1f..a5c6a911 100644
--- a/src/skeleton/widgets.yaml
+++ b/src/skeleton/widgets.yaml
@@ -1,3 +1,4 @@
+---
# For configuration options and examples, please see:
# https://github.com/benphelps/homepage/wiki/Information-Widgets
diff --git a/src/utils/config.js b/src/utils/config.js
index 7b70de37..16861de8 100644
--- a/src/utils/config.js
+++ b/src/utils/config.js
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { join } from "path";
-import { existsSync, copyFile, promises as fs } from "fs";
+import { existsSync, copyFile, readFileSync } from "fs";
import yaml from "js-yaml";
@@ -15,13 +15,22 @@ export default function checkAndCopyConfig(config) {
}
console.info("%s was copied to the config folder", config);
});
+
+ return true;
+ }
+
+ try {
+ yaml.load(readFileSync(configYaml, "utf8"));
+ return true;
+ } catch (e) {
+ return { ...e, config };
}
}
-export async function getSettings() {
+export function getSettings() {
checkAndCopyConfig("settings.yaml");
const settingsYaml = join(process.cwd(), "config", "settings.yaml");
- const fileContents = await fs.readFile(settingsYaml, "utf8");
+ const fileContents = readFileSync(settingsYaml, "utf8");
return yaml.load(fileContents);
}