1
1
---
2
- import { getCollection , getEntry } from " astro:content" ;
2
+ import { getCollection } from " astro:content" ;
3
3
import Navigation from " ../../components/base/Navigation.astro" ;
4
4
import ProductLayout from " ../../layouts/ProductLayout.astro" ;
5
- import FlexibleSection from " ../../components/FlexibleSection.astro" ;
6
- import { Image } from ' astro:assets' ;
7
- import path from ' path' ;
8
5
9
6
export async function getStaticPaths() {
10
7
const blogEntries = await getCollection (' blog' );
@@ -20,28 +17,6 @@ const { entry } = Astro.props;
20
17
// Get the rendered content
21
18
const { Content, headings, remarkPluginFrontmatter } = await entry .render ();
22
19
23
- // Function to convert Markdown image paths to Astro image component
24
- const processImagePath = (imagePath ) => {
25
- if (imagePath .startsWith (' /' )) {
26
- // For public directory images
27
- return path .join (import .meta .env .BASE_URL || ' ' , imagePath .slice (1 ));
28
- }
29
- return imagePath ;
30
- };
31
-
32
- // Extract any image paths from the markdown content for preloading
33
- const extractImagePaths = (content ) => {
34
- const regex = / !\[ . *? \]\( (. *? )\) / g ;
35
- const matches = content .match (regex ) || [];
36
- return matches .map (match => {
37
- const pathRegex = / !\[ . *? \]\( (. *? )\) / ;
38
- const result = pathRegex .exec (match );
39
- return result ? result [1 ] : null ;
40
- }).filter (Boolean );
41
- };
42
-
43
- // Get image paths from content for preloading
44
- const imagePaths = extractImagePaths (entry .body );
45
20
46
21
// Format the publication date
47
22
const formatDate = (date ) => {
@@ -53,25 +28,14 @@ const formatDate = (date) => {
53
28
};
54
29
55
30
const title = ` ${entry .data .title } | defguard Blog ` ;
56
- const featuredImage = " github.com/DefGuard/defguard.github.io/raw/main/public/images/product/core/hero-image.png" ;
57
- const imageWidth = " 1920" ;
58
- const imageHeight = " 1080" ;
59
31
const url = ` https://defguard.net/blog/${entry .slug } ` ;
60
32
---
61
33
62
34
<ProductLayout
63
35
title ={ title }
64
- featuredImage ={ featuredImage }
65
- imageWidth ={ imageWidth }
66
- imageHeight ={ imageHeight }
67
36
url ={ url }
68
37
>
69
38
<Navigation activeSlug =" /blog" />
70
-
71
- <!-- Preload critical images -->
72
- { imagePaths .map (imagePath => (
73
- <link rel = " preload" href = { processImagePath (imagePath )} as = " image" />
74
- ))}
75
39
76
40
<main id =" blog-post-page" >
77
41
<article class =" blog-post" >
@@ -87,78 +51,9 @@ const url = `https://defguard.net/blog/${entry.slug}`;
87
51
</header >
88
52
89
53
<div class =" post-content" >
90
- <style is:global >
91
- strong, b {
92
- font-weight: 400;
93
- }
94
-
95
- /* Fix for images in Markdown */
96
- img {
97
- max-width: 100%;
98
- height: auto;
99
- display: block;
100
- margin: 2rem auto;
101
- border-radius: 8px;
102
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
103
- }
104
-
105
- /* Styles for Astro Image component */
106
- :global(img.featured-image) {
107
- max-width: 100%;
108
- height: auto;
109
- margin: 2rem auto;
110
- border-radius: 8px;
111
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
112
- display: block;
113
- }
114
-
115
- /* Set proper alt text styling */
116
- /* Error handling for images */
117
- img:not([src]), img[src=""] {
118
- position: relative;
119
- min-height: 200px;
120
- background-color: #f5f5f5;
121
- display: flex;
122
- align-items: center;
123
- justify-content: center;
124
- font-style: italic;
125
- color: #666;
126
- border-radius: 8px;
127
- }
128
-
129
- img:not([src])::before, img[src=""]::before {
130
- content: "Image not found";
131
- position: absolute;
132
- top: 50%;
133
- left: 50%;
134
- transform: translate(-50%, -50%);
135
- }
136
- /* Fix for image dimensions */
137
- .post-content img {
138
- width: auto;
139
- max-width: 100%;
140
- height: auto;
141
- margin: 2rem auto;
142
- }
143
- </style >
144
-
145
- { /* Render featured image for specific blog posts using Astro Image */ }
146
- { entry .slug === ' defguard-release' && (
147
- <div class = " blog-post-image" >
148
- <Image
149
- src = " /images/blog/defguard-main-screen.png"
150
- alt = " defguard — desktop client"
151
- width = { 800 }
152
- height = { 450 }
153
- quality = { 90 }
154
- loading = " eager"
155
- class = " featured-image"
156
- />
157
- </div >
158
- )}
159
-
160
54
<Content />
161
55
</div >
56
+
162
57
<footer class =" post-footer" >
163
58
<div class =" post-navigation" >
164
59
<a href =" /blog" class =" back-to-blog" >← Back to Blog</a >
@@ -213,17 +108,6 @@ const url = `https://defguard.net/blog/${entry.slug}`;
213
108
}
214
109
}
215
110
216
- .blog-post-image {
217
- margin: 2rem 0;
218
-
219
- .featured-image {
220
- border-radius: 8px;
221
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
222
- width: 100%;
223
- height: auto;
224
- display: block;
225
- }
226
- }
227
111
228
112
.post-content {
229
113
margin-bottom: 3rem;
@@ -312,7 +196,15 @@ const url = `https://defguard.net/blog/${entry.slug}`;
312
196
border-radius: 3px;
313
197
}
314
198
315
- /* Styles moved to global scope for better image handling */
199
+ /* Markdown image styling */
200
+ :global(img) {
201
+ max-width: 100%;
202
+ height: auto;
203
+ display: block;
204
+ margin: 2.5rem auto; // Slightly increase margin for better spacing
205
+ border-radius: 4px; // Match other radius values
206
+ box-shadow: var(--box-shadow, 0 4px 8px rgba(0, 0, 0, 0.08)); // Use CSS variable for shadow
207
+ }
316
208
}
317
209
318
210
.post-footer {
0 commit comments