Skip to content

Commit c3ff466

Browse files
committed
Resolves smartstore#339 Meta robots setting for page indexing of search engines
1 parent 0879a99 commit c3ff466

10 files changed

Lines changed: 59 additions & 8 deletions

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* #457 Added option to hide the default image for categories and products
3939
* #451 Add message token for product shipping surcharge
4040
* #436 Make %Order.Product(s)% token to link the product detail page and a add product thumbnail
41+
* #339 Meta robots setting for page indexing of search engines
4142

4243
### Improvements
4344
* (Perf) Implemented static caches for URL aliases and localized properties. Increases app startup and request speed by up to 30%.

src/Libraries/SmartStore.Core/Domain/Seo/SeoSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public SeoSettings()
6868
public string DefaultTitle { get; set; }
6969
public string DefaultMetaKeywords { get; set; }
7070
public string DefaultMetaDescription { get; set; }
71+
public string MetaRobotsContent { get; set; }
7172

72-
public bool ConvertNonWesternChars { get; set; }
73+
public bool ConvertNonWesternChars { get; set; }
7374
public bool AllowUnicodeCharsInUrls { get; set; }
7475
public string SeoNameCharConversion { get; set; }
7576

src/Libraries/SmartStore.Data/Migrations/201512151526290_ImportFramework.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
375375
"Thumbnail-Größe von Produkten in E-Mails",
376376
"Specifies the thumbnail image size (pixels) of products in emails. Enter 0 to not display thumbnails.",
377377
"Legt die Thumbnail-Bildgröße (in Pixel) von Produkten in E-Mails fest. Geben Sie 0 ein, um keine Thumbnails anzuzeigen.");
378+
379+
builder.AddOrUpdate("Admin.Configuration.Settings.GeneralCommon.MetaRobotsContent",
380+
"Meta robots",
381+
"Meta Robots",
382+
"Specifies if and how search engines indexing the pages of your store.",
383+
"Legt fest, ob und wie Suchmaschinen die Seiten Ihres Shops indexieren.");
378384
}
379385
}
380386
}

src/Presentation/SmartStore.Web.Framework/UI/IPageAssetsBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public partial interface IPageAssetsBuilder
1717
void AddCssFileParts(ResourceLocation location, IEnumerable<string> parts, bool excludeFromBundling = false, bool append = false);
1818
void AddLinkPart(string rel, string href, RouteValueDictionary htmlAttributes);
1919

20-
string GenerateTitle(bool addDefaultTitle);
20+
string GenerateTitle(bool addDefaultTitle);
2121
string GenerateMetaDescription();
2222
string GenerateMetaKeywords();
2323
string GenerateCanonicalUrls();
@@ -26,7 +26,8 @@ public partial interface IPageAssetsBuilder
2626
string GenerateScripts(UrlHelper urlHelper, ResourceLocation location, bool? enableBundling = null);
2727
string GenerateCssFiles(UrlHelper urlHelper, ResourceLocation location, bool? enableBundling = null);
2828
string GenerateLinkRels();
29-
}
29+
string GenerateMetaRobots();
30+
}
3031

3132
public static class PageAssetsBuilderExtensions
3233
{

src/Presentation/SmartStore.Web.Framework/UI/LayoutExtensions.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ public static MvcHtmlString SmartMetaKeywords(this HtmlHelper html, params strin
6464
html.AppendMetaKeywordParts(parts);
6565
return MvcHtmlString.Create(html.Encode(pageAssetsBuilder.GenerateMetaKeywords()));
6666
}
67-
#endregion
67+
#endregion
68+
69+
#region MetaMisc
70+
71+
public static MvcHtmlString SmartMetaRobots(this HtmlHelper html)
72+
{
73+
var pageAssetsBuilder = EngineContext.Current.Resolve<IPageAssetsBuilder>();
74+
return MvcHtmlString.Create(pageAssetsBuilder.GenerateMetaRobots());
75+
}
6876

77+
#endregion
6978

70-
#region ScriptParts
71-
public static void AddScriptParts(this HtmlHelper html, params string[] parts)
79+
#region ScriptParts
80+
public static void AddScriptParts(this HtmlHelper html, params string[] parts)
7281
{
7382
AddScriptParts(html, ResourceLocation.Foot, false, parts);
7483
}

src/Presentation/SmartStore.Web.Framework/UI/PageAssetsBuilder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,16 @@ public string GenerateLinkRels()
406406
return sb.ToString();
407407
}
408408

