Introduces a plugin registry so the display mode is selectable per device via the NixOS module config (defaults to "calendar"). Moves the hardcoded render URL base into config.base_url. Adds tests exercising the plugin system with a synthetic ICS feed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { devices, type DeviceModel } from './devices';
|
|
|
|
const BASE = `
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;350;375;400;450;600;700&display=swap" rel="stylesheet">
|
|
<link href="https://trmnl.com/css/3.0.3/plugins.css" rel="stylesheet">
|
|
</head>
|
|
<body class="environment trmnl">
|
|
<div class="screen screen--1bit {{classes}}" data-pixel-perfect="true">{{contents}}</div>
|
|
<script src="https://trmnl.com/js/3.0.3/plugins.js"></script>
|
|
</body>
|
|
</html>`;
|
|
|
|
export type RenderMode =
|
|
| 'full'
|
|
| 'half_horizontal'
|
|
| 'half_vertical'
|
|
| 'quadrant';
|
|
export interface Renderable {
|
|
hash: string;
|
|
nextEvent?: Date;
|
|
render(mode: RenderMode, model: DeviceModel): Promise<string>;
|
|
}
|
|
|
|
export type PluginList = [Renderable, RenderMode][];
|
|
|
|
export const render = async (plugins: PluginList, model: DeviceModel) => {
|
|
const classes = Object.values(model.css.classes).join(' ');
|
|
|
|
let contents = '';
|
|
for (let [plugin, mode] of plugins) {
|
|
contents += await plugin.render(mode, model);
|
|
}
|
|
|
|
return BASE.replace('{{classes}}', classes).replace('{{contents}}', contents);
|
|
};
|