core-maugli 1.2.17 → 1.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "core-maugli",
3
3
  "description": "Astro & Tailwind CSS blog theme for Maugli.",
4
4
  "type": "module",
5
- "version": "1.2.17",
5
+ "version": "1.2.19",
6
6
  "license": "GPL-3.0-or-later OR Commercial",
7
7
  "repository": {
8
8
  "type": "git",
@@ -40,9 +40,34 @@ function getResponsiveImages(imagePath: string) {
40
40
  const basePath = imagePath.replace(/\.(webp|jpg|jpeg|png)$/i, '');
41
41
  const extension = imagePath.match(/\.(webp|jpg|jpeg|png)$/i)?.[0] || '.webp';
42
42
 
43
+ // Проверяем существование адаптивных версий
44
+ const __filename = fileURLToPath(import.meta.url);
45
+ const projectRoot = path.resolve(path.dirname(__filename), '../..');
46
+
47
+ const variants = [
48
+ { suffix: '-400', width: '400w' },
49
+ { suffix: '-800', width: '800w' },
50
+ { suffix: '-1200', width: '1200w' }
51
+ ];
52
+
53
+ const srcsetItems = [];
54
+
55
+ // Добавляем адаптивные версии, если они существуют
56
+ for (const variant of variants) {
57
+ const variantPath = `${basePath}${variant.suffix}${extension}`;
58
+ const filePath = path.join(projectRoot, 'public', variantPath.replace(/^\//, ''));
59
+
60
+ if (fs.existsSync(filePath)) {
61
+ srcsetItems.push(`${variantPath} ${variant.width}`);
62
+ }
63
+ }
64
+
65
+ // Всегда добавляем оригинальное изображение
66
+ srcsetItems.push(`${imagePath} 1200w`);
67
+
43
68
  return {
44
69
  src: imagePath,
45
- srcset: [`${basePath}-400${extension} 400w`, `${basePath}-800${extension} 800w`, `${basePath}-1200${extension} 1200w`, `${imagePath} 1200w`].join(', '),
70
+ srcset: srcsetItems.join(', '),
46
71
  sizes: '(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 400px'
47
72
  };
48
73
  }
@@ -81,7 +106,7 @@ const content = excerpt || description;
81
106
  <!-- Изображение -->
82
107
  <div class="w-full aspect-[1200/630] bg-[var(--bg-muted)] overflow-hidden relative">
83
108
  <img
84
- src={cardImage.src}
109
+ src={finalImage}
85
110
  srcset={cardImage.srcset}
86
111
  sizes={cardImage.sizes}
87
112
  alt={cardImageAlt}
@@ -1,5 +1,9 @@
1
1
  ---
2
2
  // src/components/HeroImage.astro
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
6
+
3
7
  export interface Props {
4
8
  src: string;
5
9
  alt?: string;
@@ -9,20 +13,46 @@ export interface Props {
9
13
  className?: string;
10
14
  srcset?: string;
11
15
  }
12
- const defaultWidth = 800;
13
- const { src, alt = '', caption, width = defaultWidth, height, className = '', srcset = '' } = Astro.props;
16
+ const defaultWidth = 1200;
17
+ const defaultHeight = 630;
18
+ const { src, alt = '', caption, width = defaultWidth, height = defaultHeight, className = '', srcset = '' } = Astro.props;
14
19
 
15
- // Вариант aspect-ratio: если есть оба размера, рассчитываем; иначе не пишем!
16
- const aspectRatio = width && height ? `${width} / ${height}` : undefined;
20
+ // Фиксированные пропорции 1200:630
21
+ const aspectRatio = '1200 / 630';
17
22
 
18
23
  // Генерируем адаптивные версии изображений
19
24
  function getResponsiveImages(imagePath: string) {
20
25
  const basePath = imagePath.replace(/\.(webp|jpg|jpeg|png)$/i, '');
21
26
  const extension = imagePath.match(/\.(webp|jpg|jpeg|png)$/i)?.[0] || '.webp';
22
27
 
28
+ // Проверяем существование адаптивных версий
29
+ const __filename = fileURLToPath(import.meta.url);
30
+ const projectRoot = path.resolve(path.dirname(__filename), '../..');
31
+
32
+ const variants = [
33
+ { suffix: '-400', width: '400w' },
34
+ { suffix: '-800', width: '800w' },
35
+ { suffix: '-1200', width: '1200w' }
36
+ ];
37
+
38
+ const srcsetItems = [];
39
+
40
+ // Добавляем адаптивные версии, если они существуют
41
+ for (const variant of variants) {
42
+ const variantPath = `${basePath}${variant.suffix}${extension}`;
43
+ const filePath = path.join(projectRoot, 'public', variantPath.replace(/^\//, ''));
44
+
45
+ if (fs.existsSync(filePath)) {
46
+ srcsetItems.push(`${variantPath} ${variant.width}`);
47
+ }
48
+ }
49
+
50
+ // Всегда добавляем оригинальное изображение
51
+ srcsetItems.push(`${imagePath} 1200w`);
52
+
23
53
  return {
24
54
  src: imagePath,
25
- srcset: [`${basePath}-400${extension} 400w`, `${basePath}-800${extension} 800w`, `${basePath}-1200${extension} 1200w`, `${imagePath} 1200w`].join(', '),
55
+ srcset: srcsetItems.join(', '),
26
56
  sizes: '(max-width: 768px) 100vw, (max-width: 1024px) 80vw, 1200px'
27
57
  };
28
58
  }
@@ -39,17 +69,33 @@ if (srcset) {
39
69
  // Генерируем адаптивные изображения
40
70
  imageData = getResponsiveImages(src);
41
71
  }
72
+
73
+ // Используем уменьшенное превью, если оно существует
74
+ let previewImage;
75
+ if (imageData.src) {
76
+ previewImage = imageData.src.replace(/\/([^\/]+)$/, '/previews/$1');
77
+
78
+ const __filename = fileURLToPath(import.meta.url);
79
+ const projectRoot = path.resolve(path.dirname(__filename), '../..');
80
+ const previewFilePath = path.join(projectRoot, 'public', previewImage.replace(/^\//, ''));
81
+
82
+ if (!fs.existsSync(previewFilePath)) {
83
+ previewImage = undefined;
84
+ }
85
+ }
86
+
87
+ const finalImage = previewImage || imageData.src;
42
88
  ---
43
89
 
44
90
  <figure class={`w-full max-w-[${width}px] mx-auto rounded-custom overflow-hidden bg-[var(--bg-muted)] ${className}`}>
45
91
  <img
46
- src={imageData.src}
92
+ src={finalImage}
47
93
  srcset={imageData.srcset}
48
94
  sizes={imageData.sizes}
49
95
  alt={alt}
50
96
  width={width}
51
97
  height={height}
52
- style={aspectRatio ? `aspect-ratio: ${aspectRatio}; width: 100%; height: auto;` : 'width: 100%; height: auto;'}
98
+ style={`aspect-ratio: ${aspectRatio}; width: 100%; height: auto;`}
53
99
  class="block rounded-custom object-cover"
54
100
  loading="eager"
55
101
  decoding="async"