409-
public class WebAssetDescriptor
409+
public string GenerateMetaRobots()
410+
{
411+
if (_seoSettings.MetaRobotsContent.HasValue())
412+
{
413+
return "<meta name=\"robots\" content=\"{0}\" />".FormatInvariant(_seoSettings.MetaRobotsContent);
414+
}
415+
return null;
416+
}
417+
418+
public class WebAssetDescriptor
410419
{
411420
public bool ExcludeFromBundling { get; set; }
412421
public string Part { get; set; }

src/Presentation/SmartStore.Web/Administration/Controllers/SettingController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ public ActionResult GeneralCommon()
10251025
model.SeoSettings.DefaultTitle = seoSettings.DefaultTitle;
10261026
model.SeoSettings.DefaultMetaKeywords = seoSettings.DefaultMetaKeywords;
10271027
model.SeoSettings.DefaultMetaDescription = seoSettings.DefaultMetaDescription;
1028+
model.SeoSettings.MetaRobotsContent = seoSettings.MetaRobotsContent;
10281029
model.SeoSettings.ConvertNonWesternChars = seoSettings.ConvertNonWesternChars;
10291030
model.SeoSettings.AllowUnicodeCharsInUrls = seoSettings.AllowUnicodeCharsInUrls;
10301031
model.SeoSettings.SeoNameCharConversion = seoSettings.SeoNameCharConversion;
@@ -1208,6 +1209,7 @@ public ActionResult GeneralCommon(GeneralCommonSettingsModel model, FormCollecti
12081209
seoSettings.DefaultTitle = model.SeoSettings.DefaultTitle;
12091210
seoSettings.DefaultMetaKeywords = model.SeoSettings.DefaultMetaKeywords;
12101211
seoSettings.DefaultMetaDescription = model.SeoSettings.DefaultMetaDescription;
1212+
seoSettings.MetaRobotsContent = model.SeoSettings.MetaRobotsContent;
12111213
seoSettings.AllowUnicodeCharsInUrls = model.SeoSettings.AllowUnicodeCharsInUrls;
12121214
seoSettings.SeoNameCharConversion = model.SeoSettings.SeoNameCharConversion;
12131215
seoSettings.ConvertNonWesternChars = model.SeoSettings.ConvertNonWesternChars;

src/Presentation/SmartStore.Web/Administration/Models/Settings/GeneralCommonSettingsModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ public partial class SeoSettingsModel
7878
[AllowHtml]
7979
public string DefaultMetaDescription { get; set; }
8080

81-
[SmartResourceDisplayName("Admin.Configuration.Settings.GeneralCommon.ConvertNonWesternChars")]
81+
[SmartResourceDisplayName("Admin.Configuration.Settings.GeneralCommon.MetaRobotsContent")]
82+
public string MetaRobotsContent { get; set; }
83+
84+
[SmartResourceDisplayName("Admin.Configuration.Settings.GeneralCommon.ConvertNonWesternChars")]
8285
public bool ConvertNonWesternChars { get; set; }
8386

8487
[SmartResourceDisplayName("Admin.Configuration.Settings.GeneralCommon.AllowUnicodeCharsInUrls")]

src/Presentation/SmartStore.Web/Administration/Views/Setting/GeneralCommon.cshtml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@
159159
@Html.ValidationMessageFor(model => model.SeoSettings.DefaultMetaDescription)
160160
</td>
161161
</tr>
162+
<tr>
163+
<td class="adminTitle">
164+
@Html.SmartLabelFor(model => model.SeoSettings.MetaRobotsContent)
165+
</td>
166+
<td class="adminData">
167+
@Html.SettingOverrideCheckbox(model => model.SeoSettings.MetaRobotsContent)
168+
@Html.DropDownListFor(model => model.SeoSettings.MetaRobotsContent, new List<SelectListItem>
169+
{
170+
new SelectListItem { Text = "index", Value = "index" },
171+
new SelectListItem { Text = "noindex", Value = "noindex" },
172+
new SelectListItem { Text = "index, follow", Value = "index, follow" },
173+
new SelectListItem { Text = "index, nofollow", Value = "index, nofollow" },
174+
new SelectListItem { Text = "noindex, follow", Value = "noindex, follow" },
175+
new SelectListItem { Text = "noindex, nofollow", Value = "noindex, nofollow" }
176+
}, T("Common.Unspecified"))
177+
@Html.ValidationMessageFor(model => model.SeoSettings.MetaRobotsContent)
178+
</td>
179+
</tr>
162180
<tr>
163181
<td class="adminTitle">
164182
@Html.SmartLabelFor(model => model.SeoSettings.CanonicalUrlsEnabled)

src/Presentation/SmartStore.Web/Views/Shared/_Root.Head.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
@*This is used so that themes can inject content into the header*@
9898
@Html.Partial("Head")
9999

100+
@Html.SmartMetaRobots()
100101
@Html.MetaAcceptLanguage()
101102
@Html.Partial("_ClientRes")
102103

0 commit comments

Comments
 (0)