Skip to content
Snippets Groups Projects
Commit 15cff5b6 authored by David Schwarzmann's avatar David Schwarzmann
Browse files

docs: Render latest version on next branch

parent 6f95dc1c
No related merge requests found
import axios from "axios"; import axios from "axios";
import semver from "semver"; import semver from "semver";
export default async function({ siteVersion, projectId }) { export default async function ({siteVersion, projectId}) {
return axios.get(`https://git.fitko.de/api/v4/projects/${projectId}/repository/tags`) if (siteVersion === 'next') {
.catch((error) => { return 'latest'
throw `Fetching of latest tags failed with ${error.response.status}` } else {
}) return axios.get(`https://git.fitko.de/api/v4/projects/${projectId}/repository/tags`)
.then(async ({ data }) => { .catch((error) => {
if (siteVersion === 'next') { throw `Fetching of latest tags failed with ${error.response.status}`
return data[0].name })
} else { .then(async ({data}) => {
const versionRange = `~${siteVersion}` const versionRange = `~${siteVersion}`
const suitableVersions = await data const suitableVersions = await data
.filter(({ name }) => semver.satisfies(name, versionRange)) .filter(({name}) => semver.satisfies(name, versionRange))
.map(({ name }) => name) .map(({name}) => name)
.sort() .sort()
return semver.maxSatisfying(suitableVersions, versionRange) return semver.maxSatisfying(suitableVersions, versionRange)
} })
}) }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment