Files
test-repo/website/playground/VersionLink.js
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
810 B
JavaScript
Raw Normal View History

import * as React from "react";
import * as ReactDOM from "react-dom";
2018-04-12 15:09:04 -03:00
const root = document.getElementById("version");
export default function ({ version }) {
2018-04-17 13:53:20 -03:00
const match = version.match(/^pr-(\d+)$/);
2018-04-12 15:09:04 -03:00
let href;
if (match) {
href = `pull/${match[1]}`;
2021-01-12 20:37:05 +08:00
} else if (/\.0$/.test(version)) {
2018-04-12 15:09:04 -03:00
href = `releases/tag/${version}`;
} else {
2021-01-24 01:14:13 +08:00
href = `blob/main/CHANGELOG.md#${version.replace(/\./g, "")}`;
2018-04-12 15:09:04 -03:00
}
const formattedVersion = match ? `PR #${match[1]}` : `v${version}`;
React.useEffect(() => {
document.title = `Prettier ${formattedVersion}`;
}, [formattedVersion]);
2018-04-12 15:09:04 -03:00
return ReactDOM.createPortal(
<a
href={`https://github.com/prettier/prettier/${href}`}
target="_blank"
2019-06-12 22:40:05 +08:00
rel="noreferrer noopener"
2018-04-12 15:09:04 -03:00
>
{formattedVersion}
2018-04-12 15:09:04 -03:00
</a>,
root
);
}