Skip to content

Commit

Permalink
Fixed a couple of bugs in the robots.txt file.
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-burandt committed Mar 9, 2023
1 parent eb20004 commit 6a46a76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
13 changes: 6 additions & 7 deletions Blend.RobotsTxt/RobotsTxtBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ public interface IRobotsBuilder
public class RobotsTxtBuilder : IRobotsBuilder
{
private readonly List<RobotsTxtOption> _config;
private readonly GlobalSettings _globalSettings;
private readonly IWebHostEnvironment _webHostEnvironment;

public RobotsTxtBuilder(IOptions<List<RobotsTxtOption>> config, IOptions<GlobalSettings> globalSettings, IWebHostEnvironment webHostEnvironment)
public RobotsTxtBuilder(IOptions<List<RobotsTxtOption>> config, IWebHostEnvironment webHostEnvironment)
{
_config = config.Value;
_globalSettings = globalSettings.Value;

_webHostEnvironment = webHostEnvironment;
}

Expand Down Expand Up @@ -53,7 +52,8 @@ public string BuildRobots()
{
foreach (var item in robot.Allow)
{
stringBuilder.AppendLine($"Allow: {item}");
if (!item.IsNullOrWhiteSpace())
stringBuilder.AppendLine($"Allow: {item}");
}
}

Expand All @@ -62,7 +62,8 @@ public string BuildRobots()
{
foreach (var item in robot.Disallow)
{
stringBuilder.AppendLine($"Disallow: {item}");
if (!item.IsNullOrWhiteSpace())
stringBuilder.AppendLine($"Disallow: {item}");
}
}

Expand All @@ -82,7 +83,6 @@ public string BuildRobots()
case "Production":
stringBuilder.AppendLine("User-agent: *");
stringBuilder.AppendLine("Allow: /");
stringBuilder.AppendLine($"Disallow: {_globalSettings.UmbracoPath.Replace("~", "")}");
break;
default:
stringBuilder.AppendLine("User-agent: *");
Expand All @@ -96,7 +96,6 @@ public string BuildRobots()
// Last Resort and display production robots.txt.
stringBuilder.AppendLine("User-agent: *");
stringBuilder.AppendLine("Allow: /");
stringBuilder.AppendLine($"Disallow: {_globalSettings.UmbracoPath.Replace("~", "")}");
}
var robotsTxt = stringBuilder.ToString();
return robotsTxt;
Expand Down
7 changes: 2 additions & 5 deletions Blend.RobotsTxt/RobotsTxtOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ public class RobotsTxtOption
/// <summary>
/// Array of paths to allow
/// </summary>
[DefaultValue(new string[] { })]
[Description("Array of paths to allow")]
public string[] Allow { get; set; }
public string[] Allow { get; set; } = Array.Empty<string>();

/// <summary>
/// Array of paths to disallow
/// </summary>
[DefaultValue(new string[] { "/" })]
[Description("Array of paths to allow")]
public string[] Disallow { get; set; }
public string[] Disallow { get; set; } = Array.Empty<string>();

/// <summary>
/// Path to the sitemap.xml file
/// </summary>
[DefaultValue("")]
[Description("Path to the sitemap.xml file")]
public string Sitemap { get; set; }

Expand Down

0 comments on commit 6a46a76

Please sign in to comment.