-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split target function into separate file
- Loading branch information
Showing
2 changed files
with
24 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Fetch the latest ref from the content API to ensure the redirects are accurate. | ||
* | ||
* TODO: refactor to fetch from known nav-data, rather than from version | ||
* metadata. Intent being to allow upstream changes to version metadata such | ||
* that version metadata `ref` will only be updated when version metadata is | ||
* actually updated (as opposed to on every content upload, as is currently | ||
* the case). | ||
* | ||
* @param {string} product | ||
* @returns {Promise<string>} | ||
*/ | ||
async function getLatestContentRefForProduct(product) { | ||
const contentUrl = new URL('https://content.hashicorp.com') | ||
contentUrl.pathname = `/api/content/${product}/version-metadata/latest` | ||
const latestRef = await fetch(contentUrl.toString()) | ||
.then((resp) => resp.json()) | ||
.then((json) => json.result.ref) | ||
|
||
return latestRef | ||
} | ||
|
||
module.exports = getLatestContentRefForProduct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters