generated from nhcarrigan/template
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
/**
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
import { actionIcons, platformIcons } from "../config/icons.js";
|
|
import { landingHtml } from "../config/landing.js";
|
|
import type { App } from "../interfaces/app.js";
|
|
|
|
/**
|
|
* Generates the HTML for the landing page.
|
|
* @param app - The application instance.
|
|
* @returns An HTML string.
|
|
*/
|
|
export const generateHtml = (app: App): string => {
|
|
const sanctions = app.sanctions.toSorted((a, b) => {
|
|
return b.number - a.number;
|
|
});
|
|
|
|
const sanctionHtml = sanctions.map((sanction) => {
|
|
return sanction.revoked
|
|
&& sanction.revokedBy !== null
|
|
&& sanction.revokeDate !== null
|
|
&& sanction.revokeReason !== null
|
|
? `<div class="sanction revoked">
|
|
<details>
|
|
<summary>${
|
|
actionIcons.revoked ?? ""
|
|
} #${sanction.number.toString()}: ${sanction.action} - REVOKED ${
|
|
platformIcons[sanction.platform.toLowerCase()]
|
|
?? "<i class=\"fa-solid fa-question\"></i>"
|
|
}</summary>
|
|
<p class="user">${sanction.uuid}</p>
|
|
<p>${sanction.reason}</p>
|
|
<p>Performed by: ${sanction.moderator} on ${sanction.date.toLocaleString("en-GB")}</p>
|
|
<p class="user">Revoked:</p>
|
|
<p>${sanction.revokeReason}</p>
|
|
<p>Revoked by: ${
|
|
sanction.revokedBy
|
|
} on ${sanction.revokeDate.toLocaleString("en-GB")}</p>
|
|
</details>
|
|
</div>
|
|
`
|
|
: `<div class="sanction ${sanction.action.toLowerCase()}">
|
|
<details>
|
|
<summary>${
|
|
actionIcons[sanction.action.toLowerCase()] ?? ""
|
|
} #${sanction.number.toString()}: ${sanction.action} ${
|
|
platformIcons[sanction.platform.toLowerCase()]
|
|
?? "<i class=\"fa-solid fa-question\"></i>"
|
|
}</summary>
|
|
<p class="user">${sanction.uuid}</p>
|
|
<p>${sanction.reason}</p>
|
|
<p>Performed by: ${sanction.moderator} on ${sanction.date.toLocaleString("en-GB")}</p>
|
|
</details>
|
|
</div>
|
|
`;
|
|
});
|
|
const html = landingHtml.
|
|
replace("{{ logs }}", sanctionHtml.join("\n")).
|
|
replace("{{ timestamp }}", app.cacheUpdated.toLocaleString("en-GB"));
|
|
return html;
|
|
};
|