Skip to content

Commit b28958d

Browse files
authored
production mode should now use cloudinary for image delivery (playfulprogramming#1250)
Preview: https://playfulprogramming-git-fork-gungier-1230-migrat-ef6732-oceanbit.vercel.app/
2 parents 3d7d26e + bafb057 commit b28958d

22 files changed

+37
-33
lines changed

src/constants/site-config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const buildMode = process.env.BUILD_ENV || "production";
1+
const buildMode = import.meta.env.BUILD_ENV || "production";
22
const siteUrl = (() => {
3-
let siteUrl = process.env.SITE_URL || process.env.VERCEL_URL || "";
3+
let siteUrl = import.meta.env.SITE_URL || import.meta.env.VERCEL_URL || "";
44

55
if (siteUrl && !siteUrl.startsWith("http")) siteUrl = `https://${siteUrl}`;
66

src/utils/get-picture.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { JSX } from "preact";
22
import type { ImageMetadata } from "astro";
3+
import { siteUrl } from "../constants/site-config";
34

45
export interface GetPictureSizes {
56
[size: number]: {
@@ -42,7 +43,13 @@ function getSupportedWidth(width: number) {
4243

4344
const isDev = Boolean(import.meta.env?.DEV);
4445

45-
function getSource(src: string, width: number) {
46+
const PUBLIC_CLOUDINARY_CLOUD_NAME = import.meta.env
47+
.PUBLIC_CLOUDINARY_CLOUD_NAME;
48+
49+
if (!isDev && !PUBLIC_CLOUDINARY_CLOUD_NAME)
50+
console.error("missing public variable CLOUDINARY_CLOUD_NAME");
51+
52+
function getSource(src: string, width: number, getFormat: string) {
4653
if (isDev) {
4754
// If the dev server is running, we can use the /_image endpoint
4855
return `/_image?${new URLSearchParams({
@@ -51,12 +58,9 @@ function getSource(src: string, width: number) {
5158
q: "100",
5259
})}`;
5360
} else {
54-
// Otherwise, use Vercel's Image Optimization API
55-
return `/_vercel/image?${new URLSearchParams({
56-
url: src,
57-
w: String(width),
58-
q: "100",
59-
})}`;
61+
// If in production use cloudinary's fetch
62+
const domainUrl = new URL(src, siteUrl);
63+
return `https://res.cloudinary.com/${PUBLIC_CLOUDINARY_CLOUD_NAME}/image/fetch/w_${width},f_${getFormat},q_auto/${encodeURIComponent(domainUrl.toString())}`;
6064
}
6165
}
6266

@@ -76,7 +80,7 @@ export function getPictureUrls(options: GetPictureOptions): GetPictureUrls {
7680

7781
for (const width of widths) {
7882
const supportedWidth = getSupportedWidth(width);
79-
formatUrls[supportedWidth] = getSource(src, supportedWidth);
83+
formatUrls[supportedWidth] = getSource(src, supportedWidth, format);
8084
}
8185
}
8286

src/views/collections/framework-field-guide/components/quote-card.astro

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
import { Picture } from "components/image/picture";
33
import styles from "./quote-card.module.scss";
4-
import type { ImageMetadata } from "astro";
54
65
interface Props {
7-
avatarSrc: string | Promise<{ default: ImageMetadata }>;
6+
avatarSrc: string;
87
quote: string;
98
personLink: string;
109
personTitle: string;
@@ -13,9 +12,6 @@ interface Props {
1312
1413
const { avatarSrc, quote, personTitle, personName, personLink } =
1514
Astro.props as Props;
16-
17-
const src =
18-
typeof avatarSrc === "string" ? avatarSrc : (await avatarSrc).default;
1915
---
2016

2117
<li class={styles.quoteCardContainerLi}>
@@ -26,7 +22,7 @@ const src =
2622
<div class={styles.personDetailsContainer}>
2723
<Picture
2824
imgAttrs={{ class: styles.personAvatar }}
29-
src={src}
25+
src={avatarSrc}
3026
alt=""
3127
width={40}
3228
height={40}

src/views/collections/framework-field-guide/segments/quotes.astro

+21-17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import QuoteCard from "../components/quote-card.astro";
55
import QuotesContainer from "../components/quotes-container.astro";
66
import SmallFilledButton from "../components/small-filled-button.astro";
77
import styles from "./quotes.module.scss";
8+
9+
const peoplePicturesDir =
10+
"/content/crutchcorn/collections/framework-field-guide/people-pictures";
811
---
912

1013
<section class={styles.fullQuotesContainer} aria-labelledby="quotes-heading">
@@ -36,7 +39,7 @@ Whether you want to go from zero to hero in the marvelous world of frontend Java
3639
<QuoteCard
3740
personName={`Santosh Yadav`}
3841
personLink={"https://twitter.com/SantoshYadavDev"}
39-
avatarSrc={import("../people-pictures/santosh_yadav.jpg")}
42+
avatarSrc={`${peoplePicturesDir}/santosh_yadav.jpg`}
4043
personTitle={`Angular GDE, GitHub Star, OSS Advocate, Auth0 Ambassador`}
4144
quote={`
4245
I know Angular, and the book is written in such a beautiful way I loved reading it. I just don't believe it is going to be available for free. It is one of the best technical books I've read recently; it's very well structured to give you ideas about React, Angular, and Vue.
@@ -47,7 +50,7 @@ Even if you are not interested in learning other frameworks and want to learn on
4750
<QuoteCard
4851
personName={`Satyajit Sahoo`}
4952
personLink={"https://twitter.com/satya164"}
50-
avatarSrc={import("../people-pictures/satyajit_sahoo.jpg")}
53+
avatarSrc={`${peoplePicturesDir}/satyajit_sahoo.jpg`}
5154
personTitle={`Maintainer of React Navigation, Creator of Linaria`}
5255
quote={`
5356
I am really impressed with "The Framework Field Guide" by Corbin - not only does it manage to describe various concepts of popular frameworks in a very concise way with code examples and illustrations, but it does so for multiple frameworks at once. For developers like me who are already familiar with React, it's a great way to learn how to translate those concepts to other frameworks. I highly recommend it.
@@ -56,7 +59,8 @@ I am really impressed with "The Framework Field Guide" by Corbin - not only does
5659
<QuoteCard
5760
personName={`Jessica Temporal`}
5861
personLink={"https://twitter.com/jesstemporal"}
59-
avatarSrc={import("../people-pictures/jessica_temporal.jpg")}
62+
avatarSrc={getPersonById("jtemporal", "en")!.profileImgMeta
63+
.relativeServerPath}
6064
personTitle={`PyLady • GitHub Star • Sr Developer Advocate @ Auth0 by Okta`}
6165
quote={`
6266
As a developer, my main focus is on Python. I still find the world of JavaScript confusing at times. However, Corbin's teaching style is so easy-going that even people like myself can have a great time. I first met Corbin through one of his live streams, and I can assure you that his content is worth your while. If you need help with React, Angular, and/or Vue, you've come to the right place.
@@ -65,7 +69,7 @@ As a developer, my main focus is on Python. I still find the world of JavaScript
6569
<QuoteCard
6670
personName={`Nic Raboy`}
6771
personLink={"https://twitter.com/nraboy"}
68-
avatarSrc={import("../people-pictures/nic_raboy.jpg")}
72+
avatarSrc={`${peoplePicturesDir}/nic_raboy.jpg`}
6973
personTitle={`Founder of The Polyglot Developer`}
7074
quote={`
7175
Corbin is an incredible teacher who is able to create easy to digest material that is both thorough and fun. If you're looking to become an expert in both JavaScript as well as a JavaScript related framework, this book series should help you accomplish it.
@@ -74,7 +78,7 @@ Corbin is an incredible teacher who is able to create easy to digest material th
7478
<QuoteCard
7579
personName={`Esther Agbaje`}
7680
personLink={"https://estheragbaje.dev/"}
77-
avatarSrc={import("../people-pictures/esther_agbaje.png")}
81+
avatarSrc={`${peoplePicturesDir}/esther_agbaje.png`}
7882
personTitle={`Developer Advocate, Chakra UI`}
7983
quote={`
8084
The structure of the book as a whole is well-organized and in-depth, making it a great resource for individuals with little to no prior experience in web development as well as those interested in learning more about the theoretical underpinnings of JavaScript frameworks.
@@ -85,7 +89,7 @@ In particular, what I like about Corbin's approach is how he takes intricate con
8589
<QuoteCard
8690
personName={`Mark Takata`}
8791
personLink={"https://twitter.com/MarkTakata"}
88-
avatarSrc={import("../people-pictures/mark_takata.jpg")}
92+
avatarSrc={`${peoplePicturesDir}/mark_takata.jpg`}
8993
personTitle={`Global Adobe Technical Evangelist for ColdFusion, Keynote Speaker`}
9094
quote={`
9195
Most old timey developers will tell you that, under the hood, nearly all programming languages work more or less the same. But Corbin is one of the first to lift that hood, climb in the engine bay & invite the world in for a tour. A book series that truly embodies the three E’s: Entertainment, engagement & education. Recommended for anyone with an interest in this whole ‘JavaScript frameworks’ razzledazzle.
@@ -94,7 +98,7 @@ Most old timey developers will tell you that, under the hood, nearly all program
9498
<QuoteCard
9599
personName={`Brad Garropy`}
96100
personLink="https://bradgarropy.com/"
97-
avatarSrc={import("../people-pictures/brad_garropy.jpg")}
101+
avatarSrc={`${peoplePicturesDir}/brad_garropy.jpg`}
98102
personTitle={`Lead Frontend Developer, Open Source Maintainer`}
99103
quote={`
100104
Teaching three frameworks at once is a huge undertaking, but Corbin goes deeper into software than anyone I know. He identifies core concepts and teaches them in a way that's valuable for conceptual understanding, then shows practical implementations across frameworks. This is the most comprehensive guide I've seen!
@@ -103,7 +107,7 @@ Teaching three frameworks at once is a huge undertaking, but Corbin goes deeper
103107
<QuoteCard
104108
personName={`James Quick`}
105109
personLink="https://www.youtube.com/jamesqquick"
106-
avatarSrc={import("../people-pictures/james_quick.png")}
110+
avatarSrc={`${peoplePicturesDir}/james_quick.png`}
107111
personTitle={`Developer. Speaker. Teacher`}
108112
quote={`
109113
This is one of the most unique and valuable approaches to teaching and learning frontend frameworks that I've ever seen. Being able to compare Angular, React, and Vue alongside each other while learning the core concepts of frameworks is incredible. I think focusing on the concepts while also showing how the different frameworks implement those concepts is an incredible idea!
@@ -112,7 +116,7 @@ This is one of the most unique and valuable approaches to teaching and learning
112116
<QuoteCard
113117
personName={`Brandon Roberts`}
114118
personLink="https://twitter.com/brandontroberts"
115-
avatarSrc={import("../people-pictures/brandon_roberts.jpg")}
119+
avatarSrc={`${peoplePicturesDir}/brandon_roberts.jpg`}
116120
personTitle={`NgRX and AnalogJS Maintainer, Angular GDE, Web Developer`}
117121
quote={`
118122
Learning the similarities and differences between different web frameworks helps you make an informed decision about which works better for your next project. This book does an excellent job of providing clear examples and guidance about how React, Angular, and Vue work, along with how to move on from basic understanding to advanced topics. I can recommend this book to web developers without hesitation.
@@ -121,7 +125,7 @@ Learning the similarities and differences between different web frameworks helps
121125
<QuoteCard
122126
personName={`Joshua Goldberg`}
123127
personLink="https://www.joshuakgoldberg.com"
124-
avatarSrc={import("../people-pictures/joshua_goldberg.jpg")}
128+
avatarSrc={`${peoplePicturesDir}/joshua_goldberg.jpg`}
125129
personTitle={`Maintainer of TypeScript ESLint, Author of “Learning TypeScript”`}
126130
quote={`
127131
The Framework Field Guide does a wonderful job of comparing and contrasting three of the most widely used UI frameworks out there. As a proficient user only in React, I found it quite useful for branching into Angular and Vue. I'd recommend this for anybody looking to level up their knowledge of modern UI frameworks!
@@ -140,7 +144,7 @@ Reading the Framework Field Guide is like boarding the ship of frontend developm
140144
<QuoteCard
141145
personName={`Sean Whitesell`}
142146
personLink="https://twitter.com/codewithseanw"
143-
avatarSrc={import("../people-pictures/sean_whitesell.jpg")}
147+
avatarSrc={`${peoplePicturesDir}/sean_whitesell.jpg`}
144148
personTitle={`Microsoft MVP, Cloud Architect, Author of “Pro Microservices In .NET 6”`}
145149
quote={`
146150
Corbin does an amazing job teaching fundamentals that simplify learning React, Angular, and Vue. The many analogies, pictures, and diagrams are fantastic for conveying detailed information in a way that is easy to consume. You can easily tell that Corbin cares about you, the reader, and really wants you to learn as easily as possible.
@@ -158,7 +162,7 @@ This guide offers a brilliant overview of concepts that can apply to almost any
158162
/>
159163
<QuoteCard
160164
personName={`Anar Kamalova`}
161-
avatarSrc={import("../people-pictures/anar_kamalova.jpg")}
165+
avatarSrc={`${peoplePicturesDir}/anar_kamalova.jpg`}
162166
personLink="https://www.linkedin.com/in/anarkamalova/"
163167
personTitle={`Frontend Engineer`}
164168
quote={`
@@ -168,7 +172,7 @@ Corbin's approach to teaching is to take the safest and easiest path to understa
168172
<QuoteCard
169173
personName={`Salma Alam-Naylor`}
170174
personLink="https://whitep4nth3r.com/"
171-
avatarSrc={import("../people-pictures/salma_alam-naylor.png")}
175+
avatarSrc={`${peoplePicturesDir}/salma_alam-naylor.png`}
172176
personTitle={`DX Engineer, Microsoft MVP, teacher, writer, live coder`}
173177
quote={`
174178
The Framework Field Guide is a quality resource whether you want to take a very deep dive or a light, gentle paddle in the vast open waters of JavaScript frameworks. And whether you're a seasoned developer or just starting out, you'll learn some new things on every page in a friendly and approachable way.
@@ -177,7 +181,7 @@ The Framework Field Guide is a quality resource whether you want to take a very
177181
<QuoteCard
178182
personName={`Mathis Hammel`}
179183
personLink="https://twitter.com/mathishammel"
180-
avatarSrc={import("../people-pictures/mathis_hammel.jpg")}
184+
avatarSrc={`${peoplePicturesDir}/mathis_hammel.jpg`}
181185
personTitle={`Technical Evangelist`}
182186
quote={`
183187
I've never understood anything about JavaScript. {}+[] is 0, seriously?
@@ -188,7 +192,7 @@ That was until I met Corbin. His extensive knowledge, along with his amazing abi
188192
<QuoteCard
189193
personName={`James Perkins`}
190194
personLink="https://twitter.com/james_r_perkins"
191-
avatarSrc={import("../people-pictures/james_perkins.jpg")}
195+
avatarSrc={`${peoplePicturesDir}/james_perkins.jpg`}
192196
personTitle={`Senior Developer Advocate, Content Creator`}
193197
quote={`
194198
Corbin is great at giving new developers the keys to the kingdom. The pictures, diagrams, and detailed explanations allow anyone thinking about learning Vue, React, or Angular an easy blueprint. Corbin clearly cares about his readers and wants them to come away with new knowledge of industry leading frameworks
@@ -209,7 +213,7 @@ I'm confident the book contents will help you grow your skillset and use any fra
209213
<QuoteCard
210214
personName={`Jacob Walker`}
211215
personLink="https://www.linkedin.com/in/jacobjwalker/"
212-
avatarSrc={import("../people-pictures/jacob_walker.jpg")}
216+
avatarSrc={`${peoplePicturesDir}/jacob_walker.jpg`}
213217
personTitle={`Lead Software Engineer, Renaissance Learning`}
214218
quote={`
215219
New software developers often don't see how programming languages share many commonalities with each other and get hung up on syntax instead of functionality. By showing three frameworks at the same time, Corbin dispels this misconception while also showing the pros and cons of each framework.
@@ -218,7 +222,7 @@ New software developers often don't see how programming languages share many com
218222
<QuoteCard
219223
personName={`PixelPirate_`}
220224
personLink="https://twitter.com/pixlpirate_"
221-
avatarSrc={import("../people-pictures/pixelpirate_.png")}
225+
avatarSrc={`${peoplePicturesDir}/pixelpirate_.png`}
222226
personTitle={`Java Scrublord`}
223227
quote={`
224228
Being a junior developer myself, the things Corbin can do with an IDE might as well be wizardry. He's the kind of guy that, when I asked him for help wrangling some code, instead built me a bespoke tool that did the job better than I could have imagined. Not to show off but just for the love of the craft. The kind of guy I wish I could have learned from in college.

0 commit comments

Comments
 (0)