Skip to content

Commit 1d36c3d

Browse files
authored
Add --allow-indexing option for the generate command (#264)
* Add `--allow-indexing` option for the generate command * Cleanup
1 parent d6b668f commit 1d36c3d

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

src/Elastic.Markdown/BuildContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public string? UrlPathPrefix
3030
init => _urlPathPrefix = value;
3131
}
3232

33+
// This property is used to determine if the site should be indexed by search engines
34+
public bool AllowIndexing { get; init; }
35+
3336
private readonly string? _urlPathPrefix;
3437

3538
public BuildContext(IFileSystem fileSystem)

src/Elastic.Markdown/Slices/HtmlWriter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public async Task<string> RenderLayout(MarkdownFile markdown, Cancel ctx = defau
6565
NavigationHtml = navigationHtml,
6666
UrlPathPrefix = markdown.UrlPathPrefix,
6767
Applies = markdown.YamlFrontMatter?.AppliesTo,
68-
GithubEditUrl = editUrl
68+
GithubEditUrl = editUrl,
69+
AllowIndexing = DocumentationSet.Context.AllowIndexing
6970
});
7071
return await slice.RenderAsync(cancellationToken: ctx);
7172
}

src/Elastic.Markdown/Slices/Index.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
Next = Model.NextDocument,
1212
NavigationHtml = Model.NavigationHtml,
1313
UrlPathPrefix = Model.UrlPathPrefix,
14-
GithubEditUrl = Model.GithubEditUrl
14+
GithubEditUrl = Model.GithubEditUrl,
15+
AllowIndexing = Model.AllowIndexing,
1516
};
1617
}
1718
<section id="elastic-docs-v3">

src/Elastic.Markdown/Slices/Layout/_Head.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<head>
33
<meta charset="utf-8">
44
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta name="robots" content="@(Model.AllowIndexing ? "index, follow" : "noindex, nofollow")">
56
<title>@Model.Title</title>
67
<link rel="index" title="Index" href="@Model.Link("genindex.html")"/>
78
<link rel="search" title="Search" href="@Model.Link("search.html")"/>

src/Elastic.Markdown/Slices/_ViewModels.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class IndexViewModel
2020
public required string? UrlPathPrefix { get; init; }
2121
public required string? GithubEditUrl { get; init; }
2222
public required Deployment? Applies { get; init; }
23+
public required bool AllowIndexing { get; init; }
2324
}
2425

2526
public class LayoutViewModel
@@ -33,6 +34,7 @@ public class LayoutViewModel
3334
public required string NavigationHtml { get; set; }
3435
public required string? UrlPathPrefix { get; set; }
3536
public required string? GithubEditUrl { get; set; }
37+
public required bool AllowIndexing { get; init; }
3638

3739
private MarkdownFile[]? _parents;
3840
public MarkdownFile[] Parents

src/docs-builder/Cli/Commands.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public async Task Serve(string? path = null, Cancel ctx = default)
4040
/// <param name="pathPrefix"> Specifies the path prefix for urls </param>
4141
/// <param name="force"> Force a full rebuild of the destination folder</param>
4242
/// <param name="strict"> Treat warnings as errors and fail the build on warnings</param>
43+
/// <param name="allowIndexing"> Allow indexing and following of html files</param>
4344
/// <param name="ctx"></param>
4445
[Command("generate")]
4546
[ConsoleAppFilter<StopwatchFilter>]
@@ -50,6 +51,7 @@ public async Task<int> Generate(
5051
string? pathPrefix = null,
5152
bool? force = null,
5253
bool? strict = null,
54+
bool? allowIndexing = null,
5355
Cancel ctx = default
5456
)
5557
{
@@ -59,7 +61,8 @@ public async Task<int> Generate(
5961
{
6062
UrlPathPrefix = pathPrefix,
6163
Force = force ?? false,
62-
Collector = new ConsoleDiagnosticsCollector(logger, githubActionsService)
64+
Collector = new ConsoleDiagnosticsCollector(logger, githubActionsService),
65+
AllowIndexing = allowIndexing != null
6366
};
6467
var set = new DocumentationSet(context);
6568
var generator = new DocumentationGenerator(set, logger);
@@ -81,6 +84,7 @@ public async Task<int> Generate(
8184
/// <param name="pathPrefix"> Specifies the path prefix for urls </param>
8285
/// <param name="force"> Force a full rebuild of the destination folder</param>
8386
/// <param name="strict"> Treat warnings as errors and fail the build on warnings</param>
87+
/// <param name="allowIndexing"> Allow indexing and following of html files</param>
8488
/// <param name="ctx"></param>
8589
[Command("")]
8690
[ConsoleAppFilter<StopwatchFilter>]
@@ -91,7 +95,8 @@ public async Task<int> GenerateDefault(
9195
string? pathPrefix = null,
9296
bool? force = null,
9397
bool? strict = null,
98+
bool? allowIndexing = null,
9499
Cancel ctx = default
95100
) =>
96-
await Generate(path, output, pathPrefix, force, strict, ctx);
101+
await Generate(path, output, pathPrefix, force, strict, allowIndexing, ctx);
97102
}

0 commit comments

Comments
 (0)