@@ -9,9 +9,10 @@ import {
99 ProjectApi ,
1010 ProjectsApi ,
1111} from "./api-model" ;
12- import { blogAuthors } from "../blog-authors" ;
12+ import { BlogAuthor , blogAuthors } from "../blog-authors" ;
1313import { projects } from "../projects" ;
1414import { artDescriptions } from "../art" ;
15+ import config from "../../../gatsby-config" ;
1516
1617const postResourceNameForEndpointCreator = ( slug : string ) =>
1718 slug !
@@ -35,7 +36,8 @@ export const blogPostsApiAdapter = (
3536 description : frontmatter . description ! ,
3637 date : frontmatter . date ! ,
3738 readingTime : node . fields ! . readingTime ! . text ! ,
38- featuredImageUrl : frontmatter . image ! . publicURL ! ,
39+ featuredImageUrl : `${ config . siteMetadata ! . siteUrl } ${ frontmatter . image !
40+ . publicURL ! } `,
3941 authors : authorsApi . authors . filter ( ( it ) =>
4042 frontmatter . authors ! . find (
4143 ( author ) =>
@@ -48,7 +50,7 @@ export const blogPostsApiAdapter = (
4850 apiBasePath ,
4951 node . fields ! . slug ! ,
5052 ) ,
51- webEndpoint : node . fields ! . slug ! ,
53+ webEndpoint : ` ${ config . siteMetadata ! . siteUrl } ${ node . fields ! . slug ! } ` ,
5254 } ;
5355 } ) ;
5456
@@ -59,6 +61,7 @@ export const blogPostsApiAdapter = (
5961
6062export const blogPostDetailsApiAdapter = (
6163 blogPostsApiQueryResult : Queries . BlogPostsApiQuery ,
64+ authorsApi : BlogAuthorsApi ,
6265) : Record < string , BlogPostDetailApi > =>
6366 blogPostsApiQueryResult ! . allMarkdownRemark . edges . reduce <
6467 Record < string , BlogPostDetailApi >
@@ -69,8 +72,15 @@ export const blogPostDetailsApiAdapter = (
6972 description : frontmatter . description ! ,
7073 date : frontmatter . date ! ,
7174 readingTime : edge . node . fields ! . readingTime ! . text ! ,
72- featuredImageUrl : frontmatter . image ! . publicURL ! ,
73- authors : frontmatter . authors ! . map ( ( it ) => it ! ) ,
75+ featuredImageUrl : `${ config . siteMetadata ! . siteUrl } ${ frontmatter . image !
76+ . publicURL ! } `,
77+ authors : authorsApi . authors . filter ( ( it ) =>
78+ frontmatter . authors ! . find (
79+ ( author ) =>
80+ author ! . split ( "_" ) . join ( " " ) . toUpperCase ( ) ===
81+ it . name . toUpperCase ( ) ,
82+ ) ,
83+ ) ,
7484 tags : frontmatter . tags ! . map ( ( it ) => it ! ) ,
7585 math : frontmatter . math ! ,
7686 content : edge . node ! . html ! ,
@@ -81,14 +91,17 @@ export const blogPostDetailsApiAdapter = (
8191export const blogAuthorsApiAdapter = (
8292 authorsImages : Queries . ImagesApiQuery ,
8393) : BlogAuthorsApi => {
84- const authors : BlogAuthorApi [ ] = Object . values ( blogAuthors ) . map ( ( author ) => ( {
85- name : author . name ,
86- url : author . url ,
87- imageUrl : authorsImages . allFile . edges . find (
94+ const getImageUrl = ( author : BlogAuthor ) =>
95+ authorsImages . allFile . edges . find (
8896 ( authorImage ) =>
8997 authorImage . node . name ===
9098 author . name ! . split ( " " ) . join ( "-" ) . toLowerCase ( ) ,
91- ) ?. node ?. publicURL ,
99+ ) ?. node ?. publicURL ;
100+
101+ const authors : BlogAuthorApi [ ] = Object . values ( blogAuthors ) . map ( ( author ) => ( {
102+ name : author . name ,
103+ url : author . url ,
104+ imageUrl : `${ config . siteMetadata ! . siteUrl } ${ getImageUrl ( author ) } ` ,
92105 } ) ) ;
93106 return {
94107 authors,
@@ -101,6 +114,10 @@ export const projectsApiAdapter = (
101114 const projectsApi : ProjectApi [ ] = Object . keys ( projects ) . map ( ( projectKey ) => {
102115 const project = projects [ projectKey ] ;
103116
117+ const getImageUrl = ( ) =>
118+ images . allFile . edges . find ( ( image ) => image . node . name === projectKey ) !
119+ . node ! . publicURL ;
120+
104121 return {
105122 id : projectKey ,
106123 name : project . name ,
@@ -110,9 +127,7 @@ export const projectsApiAdapter = (
110127 text : callToAction . label ,
111128 url : callToAction . link ,
112129 } ) ) ,
113- imageUrl : images . allFile . edges . find (
114- ( authorImage ) => authorImage . node . name === projectKey ,
115- ) ! . node ! . publicURL ,
130+ imageUrl : `${ config . siteMetadata ! . siteUrl } ${ getImageUrl ( ) } ` ,
116131 } ;
117132 } ) ;
118133
@@ -125,12 +140,14 @@ export const artApiAdapter = (images: Queries.ImagesApiQuery): ArtApi => {
125140 const projectsApi : DrawingApi [ ] = Object . keys ( artDescriptions ) . map ( ( date ) => {
126141 const description = artDescriptions [ date ] ;
127142
143+ const getImageUrl = ( ) =>
144+ images . allFile . edges . find ( ( drawImage ) => drawImage . node . name === date ) !
145+ . node ! . publicURL ! ;
146+
128147 return {
129148 date,
130149 description,
131- imageUrl : images . allFile . edges . find (
132- ( drawImage ) => drawImage . node . name === date ,
133- ) ! . node ! . publicURL ! ,
150+ imageUrl : `${ config . siteMetadata ! . siteUrl } ${ getImageUrl ( ) } ` ,
134151 } ;
135152 } ) ;
136153
0 commit comments