You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2024/08/07 02:11:27 UTC

(incubator-answer) branch dev updated (027caa65 -> 264f9274)

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

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


    from 027caa65 Makefile: Wraped with quotes the go location in go variable
     new f0b58597 feat: Add Open Search support
     new 264f9274 fix: branding favicon might be empty

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 internal/controller/template_controller.go      |  8 ++++++++
 internal/controller/template_render/question.go | 22 ++++++++++++++++++++++
 internal/router/template_router.go              |  2 ++
 ui/template/header.html                         |  1 +
 ui/template/{sitemap.xml => opensearch.xml}     | 20 ++++++++------------
 5 files changed, 41 insertions(+), 12 deletions(-)
 copy ui/template/{sitemap.xml => opensearch.xml} (65%)


(incubator-answer) 02/02: fix: branding favicon might be empty

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 264f927433f8153cea3566ae7c981e2947d6e1ab
Author: sy-records <52...@qq52o.cn>
AuthorDate: Tue Aug 6 15:39:55 2024 +0800

    fix: branding favicon might be empty
---
 internal/controller/template_render/question.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/internal/controller/template_render/question.go b/internal/controller/template_render/question.go
index 83d08dc7..b9753618 100644
--- a/internal/controller/template_render/question.go
+++ b/internal/controller/template_render/question.go
@@ -96,9 +96,9 @@ func (t *TemplateRenderController) OpenSearch(ctx *gin.Context) {
 		return
 	}
 
-	favicon := "favicon.ico"
+	favicon := general.SiteUrl + "/favicon.ico"
 	branding, err := t.siteInfoService.GetSiteBranding(ctx)
-	if err == nil {
+	if err == nil && len(branding.Favicon) > 0 {
 		favicon = branding.Favicon
 	}
 


(incubator-answer) 01/02: feat: Add Open Search support

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f0b585974709d4adc4364d533419c5fa45a83cd4
Author: sy-records <52...@qq52o.cn>
AuthorDate: Mon Aug 5 17:03:23 2024 +0800

    feat: Add Open Search support
---
 internal/controller/template_controller.go      |  8 +++++++
 internal/controller/template_render/question.go | 22 +++++++++++++++++++
 internal/router/template_router.go              |  2 ++
 ui/template/header.html                         |  1 +
 ui/template/opensearch.xml                      | 29 +++++++++++++++++++++++++
 5 files changed, 62 insertions(+)

diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go
index a7d69ebc..09f5bffc 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -562,6 +562,14 @@ func (tc *TemplateController) html(ctx *gin.Context, code int, tpl string, siteI
 	ctx.HTML(code, tpl, data)
 }
 
+func (tc *TemplateController) OpenSearch(ctx *gin.Context) {
+	if tc.checkPrivateMode(ctx) {
+		tc.Page404(ctx)
+		return
+	}
+	tc.templateRenderController.OpenSearch(ctx)
+}
+
 func (tc *TemplateController) Sitemap(ctx *gin.Context) {
 	if tc.checkPrivateMode(ctx) {
 		tc.Page404(ctx)
diff --git a/internal/controller/template_render/question.go b/internal/controller/template_render/question.go
index a65c3083..83d08dc7 100644
--- a/internal/controller/template_render/question.go
+++ b/internal/controller/template_render/question.go
@@ -89,6 +89,28 @@ func (t *TemplateRenderController) Sitemap(ctx *gin.Context) {
 	)
 }
 
+func (t *TemplateRenderController) OpenSearch(ctx *gin.Context) {
+	general, err := t.siteInfoService.GetSiteGeneral(ctx)
+	if err != nil {
+		log.Error("get site general failed:", err)
+		return
+	}
+
+	favicon := "favicon.ico"
+	branding, err := t.siteInfoService.GetSiteBranding(ctx)
+	if err == nil {
+		favicon = branding.Favicon
+	}
+
+	ctx.Header("Content-Type", "application/xml")
+	ctx.HTML(
+		http.StatusOK, "opensearch.xml", gin.H{
+			"general": general,
+			"favicon": favicon,
+		},
+	)
+}
+
 func (t *TemplateRenderController) SitemapPage(ctx *gin.Context, page int) error {
 	general, err := t.siteInfoService.GetSiteGeneral(ctx)
 	if err != nil {
diff --git a/internal/router/template_router.go b/internal/router/template_router.go
index 01e8b307..195030f9 100644
--- a/internal/router/template_router.go
+++ b/internal/router/template_router.go
@@ -60,6 +60,8 @@ func (a *TemplateRouter) RegisterTemplateRouter(r *gin.RouterGroup, baseURLPath
 
 	seoNoAuth.GET("/404", a.templateController.Page404)
 
+	seoNoAuth.GET("/opensearch.xml", a.templateController.OpenSearch)
+
 	seo := r.Group(baseURLPath)
 	seo.Use(a.authUserMiddleware.CheckPrivateMode())
 	seo.GET("/", a.templateController.Index)
diff --git a/ui/template/header.html b/ui/template/header.html
index 6eff7340..653f9a28 100644
--- a/ui/template/header.html
+++ b/ui/template/header.html
@@ -33,6 +33,7 @@
 
     <link rel="canonical" href="{{.siteinfo.Canonical}}" />
     <link rel="manifest" href="{{$.baseURL}}/manifest.json" />
+    <link rel="search" type="application/opensearchdescription+xml" href="{{$.baseURL}}/opensearch.xml" title="{{.siteinfo.General.Name}}" />
     <link href="{{.cssPath}}" rel="stylesheet" />
     <link href="{{$.baseURL}}/custom.css" rel="stylesheet" />
     <link
diff --git a/ui/template/opensearch.xml b/ui/template/opensearch.xml
new file mode 100644
index 00000000..af318ec0
--- /dev/null
+++ b/ui/template/opensearch.xml
@@ -0,0 +1,29 @@
+<!--
+
+    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.
+
+-->
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+  <ShortName>{{$.general.Name}}</ShortName>
+  {{if $.general.Description}}
+  <Description>{{$.general.Description}}</Description>
+  {{end}}
+  <InputEncoding>UTF-8</InputEncoding>
+  <Image width="16" height="16" type="image/x-icon">{{$.favicon}}</Image>
+  <Url type="text/html" method="get" template="{{$.general.SiteUrl}}/search?q={searchTerms}"/>
+</OpenSearchDescription>