mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 20:35:24 +00:00
cherry pick fix for file links
This commit is contained in:
parent
b9352345a3
commit
1bdb65c34e
1 changed files with 21 additions and 4 deletions
|
|
@ -43,12 +43,29 @@ export const CodePreviewPanel = ({
|
|||
.then(({ source }) => {
|
||||
const link = (() => {
|
||||
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 template
|
||||
.replace("{{.Version}}", branch ?? "HEAD")
|
||||
.replace("{{.Path}}", fileMatch.FileName);
|
||||
const url =
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue