11---
2- import { getCollection , getEntry } from " astro:content" ;
2+ import { getCollection } from " astro:content" ;
33import Navigation from " ../../components/base/Navigation.astro" ;
44import ProductLayout from " ../../layouts/ProductLayout.astro" ;
5- import FlexibleSection from " ../../components/FlexibleSection.astro" ;
6- import { Image } from ' astro:assets' ;
7- import path from ' path' ;
85
96export async function getStaticPaths() {
107 const blogEntries = await getCollection (' blog' );
@@ -20,28 +17,6 @@ const { entry } = Astro.props;
2017// Get the rendered content
2118const { Content, headings, remarkPluginFrontmatter } = await entry .render ();
2219
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 );
4520
4621// Format the publication date
4722const formatDate = (date ) => {
@@ -53,25 +28,14 @@ const formatDate = (date) => {
5328};
5429
5530const 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" ;
5931const url = ` https://defguard.net/blog/${entry .slug } ` ;
6032---
6133
6234<ProductLayout
6335 title ={ title }
64- featuredImage ={ featuredImage }
65- imageWidth ={ imageWidth }
66- imageHeight ={ imageHeight }
6736 url ={ url }
6837>
6938 <Navigation activeSlug =" /blog" />
70-
71- <!-- Preload critical images -->
72- { imagePaths .map (imagePath => (
73- <link rel = " preload" href = { processImagePath (imagePath )} as = " image" />
74- ))}
7539
7640 <main id =" blog-post-page" >
7741 <article class =" blog-post" >
@@ -87,78 +51,9 @@ const url = `https://defguard.net/blog/${entry.slug}`;
8751 </header >
8852
8953 <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-
16054 <Content />
16155 </div >
56+
16257 <footer class =" post-footer" >
16358 <div class =" post-navigation" >
16459 <a href =" /blog" class =" back-to-blog" >← Back to Blog</a >
@@ -213,17 +108,6 @@ const url = `https://defguard.net/blog/${entry.slug}`;
213108 }
214109 }
215110
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- }
227111
228112 .post-content {
229113 margin-bottom: 3rem;
@@ -312,7 +196,15 @@ const url = `https://defguard.net/blog/${entry.slug}`;
312196 border-radius: 3px;
313197 }
314198
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+ }
316208 }
317209
318210 .post-footer {
0 commit comments