Merge pull request #609 from benphelps/fix-576

Fix: settings not picked up after first container creation
This commit is contained in:
Jason Fischer 2023-01-09 16:53:24 -08:00 committed by GitHub
commit a7f290dfdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View file

@ -99,7 +99,7 @@ function Index({ initialSettings, fallback }) {
localStorage.setItem("hash", hashData.hash); localStorage.setItem("hash", hashData.hash);
} }
if (previousHash && previousHash !== hashData.hash) { if (!initialSettings.isValid || (previousHash && previousHash !== hashData.hash)) {
setStale(true); setStale(true);
localStorage.setItem("hash", hashData.hash); localStorage.setItem("hash", hashData.hash);
@ -111,7 +111,7 @@ function Index({ initialSettings, fallback }) {
} }
} }
} }
}, [hashData]); }, [hashData, initialSettings]);
if (stale) { if (stale) {
return ( return (

View file

@ -1,6 +1,6 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
import { join } from "path"; import { join } from "path";
import { existsSync, copyFile, readFileSync } from "fs"; import { existsSync, copyFile, readFileSync, statSync } from "fs";
import yaml from "js-yaml"; import yaml from "js-yaml";
@ -32,5 +32,18 @@ export function getSettings() {
const settingsYaml = join(process.cwd(), "config", "settings.yaml"); const settingsYaml = join(process.cwd(), "config", "settings.yaml");
const fileContents = readFileSync(settingsYaml, "utf8"); const fileContents = readFileSync(settingsYaml, "utf8");
return yaml.load(fileContents) ?? {};
let stats;
try {
stats = statSync(settingsYaml);
} catch (e) {
stats = {};
}
const yamlLoaded = yaml.load(fileContents) ?? {};
return {
...yamlLoaded,
isValid: fileContents !== "-\n" && stats.size !== 2 // see https://github.com/benphelps/homepage/pull/609
};
} }