Some checks failed
Build and Release / Create Release (push) Has been skipped
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 1m31s
Build and Release / Lint (push) Failing after 1m54s
Build and Release / Build Binaries (amd64, darwin) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux) (push) Has been skipped
Build and Release / Build Binaries (amd64, windows) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 1m59s
- Show full URL instead of just subdomain - Make it a clickable hyperlink with target=_blank - Use setting.Domain for proper URL construction
145 lines
4.1 KiB
Go
145 lines
4.1 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package setting
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/modules/templates"
|
|
"code.gitea.io/gitea/services/context"
|
|
pages_service "code.gitea.io/gitea/services/pages"
|
|
)
|
|
|
|
const tplRepoSettingsPages templates.TplName = "repo/settings/pages"
|
|
|
|
// Pages shows the repository pages settings
|
|
func Pages(ctx *context.Context) {
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.pages")
|
|
ctx.Data["PageIsSettingsPages"] = true
|
|
|
|
// Get pages config
|
|
config, err := repo_model.GetPagesConfig(ctx, ctx.Repo.Repository.ID)
|
|
if err != nil && !repo_model.IsErrPagesConfigNotExist(err) {
|
|
ctx.ServerError("GetPagesConfig", err)
|
|
return
|
|
}
|
|
|
|
if config != nil {
|
|
ctx.Data["PagesEnabled"] = config.Enabled
|
|
ctx.Data["PagesTemplate"] = config.Template
|
|
}
|
|
|
|
// Get pages domains
|
|
domains, err := repo_model.GetPagesDomains(ctx, ctx.Repo.Repository.ID)
|
|
if err != nil {
|
|
ctx.ServerError("GetPagesDomains", err)
|
|
return
|
|
}
|
|
ctx.Data["PagesDomains"] = domains
|
|
|
|
// Generate subdomain
|
|
ctx.Data["PagesSubdomain"] = pages_service.GetPagesSubdomain(ctx.Repo.Repository)
|
|
ctx.Data["PagesURL"] = pages_service.GetPagesURL(ctx.Repo.Repository)
|
|
|
|
// Available templates
|
|
ctx.Data["PagesTemplates"] = []string{"simple", "documentation", "product", "portfolio"}
|
|
|
|
ctx.HTML(http.StatusOK, tplRepoSettingsPages)
|
|
}
|
|
|
|
// PagesPost handles the pages settings form submission
|
|
func PagesPost(ctx *context.Context) {
|
|
ctx.Data["Title"] = ctx.Tr("repo.settings.pages")
|
|
ctx.Data["PageIsSettingsPages"] = true
|
|
|
|
action := ctx.FormString("action")
|
|
|
|
switch action {
|
|
case "enable":
|
|
template := ctx.FormString("template")
|
|
if template == "" {
|
|
template = "simple"
|
|
}
|
|
if err := pages_service.EnablePages(ctx, ctx.Repo.Repository, template); err != nil {
|
|
ctx.ServerError("EnablePages", err)
|
|
return
|
|
}
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.pages.enabled_success"))
|
|
|
|
case "disable":
|
|
if err := pages_service.DisablePages(ctx, ctx.Repo.Repository); err != nil {
|
|
ctx.ServerError("DisablePages", err)
|
|
return
|
|
}
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.pages.disabled_success"))
|
|
|
|
case "update_template":
|
|
template := ctx.FormString("template")
|
|
if template == "" {
|
|
template = "simple"
|
|
}
|
|
if err := pages_service.EnablePages(ctx, ctx.Repo.Repository, template); err != nil {
|
|
ctx.ServerError("EnablePages", err)
|
|
return
|
|
}
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success"))
|
|
|
|
case "add_domain":
|
|
domain := ctx.FormString("domain")
|
|
if domain == "" {
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.pages.domain_required"))
|
|
ctx.Redirect(ctx.Repo.Repository.Link() + "/settings/pages")
|
|
return
|
|
}
|
|
sslExternal := ctx.FormBool("ssl_external")
|
|
_, err := pages_service.AddPagesDomain(ctx, ctx.Repo.Repository.ID, domain, sslExternal)
|
|
if err != nil {
|
|
if repo_model.IsErrPagesDomainAlreadyExist(err) {
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.pages.domain_exists"))
|
|
} else {
|
|
ctx.ServerError("AddPagesDomain", err)
|
|
return
|
|
}
|
|
} else {
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.pages.domain_added"))
|
|
}
|
|
|
|
case "delete_domain":
|
|
domainID := ctx.FormInt64("domain_id")
|
|
if err := repo_model.DeletePagesDomain(ctx, domainID); err != nil {
|
|
ctx.ServerError("DeletePagesDomain", err)
|
|
return
|
|
}
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.pages.domain_deleted"))
|
|
|
|
case "activate_ssl":
|
|
domainID := ctx.FormInt64("domain_id")
|
|
if err := repo_model.ActivatePagesDomainSSL(ctx, domainID); err != nil {
|
|
ctx.ServerError("ActivatePagesDomainSSL", err)
|
|
return
|
|
}
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.pages.ssl_activated"))
|
|
|
|
case "verify_domain":
|
|
domainID := ctx.FormInt64("domain_id")
|
|
if err := pages_service.VerifyDomain(ctx, domainID); err != nil {
|
|
if err.Error() == "DNS verification failed" {
|
|
ctx.Flash.Error(ctx.Tr("repo.settings.pages.domain_verification_failed"))
|
|
} else {
|
|
ctx.ServerError("VerifyDomain", err)
|
|
return
|
|
}
|
|
} else {
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.pages.domain_verified"))
|
|
}
|
|
|
|
default:
|
|
ctx.NotFound(nil)
|
|
return
|
|
}
|
|
|
|
ctx.Redirect(ctx.Repo.Repository.Link() + "/settings/pages")
|
|
}
|