First commit
This commit is contained in:
86
Modules/htmlManager.js
Normal file
86
Modules/htmlManager.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import fs from 'fs';
|
||||
import { log } from './logManager';
|
||||
|
||||
function stylizeHTML(html) {
|
||||
return `<html>
|
||||
<head>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
div {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border: 1px solid #000;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
h2 {
|
||||
color: #333;
|
||||
font-size: 20px;
|
||||
}
|
||||
p {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
a {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
}
|
||||
div {
|
||||
background-color: #444;
|
||||
border-color: #000;
|
||||
}
|
||||
h2 {
|
||||
color: #fff;
|
||||
}
|
||||
p {
|
||||
color: #ccc;
|
||||
}
|
||||
a {
|
||||
color: #007bff;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
${html}
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
function generatePostHtml(posts) {
|
||||
return posts.map(post => `
|
||||
<div>
|
||||
<h2>${post.title}</h2>
|
||||
<p>Date: ${post.date}</p>
|
||||
<p>Flair: ${post.flair}</p>
|
||||
<p>Linked: <a href="${post.linked}">${post.linked}</a></p>
|
||||
<p>${post.description}</p>
|
||||
${post.tldr ? `<p>TLDR: ${post.tldr}</p>` : ''}
|
||||
${post.image ? `<img src="${post.image}" /><br><br>` : ''}
|
||||
<a href="${post.url}">Post Link</a>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function saveHtmlToFile(html) {
|
||||
fs.writeFileSync('index.html', html);
|
||||
log('HTML file saved.');
|
||||
}
|
||||
|
||||
export function generateHtml(posts) {
|
||||
const html = stylizeHTML(generatePostHtml(posts));
|
||||
saveHtmlToFile(html);
|
||||
}
|
||||
Reference in New Issue
Block a user