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/01/03 07:51:07 UTC

(incubator-answer) 01/01: feat(template): add noindex meta tag #661

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

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

commit 458aec1f441538ab0b5889632251a0e7841e3674
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Wed Jan 3 15:50:47 2024 +0800

    feat(template): add noindex meta tag #661
---
 internal/controller/template_controller.go | 2 ++
 ui/template/header.html                    | 1 +
 2 files changed, 3 insertions(+)

diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go
index 88e8ca0a..6b4c4bbe 100644
--- a/internal/controller/template_controller.go
+++ b/internal/controller/template_controller.go
@@ -22,6 +22,7 @@ package controller
 import (
 	"encoding/json"
 	"fmt"
+	"github.com/apache/incubator-answer/internal/entity"
 	"html/template"
 	"net/http"
 	"regexp"
@@ -376,6 +377,7 @@ func (tc *TemplateController) QuestionInfo(ctx *gin.Context) {
 		"detail":   detail,
 		"answers":  answers,
 		"comments": comments,
+		"noindex":  detail.Show == entity.QuestionHide,
 	})
 }
 
diff --git a/ui/template/header.html b/ui/template/header.html
index 5471391d..85425674 100644
--- a/ui/template/header.html
+++ b/ui/template/header.html
@@ -29,6 +29,7 @@
     <meta name="description" content="{{.description}}" data-rh="true" />
     <meta name="generator" content="Answer {{.Version}} - https://github.com/apache/incubator-answer version {{.Revision}}">
     {{if .keywords }}<meta name="keywords" content="{{.keywords}}" data-rh="true" />{{end}}
+    {{if .noindex }}<meta name="robots" content="noindex">{{end}}
 
     <link rel="canonical" href="{{.siteinfo.Canonical}}" />
     <link rel="manifest" href="/manifest.json" />