Skip to content

Commit 2665e7f

Browse files
committed
Add BlockSearchEngineIndexing to allow site-wide search engine blocking (#6385)
Progress on #6381
1 parent a2e50db commit 2665e7f

5 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/NuGetGallery/Configuration/AppConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,7 @@ public string ExternalBrandingMessage
342342
public bool RejectSignedPackagesWithNoRegisteredCertificate { get; set; }
343343

344344
public bool RejectPackagesWithTooManyPackageEntries { get; set; }
345+
346+
public bool BlockSearchEngineIndexing { get; set; }
345347
}
346348
}

src/NuGetGallery/Configuration/IAppConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,10 @@ public interface IAppConfiguration : ICoreMessageServiceConfiguration
344344
/// Whether or not to synchronously reject packages on push/upload that have too many package entries.
345345
/// </summary>
346346
bool RejectPackagesWithTooManyPackageEntries { get; set; }
347+
348+
/// <summary>
349+
/// Whether or not to block search engines from indexing the web pages using the "noindex" meta tag.
350+
/// </summary>
351+
bool BlockSearchEngineIndexing { get; set; }
347352
}
348353
}

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@{
66
ViewBag.Title = Model.Id + " " + Model.Version;
77
ViewBag.Tab = "Packages";
8+
ViewBag.BlockSearchEngineIndexing = !Model.Listed || !Model.Available;
89

910
var absolutePackageUrl = Url.Absolute(Url.Package(Model.Id));
1011

@@ -74,12 +75,6 @@
7475
<meta property="og:determiner" content="a" />
7576
<meta property="og:image" content="@(PackageHelper.ShouldRenderUrl(Model.IconUrl) ? Model.IconUrl : Url.Absolute("~/Content/gallery/img/default-package-icon-256x256.png"))" />
7677
}
77-
@section Meta {
78-
@if (!Model.Listed || !Model.Available)
79-
{
80-
<meta name="robots" content="noindex">
81-
}
82-
}
8378

8479
@helper VersionListDivider(int rowCount, bool versionsExpanded)
8580
{

src/NuGetGallery/Views/Shared/Gallery/Layout.cshtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<meta charset="utf-8" />
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
@if (Config.Current.BlockSearchEngineIndexing || ViewBag.BlockSearchEngineIndexing == true)
8+
{
9+
<meta name="robots" content="noindex">
10+
}
711
@RenderSection("SocialMeta", required: false)
812
@RenderSection("Meta", required: false)
913

src/NuGetGallery/Web.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
<add key="Gallery.EnforceDefaultSecurityPolicies" value="false"/>
148148
<add key="Gallery.RejectSignedPackagesWithNoRegisteredCertificate" value="false"/>
149149
<add key="Gallery.RejectPackagesWithTooManyPackageEntries" value="false"/>
150+
<add key="Gallery.BlockSearchEngineIndexing" value="false"/>
150151
<!-- This is also the default so you can remove this setting if you really want. -->
151152
<!-- Set this to false if you want to disable search indexing in the background. -->
152153
<add key="Gallery.AutoUpdateSearchIndex" value="true"/>

0 commit comments

Comments
 (0)