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