update at 2026-03-21 18:44:12

This commit is contained in:
douboer@gmail.com
2026-03-21 18:44:12 +08:00
parent f9d715157f
commit 89b1f97a6f
52 changed files with 3510 additions and 562 deletions

View File

@@ -9,12 +9,14 @@ const clockRegionPath = path.join(distDir, 'clock-region.json');
const themesSourcePath = path.resolve(currentDir, '../config/themes.json');
const themesDistPath = path.join(distDir, 'themes.json');
const themesDir = path.join(distDir, 'themes');
const kindleBackgroundsDir = path.resolve(currentDir, '../kindle-backgrounds');
const dashboardBaseUrl = 'https://shell.biboer.cn:20001';
const themesSource = JSON.parse(fs.readFileSync(themesSourcePath, 'utf8'));
const generatedAt = new Date().toISOString();
const defaultVariant = themesSource.themes.find((theme) => theme.id === themesSource.defaultThemeId)?.variants?.[themesSource.defaultOrientation];
const defaultDeviceClock = defaultVariant ? toDeviceClock(defaultVariant, themesSource.defaultOrientation) : null;
const defaultTheme = themesSource.themes.find((theme) => theme.id === themesSource.defaultThemeId);
const defaultVariant = defaultTheme?.variants?.[themesSource.defaultOrientation];
const defaultDeviceClock = defaultVariant ? buildRuntimeClock(defaultTheme.id, themesSource.defaultOrientation, defaultVariant) : null;
const defaultClockRegion = defaultVariant
? {
x: defaultDeviceClock.x,
@@ -95,30 +97,74 @@ function toDeviceClock(variant, orientation) {
};
}
function resolveVariantClock(themeId, orientation, variant) {
const regionPath = path.join(distDir, 'themes', themeId, orientation, 'kindlebg.clock-region.json');
const exportedRegion = fs.existsSync(regionPath)
? JSON.parse(fs.readFileSync(regionPath, 'utf8'))
: null;
return {
...variant,
clock: {
...variant.clock,
...(exportedRegion
? {
x: exportedRegion.x,
y: exportedRegion.y,
width: exportedRegion.width,
height: exportedRegion.height,
}
: {}),
},
};
}
function buildRuntimeClock(themeId, orientation, variant) {
const resolvedVariant = resolveVariantClock(themeId, orientation, variant);
const hasExportedRegion =
resolvedVariant.clock.x !== variant.clock.x ||
resolvedVariant.clock.y !== variant.clock.y ||
resolvedVariant.clock.width !== variant.clock.width ||
resolvedVariant.clock.height !== variant.clock.height;
if (orientation === 'landscape' && hasExportedRegion) {
return {
...resolvedVariant.clock,
rotationDegrees: 90,
};
}
return toDeviceClock(resolvedVariant, orientation);
}
function buildThemeConfig(theme) {
return {
id: theme.id,
label: theme.label,
updatedAt: generatedAt,
variants: Object.fromEntries(
Object.entries(theme.variants).map(([orientation, variant]) => [
orientation,
{
devicePlacement: variant.devicePlacement,
background: {
path: variant.backgroundPath,
url: `${dashboardBaseUrl}/${variant.backgroundPath}`,
refreshIntervalMinutes: 120,
Object.entries(theme.variants).map(([orientation, variant]) => {
return [
orientation,
{
devicePlacement: variant.devicePlacement,
background: {
// Kindle 端统一走扁平目录,避免设备侧自己拼主题子目录规则。
path: `kindle-backgrounds/${theme.id}-${orientation}.png`,
url: `${dashboardBaseUrl}/kindle-backgrounds/${theme.id}-${orientation}.png`,
refreshIntervalMinutes: 120,
},
clock: buildRuntimeClock(theme.id, orientation, variant),
},
clock: toDeviceClock(variant, orientation),
},
]),
];
}),
),
};
}
fs.mkdirSync(distDir, { recursive: true });
fs.mkdirSync(themesDir, { recursive: true });
fs.mkdirSync(kindleBackgroundsDir, { recursive: true });
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
fs.writeFileSync(themesDistPath, `${JSON.stringify(themesIndex, null, 2)}\n`, 'utf8');