Skip to content

Commit 29ac431

Browse files
committed
refactor: simplify blog image handling
- Remove featured image property and handling - Clean up image-related code in [slug].astro - Simplify markdown image styling - Fix SCSS syntax in blog templates
1 parent 71f336e commit 29ac431

File tree

3 files changed

+11
-126
lines changed

3 files changed

+11
-126
lines changed

src/content/blog/defguard-release.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
title: "True Zero-Trust WireGuard® VPN with 2FA/MFA - defguard security paltform released by teonite"
33
publishDate: 2023-05-12
44
description: "Defguard offers a unique combination of security-related functionalities from identity management (OpenID/OAuth2/LDAP) to VPN (Wireguard) to other features (Multi-Factor Authentication, Yubikey provisioning, Web3, Webhooks, etc.)."
5-
tags: ["announcement", "defguard", "welcome"]
65
author: "Robert Olejnik"
76
---
87

src/pages/blog/[slug].astro

Lines changed: 11 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
---
2-
import { getCollection, getEntry } from "astro:content";
2+
import { getCollection } from "astro:content";
33
import Navigation from "../../components/base/Navigation.astro";
44
import ProductLayout from "../../layouts/ProductLayout.astro";
5-
import FlexibleSection from "../../components/FlexibleSection.astro";
6-
import { Image } from 'astro:assets';
7-
import path from 'path';
85
96
export async function getStaticPaths() {
107
const blogEntries = await getCollection('blog');
@@ -20,28 +17,6 @@ const { entry } = Astro.props;
2017
// Get the rendered content
2118
const { 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
4722
const formatDate = (date) => {
@@ -53,25 +28,14 @@ const formatDate = (date) => {
5328
};
5429
5530
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";
5931
const 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 {

src/pages/blog/index.astro

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,11 @@ const formatDate = (date) => {
2323
};
2424
2525
const title = "defguard Blog - Latest Updates and News";
26-
const featuredImage = "github.com/DefGuard/defguard.github.io/raw/main/public/images/product/core/hero-image.png";
27-
const imageWidth = "1920";
28-
const imageHeight = "1080";
2926
const url = "https://defguard.net/blog";
3027
---
3128

3229
<ProductLayout
3330
title={title}
34-
featuredImage={featuredImage}
35-
imageWidth={imageWidth}
36-
imageHeight={imageHeight}
3731
url={url}
3832
>
3933
<Navigation activeSlug="/blog" />

0 commit comments

Comments
 (0)