This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/basepath
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/feat/basepath by this push:
     new c6d43e92 feat(base): add base path for ui page
c6d43e92 is described below

commit c6d43e92c196c7d74de13424210bc1f9bbf9c261
Author: LinkinStars <[email protected]>
AuthorDate: Wed Apr 24 15:31:03 2024 +0800

    feat(base): add base path for ui page
---
 cmd/main.go                                |  2 +-
 cmd/wire.go                                |  1 +
 cmd/wire_gen.go                            | 28 ++++------------------------
 internal/base/conf/conf.go                 |  1 +
 internal/base/server/config.go             |  5 +++++
 internal/base/server/http.go               |  5 +++--
 internal/controller/template_controller.go |  5 +++++
 internal/install/install_req.go            |  4 ++++
 internal/install/install_server.go         | 16 ++++++++++++----
 internal/router/template_router.go         | 16 ++++++++--------
 internal/router/ui.go                      | 10 +++++++---
 internal/schema/siteinfo_schema.go         |  5 +++++
 ui/template/404.html                       |  2 +-
 ui/template/comment.html                   |  2 +-
 ui/template/header.html                    | 10 +++++-----
 ui/template/homepage.html                  |  4 ++--
 ui/template/question-detail.html           | 20 ++++++++++----------
 ui/template/question.html                  |  8 ++++----
 ui/template/sidenav.html                   |  4 ++--
 ui/template/tag-detail.html                | 10 +++++-----
 ui/template/tags.html                      |  2 +-
 21 files changed, 87 insertions(+), 73 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go
index ec7413a0..20cdf0f5 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -72,7 +72,7 @@ func runApp() {
                panic(err)
        }
        app, cleanup, err := initApplication(
-               c.Debug, c.Server, c.Data.Database, c.Data.Cache, c.I18n, 
c.Swaggerui, c.ServiceConfig, log.GetLogger())
+               c.Debug, c.Server, c.Data.Database, c.Data.Cache, c.I18n, 
c.Swaggerui, c.ServiceConfig, c.UI, log.GetLogger())
        if err != nil {
                panic(err)
        }
