Make server observations handle default ':' fastfetch separator
Some checks are pending
build-docker / Build Image (push) Waiting to run
Some checks are pending
build-docker / Build Image (push) Waiting to run
This commit is contained in:
parent
c3b62cc6d5
commit
c42b6ddca8
1 changed files with 24 additions and 9 deletions
|
|
@ -9,6 +9,26 @@ import { withBasePath } from './utils/base-path.mjs';
|
||||||
const LINES_PER_PAGE = 4;
|
const LINES_PER_PAGE = 4;
|
||||||
const PAGE_DURATION_MS = 7000;
|
const PAGE_DURATION_MS = 7000;
|
||||||
|
|
||||||
|
const parseServerObservationLine = (line) => {
|
||||||
|
const trimmed = line.trim();
|
||||||
|
if (!trimmed) return null;
|
||||||
|
|
||||||
|
const separators = [' == ', ': '];
|
||||||
|
const parsedLine = separators.map((separator) => {
|
||||||
|
const separatorIndex = trimmed.indexOf(separator);
|
||||||
|
if (separatorIndex > 0) {
|
||||||
|
const key = trimmed.slice(0, separatorIndex).trim();
|
||||||
|
const value = trimmed.slice(separatorIndex + separator.length).trim();
|
||||||
|
if (key && value) {
|
||||||
|
return { key, value };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).find((entry) => entry);
|
||||||
|
|
||||||
|
return parsedLine ?? null;
|
||||||
|
};
|
||||||
|
|
||||||
class ServerObservations extends WeatherDisplay {
|
class ServerObservations extends WeatherDisplay {
|
||||||
constructor(navId, elemId) {
|
constructor(navId, elemId) {
|
||||||
super(navId, elemId, 'Server Observations', true);
|
super(navId, elemId, 'Server Observations', true);
|
||||||
|
|
@ -51,14 +71,9 @@ class ServerObservations extends WeatherDisplay {
|
||||||
const container = this.elem.querySelector('.container');
|
const container = this.elem.querySelector('.container');
|
||||||
|
|
||||||
// Split the fastfetch output into lines
|
// Split the fastfetch output into lines
|
||||||
const lines = this.data.split('\n');
|
const infoLines = this.data.split('\n')
|
||||||
|
.map((line) => parseServerObservationLine(line))
|
||||||
// Filter to show only key system info lines (contain "==")
|
.filter((line) => line);
|
||||||
const infoLines = lines.filter((line) => {
|
|
||||||
const trimmed = line.trim();
|
|
||||||
// Only keep lines that have the "Key == Value" format
|
|
||||||
return trimmed && trimmed.includes(' == ');
|
|
||||||
});
|
|
||||||
|
|
||||||
const pages = [];
|
const pages = [];
|
||||||
for (let i = 0; i < infoLines.length; i += LINES_PER_PAGE) {
|
for (let i = 0; i < infoLines.length; i += LINES_PER_PAGE) {
|
||||||
|
|
@ -73,7 +88,7 @@ class ServerObservations extends WeatherDisplay {
|
||||||
pageLines.forEach((line) => {
|
pageLines.forEach((line) => {
|
||||||
const lineDiv = document.createElement('div');
|
const lineDiv = document.createElement('div');
|
||||||
lineDiv.className = 'server-line';
|
lineDiv.className = 'server-line';
|
||||||
lineDiv.textContent = line.trim().replace(' == ', ': ');
|
lineDiv.textContent = `${line.key}: ${line.value}`;
|
||||||
pageElem.appendChild(lineDiv);
|
pageElem.appendChild(lineDiv);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue