first commit
This commit is contained in:
32
apps/docs/lib/public-settings-cache.ts
Normal file
32
apps/docs/lib/public-settings-cache.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
const STORAGE_KEY = 'docs-public-settings';
|
||||
|
||||
export function readCachedPublicSettings(): Record<string, string> {
|
||||
if (typeof window === 'undefined') {
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) {
|
||||
return {};
|
||||
}
|
||||
const parsed = JSON.parse(raw) as Record<string, string>;
|
||||
return parsed && typeof parsed === 'object' ? parsed : {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export function writeCachedPublicSettings(settings: Record<string, string>) {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
||||
} catch {
|
||||
// ignore quota errors
|
||||
}
|
||||
}
|
||||
|
||||
export function mergePublicSettings(...sources: Array<Record<string, string>>): Record<string, string> {
|
||||
return Object.assign({}, ...sources);
|
||||
}
|
||||
Reference in New Issue
Block a user