Skip to content

Commit

Permalink
Implement Client.playgroundURL
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuswilms committed Aug 29, 2021
1 parent 6c21951 commit df5dea8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ export default class Client {
return this.fetch(`/api/v2/tree/${this.url(url)}?${params.toString()}`);
}

// Returns a promise that resolve with the URL to a playground's index.html,
// which can be used as the source for an iframe.
static playgroundURL(node, doc, component, version = null) {
let params = new URLSearchParams();
if (version) {
params.set('v', version);
}

return Promise.resolve(
`/api/v2/tree/${this.url(node)}/_docs/${doc}/_playgrounds/${component}/index.html?${params.toString()}`
);
}

// Will automatically strip leading and trailing slashes from the given
// URL to turn it into a valid (node) URL for lookup.
static url(url) {
Expand Down

0 comments on commit df5dea8

Please sign in to comment.