mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 12:25:22 +00:00
Fix broken file links (#161)
This commit is contained in:
parent
a013298955
commit
7d516b1420
2 changed files with 23 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed issue where we crash on startup if the install / upgrade PostHog event fails to send. ([#159](https://github.com/sourcebot-dev/sourcebot/pull/159))
|
- Fixed issue where we crash on startup if the install / upgrade PostHog event fails to send. ([#159](https://github.com/sourcebot-dev/sourcebot/pull/159))
|
||||||
|
- Fixed issue with broken file links. ([#161](https://github.com/sourcebot-dev/sourcebot/pull/161))
|
||||||
|
|
||||||
## [2.7.0] - 2025-01-10
|
## [2.7.0] - 2025-01-10
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,30 @@ export const CodePreviewPanel = ({
|
||||||
.then(({ source }) => {
|
.then(({ source }) => {
|
||||||
const link = (() => {
|
const link = (() => {
|
||||||
const template = repoUrlTemplates[fileMatch.Repository];
|
const template = repoUrlTemplates[fileMatch.Repository];
|
||||||
if (!template) {
|
|
||||||
|
// This is a hacky parser for templates generated by
|
||||||
|
// the go text/template package. Example template:
|
||||||
|
// {{URLJoinPath "https://github.com/sourcebot-dev/sourcebot" "blob" .Version .Path}}
|
||||||
|
// @see: https://pkg.go.dev/text/template
|
||||||
|
if (!template || !template.match(/^{{URLJoinPath\s.*}}(\?.+)?$/)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return template
|
|
||||||
.replace("{{.Version}}", branch ?? "HEAD")
|
const url =
|
||||||
.replace("{{.Path}}", fileMatch.FileName);
|
template.substring("{{URLJoinPath ".length,template.indexOf("}}"))
|
||||||
|
.replace(".Version", branch ?? "HEAD")
|
||||||
|
.replace(".Path", fileMatch.FileName)
|
||||||
|
.split(" ")
|
||||||
|
.map((part) => {
|
||||||
|
// remove wrapping quotes
|
||||||
|
if (part.startsWith("\"")) part = part.substring(1);
|
||||||
|
if (part.endsWith("\"")) part = part.substring(0, part.length - 1);
|
||||||
|
return part;
|
||||||
|
})
|
||||||
|
.join("/");
|
||||||
|
|
||||||
|
const optionalQueryParams = template.substring(template.indexOf("}}") + 2);
|
||||||
|
return url + optionalQueryParams;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const decodedSource = base64Decode(source);
|
const decodedSource = base64Decode(source);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue