Skip to content

Commit 47f12b0

Browse files
committed
Resolve quarto pub urls properly
We need this form of URL in order to resolve resources (like social metadata).
1 parent 51ddf91 commit 47f12b0

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/publish/quarto-pub/api/index.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const contentTypeApplicationJsonHeader = {
2323
"Content-Type": "application/json",
2424
};
2525

26+
const kUrlResolveRegex = /https:\/\/quartopub\.com\/sites\/([^\/]+)\/(.*)/;
27+
2628
// Creates an authorization header, if a token was supplied.
2729
const 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

271291
async function descriptionFromErrorResponse(response: Response) {

0 commit comments

Comments
 (0)