22import yaml from " js-yaml" ;
33import path from " node:path" ;
44import { existsSync , readFileSync } from " node:fs" ;
5+ import { Image } from " astro:assets" ;
56import TableOfContents from " @astrojs/starlight/components/TableOfContents.astro" ;
67import { slugify } from " ../utils/slugify" ;
78
@@ -10,6 +11,9 @@ let driverInfo: Record<string, any> = {};
1011let driverManufacturerDisplay = " N/A" ;
1112let driverId = " " ;
1213let yamlPath = " " ;
14+ let driverImagePath = " " ;
15+ let driverImageExists = false ;
16+ let driverWebsite = " " ;
1317
1418// Extract driverId from the current URL path
1519// Example: /mounts/sky-watcher/eqmod/ -> mounts/sky-watcher/eqmod
@@ -48,6 +52,29 @@ if (currentPath.startsWith("/")) {
4852 } else if (driverInfo .manufacturer ) {
4953 driverManufacturerDisplay = driverInfo .manufacturer as string ;
5054 }
55+ if (driverInfo .website ) {
56+ driverWebsite = driverInfo .website as string ;
57+ // Ensure the website URL is absolute
58+ if (
59+ ! driverWebsite .startsWith (" http://" ) &&
60+ ! driverWebsite .startsWith (" https://" )
61+ ) {
62+ driverWebsite = ` https://${driverWebsite } ` ;
63+ }
64+ }
65+ }
66+
67+ // Construct image path and check existence
68+ const imageFileName = ` ${driverSlug }.webp ` ;
69+ const imageDirPath = path .resolve (
70+ process .cwd (),
71+ ` public/images/${driverCategorySlug }/${driverManufacturerSlug } ` ,
72+ );
73+ const potentialImagePath = path .resolve (imageDirPath , imageFileName );
74+
75+ if (existsSync (potentialImagePath )) {
76+ driverImagePath = ` /images/${driverCategorySlug }/${driverManufacturerSlug }/${imageFileName } ` ;
77+ driverImageExists = true ;
5178 }
5279 }
5380 } catch (e ) {
@@ -62,6 +89,25 @@ if (currentPath.startsWith("/")) {
6289---
6390
6491<aside class =" starlight-right-sidebar" >
92+ {
93+ driverImageExists && driverWebsite && (
94+ <a
95+ href = { driverWebsite }
96+ target = " _blank"
97+ rel = " noopener noreferrer"
98+ class = " driver-thumbnail-link"
99+ >
100+ <Image
101+ src = { driverImagePath }
102+ alt = { ` ${driverInfo .driver_name || " Driver" } Thumbnail ` }
103+ width = { 320 }
104+ height = { 180 }
105+ class = " driver-thumbnail"
106+ />
107+ </a >
108+ )
109+ }
110+
65111 {
66112 Object .entries (driverInfo ).length > 0 ? (
67113 <div class = " driver-info-container" >
@@ -75,7 +121,8 @@ if (currentPath.startsWith("/")) {
75121 key .toLowerCase () !== " manufacturer" &&
76122 key .toLowerCase () !== " manufacturer_name" &&
77123 key .toLowerCase () !== " category_name" &&
78- key .toLowerCase () !== " driver_name" ,
124+ key .toLowerCase () !== " driver_name" &&
125+ key .toLowerCase () !== " website" ,
79126 )
80127 .map (([key , value ]) => (
81128 <div class = " info-row" >
@@ -109,6 +156,26 @@ if (currentPath.startsWith("/")) {
109156 width: max-content;
110157 }
111158
159+ .driver-thumbnail-link {
160+ display: block;
161+ margin-bottom: 1.5rem;
162+ border-radius: 0.5rem;
163+ overflow: hidden;
164+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
165+ transition: transform 0.2s ease;
166+ }
167+
168+ .driver-thumbnail-link:hover {
169+ transform: translateY(-3px);
170+ }
171+
172+ .driver-thumbnail {
173+ display: block;
174+ width: 100%;
175+ height: auto;
176+ object-fit: cover;
177+ }
178+
112179 .driver-info-container {
113180 display: flex;
114181 flex-direction: column;
0 commit comments