Dumb hardcoding
This commit is contained in:
parent
d575fd58e2
commit
81daaa174a
@ -5,7 +5,7 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
volumes:
|
volumes:
|
||||||
- ./images:/app/images
|
- ./images:/app/images
|
||||||
- ./images.json:/app/images.json
|
- /var/core/analogGallery/images.json:/app/images.json
|
||||||
expose:
|
expose:
|
||||||
- "3000"
|
- "3000"
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@ -7,38 +7,42 @@ import { fileURLToPath } from 'url';
|
|||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
async function generateSite() {
|
async function generateSite() {
|
||||||
// Read the images data
|
try {
|
||||||
const imagesData = JSON.parse(
|
// Check if images.json exists before trying to read it
|
||||||
await fs.readFile('images.json', 'utf-8')
|
await fs.access('images.json', fs.constants.F_OK);
|
||||||
);
|
|
||||||
|
|
||||||
console.log(imagesData);
|
|
||||||
|
|
||||||
// Create output directory if it doesn't exist
|
|
||||||
await fs.mkdir('public', { recursive: true });
|
|
||||||
|
|
||||||
// Copy the CSS file to public directory
|
|
||||||
await fs.copyFile('public/styles.css', 'public/styles.css').catch(err => {
|
|
||||||
console.error('Error copying CSS file:', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Copy the favicon
|
|
||||||
await fs.copyFile('public/AnalogCameraS.png', 'public/favicon.png').catch(err => {
|
|
||||||
console.error('Error copying favicon:', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Generate individual pages for each image
|
|
||||||
for (let i = 0; i < imagesData.length; i++) {
|
|
||||||
const image = imagesData[i];
|
|
||||||
const prevImage = imagesData[i > 0 ? i - 1 : imagesData.length - 1];
|
|
||||||
const nextImage = imagesData[(i + 1) % imagesData.length];
|
|
||||||
|
|
||||||
// Use image ID for filename
|
// Read the images data
|
||||||
const fileName = `${image.id}.html`;
|
const imagesData = JSON.parse(
|
||||||
const prevFileName = `${prevImage.id}.html`;
|
await fs.readFile('images.json', 'utf-8')
|
||||||
const nextFileName = `${nextImage.id}.html`;
|
);
|
||||||
|
|
||||||
|
console.log(imagesData);
|
||||||
|
|
||||||
|
// Create output directory if it doesn't exist
|
||||||
|
await fs.mkdir('public', { recursive: true });
|
||||||
|
|
||||||
const html = `
|
// Copy the CSS file to public directory
|
||||||
|
await fs.copyFile('public/styles.css', 'public/styles.css').catch(err => {
|
||||||
|
console.error('Error copying CSS file:', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Copy the favicon
|
||||||
|
await fs.copyFile('public/AnalogCameraS.png', 'public/favicon.png').catch(err => {
|
||||||
|
console.error('Error copying favicon:', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Generate individual pages for each image
|
||||||
|
for (let i = 0; i < imagesData.length; i++) {
|
||||||
|
const image = imagesData[i];
|
||||||
|
const prevImage = imagesData[i > 0 ? i - 1 : imagesData.length - 1];
|
||||||
|
const nextImage = imagesData[(i + 1) % imagesData.length];
|
||||||
|
|
||||||
|
// Use image ID for filename
|
||||||
|
const fileName = `${image.id}.html`;
|
||||||
|
const prevFileName = `${prevImage.id}.html`;
|
||||||
|
const nextFileName = `${nextImage.id}.html`;
|
||||||
|
|
||||||
|
const html = `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@ -98,11 +102,11 @@ async function generateSite() {
|
|||||||
</body>
|
</body>
|
||||||
</html>`;
|
</html>`;
|
||||||
|
|
||||||
await fs.writeFile(`public/${fileName}`, html);
|
await fs.writeFile(`public/${fileName}`, html);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update index.html to redirect to first image's ID
|
// Update index.html to redirect to first image's ID
|
||||||
const indexHtml = `
|
const indexHtml = `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@ -113,9 +117,17 @@ async function generateSite() {
|
|||||||
</body>
|
</body>
|
||||||
</html>`;
|
</html>`;
|
||||||
|
|
||||||
await fs.writeFile('public/index.html', indexHtml);
|
await fs.writeFile('public/index.html', indexHtml);
|
||||||
|
|
||||||
console.log('Site generated successfully!');
|
console.log('Site generated successfully!');
|
||||||
|
} catch (error) {
|
||||||
|
if (error.code === 'ENOENT') {
|
||||||
|
console.error('images.json does not exist. Please run fetchImages.js first.');
|
||||||
|
} else {
|
||||||
|
console.error('Error generating site:', error);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function serveStaticSite(port = 3000) {
|
async function serveStaticSite(port = 3000) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user