Commit 50d81f2
Eric Bower
·
2023-08-11 14:30:04 -0400 EDT
parent e93b271
fix: use commit for refs in url
1 files changed,
+19,
-23
M
main.go
M
main.go
+19,
-23
| ... | ... | @@ -283,7 +283,7 @@ func readmeFile(repo *Config) string { | |
| 283 | 283 | return strings.ToLower(repo.Readme) | |
| 284 | 284 | } | |
| 285 | 285 | ||
| 286 | - | func walkTree(tree *git.Tree, branch string, curpath string, aggregate []*TreeItem) []*TreeItem { | |
| 286 | + | func walkTree(tree *git.Tree, commitID string, curpath string, aggregate []*TreeItem) []*TreeItem { | |
| 287 | 287 | entries, err := tree.Entries() | |
| 288 | 288 | bail(err) | |
| 289 | 289 |
| ... | ... | @@ -292,7 +292,7 @@ func walkTree(tree *git.Tree, branch string, curpath string, aggregate []*TreeIt | |
| 292 | 292 | typ := entry.Type() | |
| 293 | 293 | if typ == git.ObjectTree { | |
| 294 | 294 | re, _ := tree.Subtree(entry.Name()) | |
| 295 | - | aggregate = walkTree(re, branch, fname, aggregate) | |
| 295 | + | aggregate = walkTree(re, commitID, fname, aggregate) | |
| 296 | 296 | } | |
| 297 | 297 | ||
| 298 | 298 | if entry.Type() == git.ObjectBlob { |
| ... | ... | @@ -300,7 +300,7 @@ func walkTree(tree *git.Tree, branch string, curpath string, aggregate []*TreeIt | |
| 300 | 300 | Size: toPretty(entry.Size()), | |
| 301 | 301 | Path: fname, | |
| 302 | 302 | Entry: entry, | |
| 303 | - | URL: template.URL(filepath.Join("/", "tree", branch, "item", fname)), | |
| 303 | + | URL: template.URL(filepath.Join("/", "tree", commitID, "item", fname)), | |
| 304 | 304 | }) | |
| 305 | 305 | } | |
| 306 | 306 | } |
| ... | ... | @@ -415,7 +415,7 @@ func (c *Config) writeHTMLTreeFiles(pageData *PageData, tree []*TreeItem) string | |
| 415 | 415 | Contents: template.HTML(contents), | |
| 416 | 416 | Path: file.Path, | |
| 417 | 417 | }, | |
| 418 | - | Subdir: filepath.Join("tree", pageData.RevData.RevName, "item", d), | |
| 418 | + | Subdir: filepath.Join("tree", getShortID(pageData.RevData.ID), "item", d), | |
| 419 | 419 | }) | |
| 420 | 420 | } | |
| 421 | 421 | return readme |
| ... | ... | @@ -504,27 +504,22 @@ func (c *Config) writeLogDiffs(repo *git.Repository, pageData *PageData, logs [] | |
| 504 | 504 | } | |
| 505 | 505 | } | |
| 506 | 506 | ||
| 507 | - | func (c *Config) getCloneURL() template.URL { | |
| 508 | - | url := fmt.Sprintf("https://%s/%s.git", c.CloneURL, c.RepoName) | |
| 509 | - | return template.URL(url) | |
| 510 | - | } | |
| 511 | - | ||
| 512 | - | func (c *Config) getSummaryUrl() template.URL { | |
| 507 | + | func (c *Config) getSummaryURL() template.URL { | |
| 513 | 508 | url := fmt.Sprintf("/%s/index.html", c.RepoName) | |
| 514 | 509 | return template.URL(url) | |
| 515 | 510 | } | |
| 516 | 511 | ||
| 517 | - | func (c *Config) getRefsUrl() template.URL { | |
| 512 | + | func (c *Config) getRefsURL() template.URL { | |
| 518 | 513 | url := fmt.Sprintf("/%s/refs.html", c.RepoName) | |
| 519 | 514 | return template.URL(url) | |
| 520 | 515 | } | |
| 521 | 516 | ||
| 522 | - | func (c *Config) getTreeUrl(revn string) template.URL { | |
| 517 | + | func (c *Config) getTreeURL(revn string) template.URL { | |
| 523 | 518 | url := fmt.Sprintf("/%s/tree/%s/index.html", c.RepoName, revn) | |
| 524 | 519 | return template.URL(url) | |
| 525 | 520 | } | |
| 526 | 521 | ||
| 527 | - | func (c *Config) getLogsUrl(revn string) template.URL { | |
| 522 | + | func (c *Config) getLogsURL(revn string) template.URL { | |
| 528 | 523 | url := fmt.Sprintf("/%s/logs/%s/index.html", c.RepoName, revn) | |
| 529 | 524 | return template.URL(url) | |
| 530 | 525 | } |
| ... | ... | @@ -538,8 +533,8 @@ func (c *Config) getURLs() *SiteURLs { | |
| 538 | 533 | return &SiteURLs{ | |
| 539 | 534 | RootURL: c.HomeUrl, | |
| 540 | 535 | CloneURL: c.CloneURL, | |
| 541 | - | RefsURL: c.getRefsUrl(), | |
| 542 | - | SummaryURL: c.getSummaryUrl(), | |
| 536 | + | RefsURL: c.getRefsURL(), | |
| 537 | + | SummaryURL: c.getSummaryURL(), | |
| 543 | 538 | } | |
| 544 | 539 | } | |
| 545 | 540 |
| ... | ... | @@ -572,8 +567,8 @@ func (c *Config) writeRepo() *BranchOutput { | |
| 572 | 567 | data := &RevData{ | |
| 573 | 568 | ID: fullRevID, | |
| 574 | 569 | RevName: revName, | |
| 575 | - | TreeURL: c.getTreeUrl(revName), | |
| 576 | - | LogURL: c.getLogsUrl(revName), | |
| 570 | + | TreeURL: c.getTreeURL(revName), | |
| 571 | + | LogURL: c.getLogsURL(revName), | |
| 577 | 572 | } | |
| 578 | 573 | if first == nil { | |
| 579 | 574 | first = data |
| ... | ... | @@ -643,8 +638,8 @@ func (c *Config) writeRepo() *BranchOutput { | |
| 643 | 638 | // use the first revision in our list to generate | |
| 644 | 639 | // the root summary, logs, and tree the user can click | |
| 645 | 640 | revData := &RevData{ | |
| 646 | - | TreeURL: c.getTreeUrl(first.RevName), | |
| 647 | - | LogURL: c.getLogsUrl(first.RevName), | |
| 641 | + | TreeURL: c.getTreeURL(getShortID(first.ID)), | |
| 642 | + | LogURL: c.getLogsURL(getShortID(first.ID)), | |
| 648 | 643 | RevName: first.RevName, | |
| 649 | 644 | } | |
| 650 | 645 |
| ... | ... | @@ -702,7 +697,7 @@ func (c *Config) writeRevision(repo *git.Repository, pageData *PageData, refs [] | |
| 702 | 697 | bail(err) | |
| 703 | 698 | ||
| 704 | 699 | entries := []*TreeItem{} | |
| 705 | - | treeEntries := walkTree(tree, pageData.RevData.RevName, "", entries) | |
| 700 | + | treeEntries := walkTree(tree, getShortID(pageData.RevData.ID), "", entries) | |
| 706 | 701 | for _, entry := range treeEntries { | |
| 707 | 702 | entry.Path = strings.TrimPrefix(entry.Path, "/") | |
| 708 | 703 |
| ... | ... | @@ -725,14 +720,15 @@ func (c *Config) writeRevision(repo *git.Repository, pageData *PageData, refs [] | |
| 725 | 720 | entry.Summary = lc.Summary() | |
| 726 | 721 | entry.When = lc.Author.When.Format(time.RFC822) | |
| 727 | 722 | } | |
| 728 | - | entry.URL = template.URL(filepath.Join( | |
| 723 | + | fpath := filepath.Join( | |
| 729 | 724 | "/", | |
| 730 | 725 | c.RepoName, | |
| 731 | 726 | "tree", | |
| 732 | - | pageData.RevData.RevName, | |
| 727 | + | getShortID(pageData.RevData.ID), | |
| 733 | 728 | "item", | |
| 734 | 729 | fmt.Sprintf("%s.html", entry.Path), | |
| 735 | - | )) | |
| 730 | + | ) | |
| 731 | + | entry.URL = template.URL(fpath) | |
| 736 | 732 | } | |
| 737 | 733 | ||
| 738 | 734 | c.Logger.Infof( |