-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added utility to extract WP images from ACF values #134
base: master
Are you sure you want to change the base?
Conversation
constants.js is a file for placing things that don't change per environment but do change per project. i.e. WP thumbs, some projects have different thumbs, but no matter the environment they will not change (thus we want to keep it out of app-template.js) |
// Wordpress | ||
export const WP_URL = 'http://localhost/starward_wp'; | ||
export const WP_URL = APP_WP_URL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The app needs WP_URL and cannot reference a /server/ file, thus we move it to the /app/config/app.js
@@ -11,6 +11,9 @@ export const SEARCH_SLUG = 'search'; | |||
|
|||
// Starward | |||
export const baseURL = `http://${HOST}:${PORT}`; | |||
export const WP_URL = 'http://localhost/starward_wp'; | |||
export const WP_RESOURCE_URL = WP_URL; // change to '' and images will attempt to resolve to the app host, then if you have nginx setup you can proxy the WP through the APP hosting's address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this new config value is required so that we can per-environment change where we fetch images. This allows us to proxy images through someawesomesite.com instead of wp.someawesomesite.com
Adds a utility that streamlines extracting WP images from ACF in such a way that allows for:
Example usages:
extractWpImageUrl
mapExtractWpImageUrl
extractWpFeaturedImageUrl
same as
extractWpImageUrl
, except it works on featured imagesgetWpImageAlt
getWpImageCaption
By doing this we standardise how we are extracting image URL's and Thumbnails for easier usage by developers. It would be recomended practice that the ACF component extracts the image url or array of url's before passing it down to lower level components as that lets us remove the idea of WP/ACF from our components, thus making them simpler (i.e. in your acf/Hero.js extract the image url's then feed them to the slider as URL's not as WP/ACF objects.
Also do note the new config item of
WP_RESOURCE_URL
this allows us to configure the location of the images to be either the WP location (this will be used in local dev) or we can change it to be an external CDN OR if we need to proxy the images through NGINX (if we are exposing /feed/ or sitemap.xml on WP via proxying we also need to proxy images otherwise the re-writing of wp.somesite.com will leave 404's for the images). If you were to be proxying the images via nginx you would just change this variable to beWP_RESOURCE_URL = ''
I have a bunch more utility functions i can upload, however for now this is a really important one to standardise on.