This commit is contained in:
2026-05-01 16:17:59 +05:00
parent 70ea8bc844
commit 5c074a8edf
5 changed files with 47 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
{
"dependencies": {
"express": "^5.2.1"
"express": "^5.2.1",
"sharp": "^0.34.5"
}
}

BIN
public/img/h777.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

BIN
public/img/znak.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@@ -34,7 +34,7 @@
nav a { color: white; text-decoration: none; transition: color 0.3s; }
nav a:hover { color: var(--light); }
.hero { height: 100vh; background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url('img/h777.png') center/cover; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; color: white; padding: 0 20px; }
.hero { height: 100vh; background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url('img/h777.webp') center/cover; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; color: white; padding: 0 20px; }
.hero h1 { font-size: 4rem; margin-bottom: 10px; text-transform: uppercase; }
.hero p { font-size: 1.5rem; margin-bottom: 30px; }
.btn { padding: 12px 30px; background: var(--secondary); color: white; text-decoration: none; border-radius: 25px; font-weight: bold; transition: background 0.3s, transform 0.3s; border: none; cursor: pointer; }
@@ -107,7 +107,7 @@
<h2 class="section-title animate" data-i18n="loc_title">Удобное расположение</h2>
<div class="about-grid">
<div>
<img src="img/znak.png" alt="Указатель" class="about-img signpost-img animate delay-1" style="box-shadow:none; border-radius:0;">
<img src="img/znak.webp" alt="Указатель" class="about-img signpost-img animate delay-1" style="box-shadow:none; border-radius:0;">
</div>
<div class="animate delay-2">
<h3 data-i18n="loc_subtitle">Все красоты Абхазии рядом</h3>

View File

@@ -1,9 +1,47 @@
const express = require('express');
const path = require('path');
const fs = require('fs');
const sharp = require('sharp');
const app = express();
const PORT = process.env.PORT || 3000;
// Функция для автоматической конвертации изображений
async function convertImages() {
const imgDir = path.join(__dirname, 'public', 'img');
// Проверяем, существует ли папка img
if (!fs.existsSync(imgDir)) {
console.log('Папка img не найдена, пропускаем конвертацию.');
return;
}
const files = fs.readdirSync(imgDir);
for (const file of files) {
const filePath = path.join(imgDir, file);
const ext = path.extname(file).toLowerCase();
// Проверяем, является ли файл JPG или PNG
if (ext === '.jpg' || ext === '.jpeg' || ext === '.png') {
const fileNameNoExt = path.parse(file).name;
const webpPath = path.join(imgDir, `${fileNameNoExt}.webp`);
// Проверяем, существует ли уже файл .webp для этого изображения
if (!fs.existsSync(webpPath)) {
try {
await sharp(filePath)
.webp({ quality: 85 }) // Качество 85 — золотая середина
.toFile(webpPath);
console.log(`✅ Сконвертировано: ${file} -> ${fileNameNoExt}.webp`);
} catch (err) {
console.error(`❌ Ошибка при конвертации ${file}:`, err);
}
}
}
}
}
// Раздача статических файлов из папки public
app.use(express.static(path.join(__dirname, 'public')));
@@ -11,6 +49,9 @@ app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.listen(PORT, () => {
console.log(`Сервер Hotel 777 запущен: http://localhost:${PORT}`);
// Сначала конвертируем, потом запускаем сервер
convertImages().then(() => {
app.listen(PORT, () => {
console.log(`Сервер Hotel 777 запущен: http://localhost:${PORT}`);
});
});