mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
79 lines
2.5 KiB
Go
79 lines
2.5 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package renderhelper
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path"
|
|
|
|
repo_model "github.com/hanzoai/git/models/repo"
|
|
"github.com/hanzoai/git/modules/markup"
|
|
"github.com/hanzoai/git/modules/markup/markdown"
|
|
"github.com/hanzoai/git/modules/util"
|
|
)
|
|
|
|
type RepoWiki struct {
|
|
ctx *markup.RenderContext
|
|
opts RepoWikiOptions
|
|
|
|
commitChecker *commitChecker
|
|
repoLink string
|
|
}
|
|
|
|
func (r *RepoWiki) CleanUp() {
|
|
_ = r.commitChecker.Close()
|
|
}
|
|
|
|
func (r *RepoWiki) IsCommitIDExisting(commitID string) bool {
|
|
return r.commitChecker.IsCommitIDExisting(commitID)
|
|
}
|
|
|
|
func (r *RepoWiki) ResolveLink(link, preferLinkType string) (finalLink string) {
|
|
linkType, link := markup.ParseRenderedLink(link, preferLinkType)
|
|
switch linkType {
|
|
case markup.LinkTypeRoot:
|
|
finalLink = r.ctx.ResolveLinkRoot(link)
|
|
case markup.LinkTypeMedia, markup.LinkTypeRaw:
|
|
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "wiki/raw", r.opts.currentRefSubURL), r.opts.currentTreePath, link)
|
|
default:
|
|
finalLink = r.ctx.ResolveLinkRelative(path.Join(r.repoLink, "wiki", r.opts.currentRefSubURL), r.opts.currentTreePath, link)
|
|
}
|
|
return finalLink
|
|
}
|
|
|
|
var _ markup.RenderHelper = (*RepoWiki)(nil)
|
|
|
|
type RepoWikiOptions struct {
|
|
DeprecatedRepoName string // it is only a patch for the non-standard "markup" api
|
|
DeprecatedOwnerName string // it is only a patch for the non-standard "markup" api
|
|
|
|
// these options are not used at the moment because Wiki doesn't support sub-path, nor branch
|
|
currentRefSubURL string // eg: "branch/main"
|
|
currentTreePath string // eg: "path/to/file" in the repo
|
|
}
|
|
|
|
func NewRenderContextRepoWiki(ctx context.Context, repo *repo_model.Repository, opts ...RepoWikiOptions) *markup.RenderContext {
|
|
helper := &RepoWiki{opts: util.OptionalArg(opts)}
|
|
rctx := markup.NewRenderContext(ctx).WithMarkupType(markdown.MarkupName)
|
|
if repo != nil {
|
|
helper.repoLink = repo.Link()
|
|
helper.commitChecker = newCommitChecker(ctx, repo)
|
|
rctx = rctx.WithMetas(repo.ComposeWikiMetas(ctx))
|
|
} else {
|
|
// this is almost dead code, only to pass the incorrect tests
|
|
helper.repoLink = fmt.Sprintf("%s/%s", helper.opts.DeprecatedOwnerName, helper.opts.DeprecatedRepoName)
|
|
rctx = rctx.WithMetas(map[string]string{
|
|
"user": helper.opts.DeprecatedOwnerName,
|
|
"repo": helper.opts.DeprecatedRepoName,
|
|
|
|
"markupAllowShortIssuePattern": "true",
|
|
})
|
|
}
|
|
rctx = rctx.WithHelper(helper).WithEnableHeadingIDGeneration(true)
|
|
helper.ctx = rctx
|
|
return rctx
|
|
}
|