Skip to content

Commit

Permalink
Add --allow-indexing option for the generate command (#264)
Browse files Browse the repository at this point in the history
* Add `--allow-indexing` option for the generate command

* Cleanup
  • Loading branch information
reakaleek authored Jan 17, 2025
1 parent d6b668f commit 1d36c3d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Elastic.Markdown/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public string? UrlPathPrefix
init => _urlPathPrefix = value;
}

// This property is used to determine if the site should be indexed by search engines
public bool AllowIndexing { get; init; }

private readonly string? _urlPathPrefix;

public BuildContext(IFileSystem fileSystem)
Expand Down
3 changes: 2 additions & 1 deletion src/Elastic.Markdown/Slices/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public async Task<string> RenderLayout(MarkdownFile markdown, Cancel ctx = defau
NavigationHtml = navigationHtml,
UrlPathPrefix = markdown.UrlPathPrefix,
Applies = markdown.YamlFrontMatter?.AppliesTo,
GithubEditUrl = editUrl
GithubEditUrl = editUrl,
AllowIndexing = DocumentationSet.Context.AllowIndexing
});
return await slice.RenderAsync(cancellationToken: ctx);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Elastic.Markdown/Slices/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
Next = Model.NextDocument,
NavigationHtml = Model.NavigationHtml,
UrlPathPrefix = Model.UrlPathPrefix,
GithubEditUrl = Model.GithubEditUrl
GithubEditUrl = Model.GithubEditUrl,
AllowIndexing = Model.AllowIndexing,
};
}
<section id="elastic-docs-v3">
Expand Down
1 change: 1 addition & 0 deletions src/Elastic.Markdown/Slices/Layout/_Head.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="@(Model.AllowIndexing ? "index, follow" : "noindex, nofollow")">
<title>@Model.Title</title>
<link rel="index" title="Index" href="@Model.Link("genindex.html")"/>
<link rel="search" title="Search" href="@Model.Link("search.html")"/>
Expand Down
2 changes: 2 additions & 0 deletions src/Elastic.Markdown/Slices/_ViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class IndexViewModel
public required string? UrlPathPrefix { get; init; }
public required string? GithubEditUrl { get; init; }
public required Deployment? Applies { get; init; }
public required bool AllowIndexing { get; init; }
}

public class LayoutViewModel
Expand All @@ -33,6 +34,7 @@ public class LayoutViewModel
public required string NavigationHtml { get; set; }
public required string? UrlPathPrefix { get; set; }
public required string? GithubEditUrl { get; set; }
public required bool AllowIndexing { get; init; }

private MarkdownFile[]? _parents;
public MarkdownFile[] Parents
Expand Down
9 changes: 7 additions & 2 deletions src/docs-builder/Cli/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public async Task Serve(string? path = null, Cancel ctx = default)
/// <param name="pathPrefix"> Specifies the path prefix for urls </param>
/// <param name="force"> Force a full rebuild of the destination folder</param>
/// <param name="strict"> Treat warnings as errors and fail the build on warnings</param>
/// <param name="allowIndexing"> Allow indexing and following of html files</param>
/// <param name="ctx"></param>
[Command("generate")]
[ConsoleAppFilter<StopwatchFilter>]
Expand All @@ -50,6 +51,7 @@ public async Task<int> Generate(
string? pathPrefix = null,
bool? force = null,
bool? strict = null,
bool? allowIndexing = null,
Cancel ctx = default
)
{
Expand All @@ -59,7 +61,8 @@ public async Task<int> Generate(
{
UrlPathPrefix = pathPrefix,
Force = force ?? false,
Collector = new ConsoleDiagnosticsCollector(logger, githubActionsService)
Collector = new ConsoleDiagnosticsCollector(logger, githubActionsService),
AllowIndexing = allowIndexing != null
};
var set = new DocumentationSet(context);
var generator = new DocumentationGenerator(set, logger);
Expand All @@ -81,6 +84,7 @@ public async Task<int> Generate(
/// <param name="pathPrefix"> Specifies the path prefix for urls </param>
/// <param name="force"> Force a full rebuild of the destination folder</param>
/// <param name="strict"> Treat warnings as errors and fail the build on warnings</param>
/// <param name="allowIndexing"> Allow indexing and following of html files</param>
/// <param name="ctx"></param>
[Command("")]
[ConsoleAppFilter<StopwatchFilter>]
Expand All @@ -91,7 +95,8 @@ public async Task<int> GenerateDefault(
string? pathPrefix = null,
bool? force = null,
bool? strict = null,
bool? allowIndexing = null,
Cancel ctx = default
) =>
await Generate(path, output, pathPrefix, force, strict, ctx);
await Generate(path, output, pathPrefix, force, strict, allowIndexing, ctx);
}

0 comments on commit 1d36c3d

Please sign in to comment.