From 5143ebb50746a70d0528c2ed6f7250e0c141b71c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 17 Feb 2024 10:20:10 +0100 Subject: [PATCH] Add rel="nofollow" to issue filter links The issue filter links should not be crawled by search engines, because they they only filter results, and contain nothing new, yet, they put a considerable load on the server. To stop - well behaving - search engines from following these links, add a `rel="nofollow"` property to them. The same property is already present on the archive download links, and plenty of other places. Fixes #2361. Signed-off-by: Gergely Nagy --- templates/repo/issue/filter_list.tmpl | 56 +++++++++++++-------------- tests/integration/issue_test.go | 18 +++++++++ 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/templates/repo/issue/filter_list.tmpl b/templates/repo/issue/filter_list.tmpl index 511ef7f397..5aa9135efa 100644 --- a/templates/repo/issue/filter_list.tmpl +++ b/templates/repo/issue/filter_list.tmpl @@ -23,8 +23,8 @@ {{ctx.Locale.Tr "repo.issues.filter_label_exclude" | Safe}}
- {{ctx.Locale.Tr "repo.issues.filter_label_no_select"}} - {{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}} + {{ctx.Locale.Tr "repo.issues.filter_label_no_select"}} + {{ctx.Locale.Tr "repo.issues.filter_label_select_no_label"}} {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} {{$exclusiveScope := .ExclusiveScope}} @@ -32,7 +32,7 @@
{{end}} {{$previousExclusiveScope = $exclusiveScope}} - + {{if .IsExcluded}} {{svg "octicon-circle-slash"}} {{else if .IsSelected}} @@ -62,13 +62,13 @@
-
{{ctx.Locale.Tr "repo.issues.filter_milestone_all"}} - {{ctx.Locale.Tr "repo.issues.filter_milestone_none"}} + {{ctx.Locale.Tr "repo.issues.filter_milestone_all"}} + {{ctx.Locale.Tr "repo.issues.filter_milestone_none"}} {{if .OpenMilestones}}
{{ctx.Locale.Tr "repo.issues.filter_milestone_open"}}
{{range .OpenMilestones}} - + {{svg "octicon-milestone" 16 "mr-2"}} {{.Name}} @@ -78,7 +78,7 @@
{{ctx.Locale.Tr "repo.issues.filter_milestone_closed"}}
{{range .ClosedMilestones}} - + {{svg "octicon-milestone" 16 "mr-2"}} {{.Name}} @@ -99,15 +99,15 @@ {{svg "octicon-search" 16}} - {{ctx.Locale.Tr "repo.issues.filter_project_all"}} - {{ctx.Locale.Tr "repo.issues.filter_project_none"}} + {{ctx.Locale.Tr "repo.issues.filter_project_all"}} + {{ctx.Locale.Tr "repo.issues.filter_project_none"}} {{if .OpenProjects}}
{{ctx.Locale.Tr "repo.issues.new.open_projects"}}
{{range .OpenProjects}} - + {{svg .IconName 18 "gt-mr-3 gt-shrink-0"}}{{.Title}} {{end}} @@ -118,7 +118,7 @@ {{ctx.Locale.Tr "repo.issues.new.closed_projects"}} {{range .ClosedProjects}} - + {{svg .IconName 18 "gt-mr-3"}}{{.Title}} {{end}} @@ -156,11 +156,11 @@ {{svg "octicon-search" 16}} - {{ctx.Locale.Tr "repo.issues.filter_assginee_no_select"}} - {{ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee"}} + {{ctx.Locale.Tr "repo.issues.filter_assginee_no_select"}} + {{ctx.Locale.Tr "repo.issues.filter_assginee_no_assignee"}}
{{range .Assignees}} - + {{ctx.AvatarUtils.Avatar . 20}}{{template "repo/search_name" .}} {{end}} @@ -175,14 +175,14 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} {{end}} @@ -194,13 +194,13 @@ {{svg "octicon-triangle-down" 14 "dropdown icon"}} diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 268200be6f..7c00c4f958 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -1,4 +1,5 @@ // Copyright 2017 The Gitea Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved. // SPDX-License-Identifier: MIT package integration @@ -797,3 +798,20 @@ func TestCommitRefComment(t *testing.T) { assert.Contains(t, event, "referenced this issue") }) } + +func TestIssueFilterNoFollow(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues") + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + // Check that every link in the filter list has rel="nofollow". + filterLinks := htmlDoc.Find(".issue-list-toolbar-right a[href*=\"/issues?q=\"]") + assert.True(t, filterLinks.Length() > 0) + filterLinks.Each(func(i int, link *goquery.Selection) { + rel, has := link.Attr("rel") + assert.True(t, has) + assert.Equal(t, "nofollow", rel) + }) +}