@@ -23,6 +23,8 @@ const contentTypeApplicationJsonHeader = {
2323 "Content-Type" : "application/json" ,
2424} ;
2525
26+ const kUrlResolveRegex = / h t t p s : \/ \/ q u a r t o p u b \. c o m \/ s i t e s \/ ( [ ^ \/ ] + ) \/ ( .* ) / ;
27+
2628// Creates an authorization header, if a token was supplied.
2729const authorizationHeader = (
2830 token ?: string ,
@@ -163,7 +165,9 @@ export class QuartoPubClient {
163165 }
164166
165167 // Return the result.
166- return < Site > await response . json ( ) ;
168+ const site = < Site > await response . json ( ) ;
169+ site . url = this . resolveUrl ( site . url ) ;
170+ return site ;
167171 } ;
168172
169173 // Creates a site deploy.
@@ -197,7 +201,9 @@ export class QuartoPubClient {
197201 }
198202
199203 // Return the result.
200- return < PublishDeploy > await response . json ( ) ;
204+ const deploy = < PublishDeploy > await response . json ( ) ;
205+ deploy . url = this . resolveUrl ( deploy . url ) ;
206+ return deploy ;
201207 } ;
202208
203209 // Gets a deploy.
@@ -217,7 +223,9 @@ export class QuartoPubClient {
217223 }
218224
219225 // Return the result.
220- return < PublishDeploy > await response . json ( ) ;
226+ const deploy = < PublishDeploy > await response . json ( ) ;
227+ deploy . url = this . resolveUrl ( deploy . url ) ;
228+ return deploy ;
221229 } ;
222230
223231 // Uploads a deploy file.
@@ -266,6 +274,18 @@ export class QuartoPubClient {
266274
267275 // Creates a URL.
268276 private createURL = ( path : string ) => `${ this . baseURL_ } /${ path } ` ;
277+
278+ // Resolve the URL into a form that can be used to address resources
279+ // (not just the root redirect). For example this form allows
280+ // social metadata cards to properly form links to images, and so on.
281+ private resolveUrl = ( url : string ) => {
282+ const match = url . match ( kUrlResolveRegex ) ;
283+ if ( match ) {
284+ return `https://${ match [ 1 ] } .quarto.pub/${ match [ 2 ] } ` ;
285+ } else {
286+ return url ;
287+ }
288+ } ;
269289}
270290
271291async function descriptionFromErrorResponse ( response : Response ) {
0 commit comments