diff --git a/cmd/wire.go b/cmd/wire.go
index 0f12f7dc..8d12f5d2 100644
--- a/cmd/wire.go
+++ b/cmd/wire.go
@@ -52,6 +52,7 @@ func initApplication(
        i18nConf *translator.I18n,
        swaggerConf *router.SwaggerConfig,
        serviceConf *service_config.ServiceConfig,
+       uiConf *server.UI,
        logConf log.Logger) (*pacman.Application, func(), error) {
        panic(wire.Build(
                server.ProviderSetServer,
diff --git a/cmd/wire_gen.go b/cmd/wire_gen.go
index 7ed904d0..7d899098 100644
--- a/cmd/wire_gen.go
+++ b/cmd/wire_gen.go
@@ -1,28 +1,8 @@
-//go:build !wireinject
-// +build !wireinject
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
 // Code generated by Wire. DO NOT EDIT.
 
 //go:generate go run github.com/google/wire/cmd/wire
+//go:build !wireinject
+// +build !wireinject
 
 package answercmd
 
@@ -112,7 +92,7 @@ import (
 // Injectors from wire.go:
 
 // initApplication init application.
-func initApplication(debug bool, serverConf *conf.Server, dbConf 
*data.Database, cacheConf *data.CacheConf, i18nConf *translator.I18n, 
swaggerConf *router.SwaggerConfig, serviceConf *service_config.ServiceConfig, 
logConf log.Logger) (*pacman.Application, func(), error) {
+func initApplication(debug bool, serverConf *conf.Server, dbConf 
*data.Database, cacheConf *data.CacheConf, i18nConf *translator.I18n, 
swaggerConf *router.SwaggerConfig, serviceConf *service_config.ServiceConfig, 
uiConf *server.UI, logConf log.Logger) (*pacman.Application, func(), error) {
        staticRouter := router.NewStaticRouter(serviceConf)
        i18nTranslator, err := translator.NewTranslator(i18nConf)
        if err != nil {
@@ -263,7 +243,7 @@ func initApplication(debug bool, serverConf *conf.Server, 
dbConf *data.Database,
        userCenterLoginService := 
user_external_login2.NewUserCenterLoginService(userRepo, userCommon, 
userExternalLoginRepo, userActiveActivityRepo, siteInfoCommonService)
        userCenterController := 
controller.NewUserCenterController(userCenterLoginService, 
siteInfoCommonService)
        pluginAPIRouter := router.NewPluginAPIRouter(connectorController, 
userCenterController)
-       ginEngine := server.NewHTTPServer(debug, staticRouter, answerAPIRouter, 
swaggerRouter, uiRouter, authUserMiddleware, avatarMiddleware, 
shortIDMiddleware, templateRouter, pluginAPIRouter)
+       ginEngine := server.NewHTTPServer(debug, staticRouter, answerAPIRouter, 
swaggerRouter, uiRouter, authUserMiddleware, avatarMiddleware, 
shortIDMiddleware, templateRouter, pluginAPIRouter, uiConf)
        scheduledTaskManager := 
cron.NewScheduledTaskManager(siteInfoCommonService, questionService)
        application := newApplication(serverConf, ginEngine, 
scheduledTaskManager)
        return application, func() {
diff --git a/internal/base/conf/conf.go b/internal/base/conf/conf.go
index eaf6d8ce..17090d4b 100644
--- a/internal/base/conf/conf.go
+++ b/internal/base/conf/conf.go
@@ -42,6 +42,7 @@ type AllConfig struct {
        I18n          *translator.I18n              `json:"i18n" 
mapstructure:"i18n" yaml:"i18n"`
        ServiceConfig *service_config.ServiceConfig `json:"service_config" 
mapstructure:"service_config" yaml:"service_config"`
        Swaggerui     *router.SwaggerConfig         `json:"swaggerui" 
mapstructure:"swaggerui" yaml:"swaggerui"`
+       UI            *server.UI                    `json:"ui" 
mapstructure:"ui" yaml:"ui"`
 }
 
 type PathIgnore struct {
diff --git a/internal/base/server/config.go b/internal/base/server/config.go
index 7041f889..baf6fb77 100644
--- a/internal/base/server/config.go
+++ b/internal/base/server/config.go
@@ -23,3 +23,8 @@ package server
 type HTTP struct {
        Addr string `json:"addr" mapstructure:"addr"`
 }
+
+// UI ui config
+type UI struct {
+       BaseURL string `json:"base_url" mapstructure:"base_url" yaml:"base_url"`
+}
diff --git a/internal/base/server/http.go b/internal/base/server/http.go
index daaf90fb..b45991a1 100644
--- a/internal/base/server/http.go
+++ b/internal/base/server/http.go
@@ -42,6 +42,7 @@ func NewHTTPServer(debug bool,
        shortIDMiddleware *middleware.ShortIDMiddleware,
        templateRouter *router.TemplateRouter,
        pluginAPIRouter *router.PluginAPIRouter,
+       uiConf *UI,
 ) *gin.Engine {
 
        if debug {
@@ -57,7 +58,7 @@ func NewHTTPServer(debug bool,
        htmlTemplate := 
template.Must(template.New("").Funcs(funcMap).ParseFS(html, "*"))
        r.SetHTMLTemplate(htmlTemplate)
        r.Use(middleware.HeadersByRequestURI())
-       viewRouter.Register(r)
+       viewRouter.Register(r, uiConf.BaseURL)
 
        rootGroup := r.Group("")
        swaggerRouter.Register(rootGroup)
@@ -88,7 +89,7 @@ func NewHTTPServer(debug bool,
        adminauthV1.Use(authUserMiddleware.AdminAuth())
        answerRouter.RegisterAnswerAdminAPIRouter(adminauthV1)
 
-       templateRouter.RegisterTemplateRouter(rootGroup)
+       templateRouter.RegisterTemplateRouter(rootGroup, uiConf.BaseURL)
 
        // plugin routes
        pluginAPIRouter.RegisterUnAuthConnectorRouter(mustUnAuthV1)
diff --git a/internal/controller/template_controller.go 
b/internal/controller/template_controller.go
index b128b91a..a3a4ab71 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -24,6 +24,7 @@ import (
        "fmt"
        "html/template"
        "net/http"
+       "net/url"
        "regexp"
        "strings"
        "time"
@@ -495,6 +496,10 @@ func (tc *TemplateController) Page404(ctx *gin.Context) {
 
 func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, 
siteInfo *schema.TemplateSiteInfoResp, data gin.H) {
        data["siteinfo"] = siteInfo
+       data["baseURL"] = ""
+       if parsedUrl, err := url.Parse(siteInfo.General.SiteUrl); err == nil {
+               data["baseURL"] = parsedUrl.Path
+       }
        data["scriptPath"] = tc.scriptPath
        data["cssPath"] = tc.cssPath
        data["keywords"] = siteInfo.Keywords
diff --git a/internal/install/install_req.go b/internal/install/install_req.go
index 83a36fd1..9863dadd 100644
--- a/internal/install/install_req.go
+++ b/internal/install/install_req.go
@@ -124,4 +124,8 @@ func (r *InitBaseInfoReq) FormatSiteUrl() {
                return
        }
        r.SiteURL = fmt.Sprintf("%s://%s", parsedUrl.Scheme, parsedUrl.Host)
+       if len(parsedUrl.Path) > 0 {
+               r.SiteURL = r.SiteURL + parsedUrl.Path
+               r.SiteURL = strings.TrimSuffix(r.SiteURL, "/")
+       }
 }
diff --git a/internal/install/install_server.go 
b/internal/install/install_server.go
index b628f2fe..f6087fea 100644
--- a/internal/install/install_server.go
+++ b/internal/install/install_server.go
@@ -25,9 +25,12 @@ import (
        "io/fs"
        "net/http"
 
+       "github.com/apache/incubator-answer/configs"
+       "github.com/apache/incubator-answer/internal/base/conf"
        "github.com/apache/incubator-answer/ui"
        "github.com/gin-gonic/gin"
        "github.com/segmentfault/pacman/log"
+       "gopkg.in/yaml.v3"
 )
 
 const UIStaticPath = "build/static"
@@ -47,15 +50,20 @@ func (r *_resource) Open(name string) (fs.File, error) {
 func NewInstallHTTPServer() *gin.Engine {
        gin.SetMode(gin.ReleaseMode)
        r := gin.New()
+
+       c := &conf.AllConfig{}
+       _ = yaml.Unmarshal(configs.Config, c)
+
        r.GET("/healthz", func(ctx *gin.Context) { ctx.String(200, "OK") })
-       r.StaticFS("/static", http.FS(&_resource{
+       r.StaticFS(c.UI.BaseURL+"/static", http.FS(&_resource{
                fs: ui.Build,
        }))
 
+       // read default config file and extract ui config
        installApi := r.Group("")
-       installApi.GET("/", CheckConfigFileAndRedirectToInstallPage)
-       installApi.GET("/install", WebPage)
-       installApi.GET("/50x", WebPage)
+       installApi.GET(c.UI.BaseURL+"/", 
CheckConfigFileAndRedirectToInstallPage)
+       installApi.GET(c.UI.BaseURL+"/install", WebPage)
+       installApi.GET(c.UI.BaseURL+"/50x", WebPage)
        installApi.GET("/installation/language/options", LangOptions)
        installApi.POST("/installation/db/check", CheckDatabase)
        installApi.POST("/installation/config-file/check", CheckConfigFile)
diff --git a/internal/router/template_router.go 
b/internal/router/template_router.go
index c8bf4b22..01e8b307 100644
--- a/internal/router/template_router.go
+++ b/internal/router/template_router.go
@@ -50,17 +50,17 @@ func NewTemplateRouter(
 }
 
 // RegisterTemplateRouter template router
-func (a *TemplateRouter) RegisterTemplateRouter(r *gin.RouterGroup) {
-       r.GET("/sitemap.xml", a.templateController.Sitemap)
-       r.GET("/sitemap/:page", a.templateController.SitemapPage)
+func (a *TemplateRouter) RegisterTemplateRouter(r *gin.RouterGroup, 
baseURLPath string) {
+       seoNoAuth := r.Group(baseURLPath)
+       seoNoAuth.GET("/sitemap.xml", a.templateController.Sitemap)
+       seoNoAuth.GET("/sitemap/:page", a.templateController.SitemapPage)
 
-       r.GET("/robots.txt", a.siteInfoController.GetRobots)
-       r.GET("/custom.css", a.siteInfoController.GetCss)
+       seoNoAuth.GET("/robots.txt", a.siteInfoController.GetRobots)
+       seoNoAuth.GET("/custom.css", a.siteInfoController.GetCss)
 
-       r.GET("/404", a.templateController.Page404)
+       seoNoAuth.GET("/404", a.templateController.Page404)
 
-       //todo add middleware
-       seo := r.Group("")
+       seo := r.Group(baseURLPath)
        seo.Use(a.authUserMiddleware.CheckPrivateMode())
        seo.GET("/", a.templateController.Index)
        seo.GET("/questions", a.templateController.QuestionList)
diff --git a/internal/router/ui.go b/internal/router/ui.go
index 60894500..e12e1dc9 100644
--- a/internal/router/ui.go
+++ b/internal/router/ui.go
@@ -25,6 +25,7 @@ import (
        "io/fs"
        "net/http"
        "os"
+       "strings"
 
        "github.com/apache/incubator-answer/internal/controller"
        "github.com/apache/incubator-answer/internal/service/siteinfo_common"
@@ -68,7 +69,7 @@ func (r *_resource) Open(name string) (fs.File, error) {
 }
 
 // Register a new static resource which generated by ui directory
-func (a *UIRouter) Register(r *gin.Engine) {
+func (a *UIRouter) Register(r *gin.Engine, baseURLPath string) {
        staticPath := os.Getenv("ANSWER_STATIC_PATH")
 
        // if ANSWER_STATIC_PATH is set and not empty, ignore embed resource
@@ -81,7 +82,7 @@ func (a *UIRouter) Register(r *gin.Engine) {
                        log.Debugf("registering static path %s", staticPath)
 
                        r.LoadHTMLGlob(staticPath + "/*.html")
-                       r.Static("/static", staticPath+"/static")
+                       r.Static(baseURLPath+"/static", staticPath+"/static")
                        r.NoRoute(func(c *gin.Context) {
                                c.HTML(http.StatusOK, "index.html", gin.H{})
                        })
@@ -92,13 +93,16 @@ func (a *UIRouter) Register(r *gin.Engine) {
        }
 
        // handle the static file by default ui static files
-       r.StaticFS("/static", http.FS(&_resource{
+       r.StaticFS(baseURLPath+"/static", http.FS(&_resource{
                fs: ui.Build,
        }))
 
        // specify the not router for default routes and redirect
        r.NoRoute(func(c *gin.Context) {
                urlPath := c.Request.URL.Path
+               if len(baseURLPath) > 0 {
+                       urlPath = strings.TrimPrefix(urlPath, baseURLPath)
+               }
                filePath := ""
                switch urlPath {
                case "/favicon.ico":
diff --git a/internal/schema/siteinfo_schema.go 
b/internal/schema/siteinfo_schema.go
index ea19d046..88b7dc7c 100644
--- a/internal/schema/siteinfo_schema.go
+++ b/internal/schema/siteinfo_schema.go
@@ -24,6 +24,7 @@ import (
        "fmt"
        "net/mail"
        "net/url"
+       "strings"
 
        "github.com/apache/incubator-answer/internal/base/constant"
        "github.com/apache/incubator-answer/internal/base/handler"
@@ -49,6 +50,10 @@ func (r *SiteGeneralReq) FormatSiteUrl() {
                return
        }
        r.SiteUrl = fmt.Sprintf("%s://%s", parsedUrl.Scheme, parsedUrl.Host)
+       if len(parsedUrl.Path) > 0 {
+               r.SiteUrl = r.SiteUrl + parsedUrl.Path
+               r.SiteUrl = strings.TrimSuffix(r.SiteUrl, "/")
+       }
 }
 
 // SiteInterfaceReq site interface request
diff --git a/ui/template/404.html b/ui/template/404.html
index 6a39e641..6f252672 100644
--- a/ui/template/404.html
+++ b/ui/template/404.html
@@ -22,7 +22,7 @@
             <div class="d-flex flex-column justify-content-center 
align-items-center page-wrap container">
                 <div class="mb-4 text-secondary" style="font-size: 120px; 
line-height: 1.2;">(=‘x‘=)</div>
                 <div class="text-center mb-4">Unfortunately, this page doesn't 
exist.</div>
-                <div class="text-center"><a role="button" tabindex="0" 
href="/" class="btn btn-link">Back to
+                <div class="text-center"><a role="button" tabindex="0" 
href="{{$.baseURL}}/" class="btn btn-link">Back to
                         homepage</a></div>
             </div>
 
diff --git a/ui/template/comment.html b/ui/template/comment.html
index 6e5b7bc3..9aa1c4da 100644
--- a/ui/template/comment.html
+++ b/ui/template/comment.html
@@ -28,7 +28,7 @@
   </div>
   <div class="d-flex justify-content-between small">
     <div class="d-flex align-items-center link-secondary">
-      <a href="/users/{{.Username}}">{{.UserDisplayName}}</a><span
+      <a href="{{$.baseURL}}/users/{{.Username}}">{{.UserDisplayName}}</a><span
       class="mx-1">•</span>
       <time
         class="me-3"
diff --git a/ui/template/header.html b/ui/template/header.html
index 75c696f9..c956bb70 100644
--- a/ui/template/header.html
+++ b/ui/template/header.html
@@ -32,13 +32,13 @@
     {{if .noindex }}<meta name="robots" content="noindex">{{end}}
 
     <link rel="canonical" href="{{.siteinfo.Canonical}}" />
-    <link rel="manifest" href="/manifest.json" />
+    <link rel="manifest" href="{{$.baseURL}}/manifest.json" />
     <link href="{{.cssPath}}" rel="stylesheet" />
-    <link href="/custom.css" rel="stylesheet" />
+    <link href="{{$.baseURL}}/custom.css" rel="stylesheet" />
     <link
       rel="icon"
       type="image/png"
-      href="{{if $.siteinfo.Branding.Favicon 
}}{{$.siteinfo.Branding.Favicon}}{{else}}/favicon.ico{{end}}"
+      href="{{if $.siteinfo.Branding.Favicon 
}}{{$.siteinfo.Branding.Favicon}}{{else}}{{$.baseURL}}/favicon.ico{{end}}"
       data-rh="true"
     />
     <link
@@ -133,11 +133,11 @@
             class="d-flex justify-content-between align-items-center nav-grow 
flex-nowrap"
           >
             {{if .siteinfo.Branding.Logo}}
-              <a class="lh-1 me-0 me-sm-5 p-0 navbar-brand" href="/">
+              <a class="lh-1 me-0 me-sm-5 p-0 navbar-brand" 
href="{{$.baseURL}}/">
                 <img class="logo me-0" src="{{.siteinfo.Branding.Logo}}" 
alt="{{.siteinfo.General.Name}}">
               </a>
             {{else}}
-              <a class="lh-1 me-0 me-sm-3 navbar-brand" href="/">
+              <a class="lh-1 me-0 me-sm-3 navbar-brand" href="{{$.baseURL}}/">
                 {{.siteinfo.General.Name}}
               </a>
             {{end}}
diff --git a/ui/template/homepage.html b/ui/template/homepage.html
index 6507eebb..ad5b0209 100644
--- a/ui/template/homepage.html
+++ b/ui/template/homepage.html
@@ -23,12 +23,12 @@
                 <div class="justify-content-center row">
                     <div class="col-xxl-7 col-lg-8 col-sm-12">
                         <div class="d-flex flex-column flex-md-row mb-4">
-                            <a href="/users/{{.userinfo.Username}}"><img
+                            <a 
href="{{$.baseURL}}/users/{{.userinfo.Username}}"><img
                                     src="{{.userinfo.Avatar}}"
                                     width="160px" height="160px" 
class="rounded" alt="" /></a>
                             <div class="ms-0 ms-md-4 mt-4 mt-md-0">
                                 <div class="d-flex align-items-center mb-2">
-                                    <a class="link-dark h3 mb-0" 
href="/users/{{.userinfo.Username}}">{{.userinfo.DisplayName}}</a>
+                                    <a class="link-dark h3 mb-0" 
href="{{$.baseURL}}/users/{{.userinfo.Username}}">{{.userinfo.DisplayName}}</a>
 
                                 </div>
                                 <div class="text-secondary 
mb-4">@{{.userinfo.Username}}</div>
diff --git a/ui/template/question-detail.html b/ui/template/question-detail.html
index fc276fba..c254f79a 100644
--- a/ui/template/question-detail.html
+++ b/ui/template/question-detail.html
@@ -24,7 +24,7 @@
     <div class="mb-5 mb-md-0 col-xxl-7 col-lg-8 col-sm-12">
       <div>
         <h1 class="h3 mb-3 text-wrap text-break">
-          <a class="link-dark" 
href="/questions/{{.detail.ID}}">{{.detail.Title}}</a>
+          <a class="link-dark" 
href="{{$.baseURL}}/questions/{{.detail.ID}}">{{.detail.Title}}</a>
         </h1>
         <div
           class="d-flex flex-wrap align-items-center small mb-3 
text-secondary">
@@ -41,7 +41,7 @@
         </div>
         <div class="m-n1">
           {{range .detail.Tags}}
-          <a href="/tags/{{.SlugName}}"
+          <a href="{{$.baseURL}}/tags/{{.SlugName}}"
              class="badge-tag rounded-1 {{if 
.Reserved}}badge-tag-reserved{{end}} {{if .Recommend}}badge-tag-required{{end}} 
m-1">
             <span class="">{{.SlugName}}</span>
           </a>
@@ -71,7 +71,7 @@
 
           </div>
           <div class="mb-3 mb-md-0 col-lg-3">
-            <a href="/posts/{{.detail.ID}}/timeline">
+            <a href="{{$.baseURL}}/posts/{{.detail.ID}}/timeline">
               <time class="link-secondary small"
                     datetime="{{timeFormatISO $.timezone .detail.UpdateTime}}"
                     title="{{translatorTimeFormatLongDate $.language 
$.timezone .detail.UpdateTime}}">
@@ -81,7 +81,7 @@
           </div>
           <div class="col-lg-3">
             <div class="d-flex">
-              <a href="/users/bmckfbksayryy"><img
+              <a href="{{$.baseURL}}/users/{{.UserInfo.Username}}"><img
                 src="{{.detail.UserInfo.Avatar}}"
                 width="40px" height="40px"
                 class="rounded me-2 d-none d-md-block"
@@ -94,10 +94,10 @@
                 class="small text-secondary d-flex flex-row flex-md-column 
align-items-center align-items-md-start">
                 <div class="me-1 me-md-0">
                   <a class="me-1 text-break"
-                     
href="/users/{{.detail.UserInfo.Username}}">{{.detail.UserInfo.DisplayName}}</a><span
+                     
href="{{$.baseURL}}/users/{{.detail.UserInfo.Username}}">{{.detail.UserInfo.DisplayName}}</a><span
                   class="fw-bold" 
title="Reputation">{{.detail.UserInfo.Rank}}</span>
                 </div>
-                <a href="/posts/{{.detail.ID}}/timeline">
+                <a href="{{$.baseURL}}/posts/{{.detail.ID}}/timeline">
                   <time class="link-secondary"
                         datetime="{{timeFormatISO $.timezone 
.detail.CreateTime}}"
                         title="{{translatorTimeFormatLongDate $.language 
$.timezone .detail.CreateTime}}">{{translator $.language 
"ui.question_detail.asked"}} {{translatorTimeFormat $.language $.timezone 
.detail.CreateTime}}
@@ -148,7 +148,7 @@
             </div>
           </div>
           <div class="mb-3 mb-md-0 col-lg-3">
-            <a href="/posts/{{$.detail.ID}}/{{.ID}}/timeline">
+            <a href="{{$.baseURL}}/posts/{{$.detail.ID}}/{{.ID}}/timeline">
               <time
                 class="link-secondary small"
                 datetime="{{timeFormatISO $.timezone .UpdateTime}}"
@@ -159,7 +159,7 @@
           </div>
           <div class="col-lg-4">
             <div class="d-flex">
-              <a href="/users/bmxtgtpksxayy"><img
+              <a href="{{$.baseURL}}/users/{{.UserInfo.Username}}"><img
                 src="{{.UserInfo.Avatar}}"
                 width="40px" height="40px"
                 class="rounded me-2 d-none d-md-block"
@@ -172,10 +172,10 @@
                 class="small text-secondary d-flex flex-row flex-md-column 
align-items-center align-items-md-start">
                 <div class="me-1 me-md-0">
                   <a class="me-1 text-break"
-                     
href="/users/{{.UserInfo.Username}}">{{.UserInfo.DisplayName}}</a><span
+                     
href="{{$.baseURL}}/users/{{.UserInfo.Username}}">{{.UserInfo.DisplayName}}</a><span
                   class="fw-bold" title="Reputation">{{.UserInfo.Rank}}</span>
                 </div>
-                <a href="/posts/{{$.detail.ID}}/{{.ID}}/timeline">
+                <a href="{{$.baseURL}}/posts/{{$.detail.ID}}/{{.ID}}/timeline">
                   <time
                     class="link-secondary"
                     datetime="{{timeFormatISO $.timezone .CreateTime}}"
diff --git a/ui/template/question.html b/ui/template/question.html
index ff3d4a3c..40c645ed 100644
--- a/ui/template/question.html
+++ b/ui/template/question.html
@@ -33,11 +33,11 @@
           <div class="border-bottom pt-3 pb-2 px-0 list-group-item">
             <h5 class="text-wrap text-break">
               {{if $.useTitle }}
-              <a class="link-dark" href="/questions/{{.ID}}/{{urlTitle 
.Title}}"
+              <a class="link-dark" 
href="{{$.baseURL}}/questions/{{.ID}}/{{urlTitle .Title}}"
                 >{{.Title}}</a
               >
               {{else}}
-              <a class="link-dark" href="/questions/{{.ID}}">{{.Title}}</a>
+              <a class="link-dark" 
href="{{$.baseURL}}/questions/{{.ID}}">{{.Title}}</a>
               {{end}}
             </h5>
             <div
@@ -45,7 +45,7 @@
             >
               <div class="d-flex">
                 <div class="text-secondary me-1">
-                  <a href="/users/{{.Operator.Username}}"
+                  <a href="{{$.baseURL}}/users/{{.Operator.Username}}"
                     ><span class="me-1 text-break"
                       >{{.Operator.DisplayName}}</span
                     ></a
@@ -79,7 +79,7 @@
             <div class="question-tags mx-n1 mt-2">
               {{range .Tags }}
               <a
-                href="/tags/{{.SlugName}}"
+                href="{{$.baseURL}}/tags/{{.SlugName}}"
                 class="badge-tag rounded-1 {{if 
.Reserved}}badge-tag-reserved{{end}} {{if .Recommend}}badge-tag-required{{end}} 
m-1"
               >
                 <span class="">{{.SlugName}}</span>
diff --git a/ui/template/sidenav.html b/ui/template/sidenav.html
index 85e5fb6e..3191770a 100644
--- a/ui/template/sidenav.html
+++ b/ui/template/sidenav.html
@@ -22,7 +22,7 @@
 <div id="sideNav" class="position-relative d-none d-lg-block col-xl-2 col-lg-3 
col-md-12">
   <div class="nav-wrap pt-4">
     <div class="flex-column nav nav-pills">
-      <a class="nav-link active" href="/questions">
+      <a class="nav-link active" href="{{$.baseURL}}/questions">
         <i class="br bi-question-circle-fill me-2"></i>
         <span>{{translator $.language "ui.header.nav.question"}}</span>
       </a>
@@ -30,7 +30,7 @@
         <i class="br bi-tags-fill me-2"></i>
         <span>{{translator $.language "ui.header.nav.tag"}}</span>
       </a>
-      <a class="nav-link" href="/users">
+      <a class="nav-link" href="{{$.baseURL}}/users">
         <i class="br bi-people-fill me-2"></i>
         <span>{{translator $.language "ui.header.nav.user"}}</span>
       </a>
diff --git a/ui/template/tag-detail.html b/ui/template/tag-detail.html
index ee5bf59c..f3259949 100644
--- a/ui/template/tag-detail.html
+++ b/ui/template/tag-detail.html
@@ -24,7 +24,7 @@
     <div class="col-xxl-7 col-lg-8 col-sm-12">
       <div class="tag-box mb-5">
         <h3 class="mb-3">
-          <a class="link-dark" href="/tags/{{$.tag.SlugName}}"
+          <a class="link-dark" href="{{$.baseURL}}/tags/{{$.tag.SlugName}}"
             >{{$.tag.SlugName}}</a
           >
         </h3>
@@ -42,11 +42,11 @@
           <div class="border-bottom pt-3 pb-2 px-0 list-group-item">
             <h5 class="text-wrap text-break">
               {{if $.useTitle }}
-              <a class="link-dark" href="/questions/{{.ID}}/{{urlTitle 
.Title}}"
+              <a class="link-dark" 
href="{{$.baseURL}}/questions/{{.ID}}/{{urlTitle .Title}}"
                 >{{.Title}}</a
               >
               {{else}}
-              <a class="link-dark" href="/questions/{{.ID}}">{{.Title}}</a>
+              <a class="link-dark" 
href="{{$.baseURL}}/questions/{{.ID}}">{{.Title}}</a>
               {{end}}
             </h5>
             <div
@@ -54,7 +54,7 @@
             >
               <div class="d-flex">
                 <div class="text-secondary me-1">
-                  <a href="/users/{{.Operator.Username}}"
+                  <a href="{{$.baseURL}}/users/{{.Operator.Username}}"
                     ><span class="me-1 text-break"
                       >{{.Operator.DisplayName}}</span
                     ></a
@@ -89,7 +89,7 @@
             <div class="question-tags mx-n1 mt-2">
               {{range .Tags }}
               <a
-                href="/tags/{{.SlugName}}"
+                href="{{$.baseURL}}/tags/{{.SlugName}}"
                 class="badge-tag rounded-1 {{if 
.Reserved}}badge-tag-reserved{{end}} {{if .Recommend}}badge-tag-required{{end}} 
m-1"
               >
                 <span class="">{{.SlugName}}</span>
diff --git a/ui/template/tags.html b/ui/template/tags.html
index 7eb2b9b3..292fd477 100644
--- a/ui/template/tags.html
+++ b/ui/template/tags.html
@@ -40,7 +40,7 @@
                 <div class="mb-4 col-lg-3 col-md-4 col-sm-6 col-12">
                     <div class="h-100 card">
                         <div class="d-flex flex-column align-items-start 
card-body">
-                            <a href="/tags/{{.SlugName}}" class="badge-tag 
rounded-1 mb-3"><span
+                            <a href="{{$.baseURL}}/tags/{{.SlugName}}" 
class="badge-tag rounded-1 mb-3"><span
                                     class="">{{.SlugName}}</span></a>
                             <p class="small flex-fill text-break text-wrap 
text-truncate-4">{{formatLinkNofollow .ParsedText}}
                             </p>

Reply via email to