Skip to content

Commit f6f1d81

Browse files
authored
Make assembler build explicit on BuildContext (#1222)
1 parent 3a60a07 commit f6f1d81

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

docs/_docset.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ subs:
1313
serverless-short: Serverless
1414
ece: "Elastic Cloud Enterprise"
1515
eck: "Elastic Cloud on Kubernetes"
16-
ech: "Elastic Cloud Hosted"
17-
kib: "Kibana"
18-
16+
1917
features:
2018
primary-nav: false
2119

src/Elastic.Markdown/BuildContext.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ public record BuildContext : IDocumentationContext
3030

3131
public bool Force { get; init; }
3232

33-
public bool SkipDocumentationState { get; init; }
33+
public bool SkipDocumentationState { get; private set; }
34+
35+
public bool AssemblerBuild
36+
{
37+
get => _assemblerBuild;
38+
init
39+
{
40+
_assemblerBuild = value;
41+
SkipDocumentationState = value;
42+
}
43+
}
3444

3545
// This property is used to determine if the site should be indexed by search engines
3646
public bool AllowIndexing { get; init; }
@@ -41,6 +51,8 @@ public record BuildContext : IDocumentationContext
4151
public Uri? CanonicalBaseUrl { get; init; }
4252

4353
private readonly string? _urlPathPrefix;
54+
private readonly bool _assemblerBuild;
55+
4456
public string? UrlPathPrefix
4557
{
4658
get => string.IsNullOrWhiteSpace(_urlPathPrefix) ? "" : $"/{_urlPathPrefix.Trim('/')}";

src/Elastic.Markdown/DocumentationGenerator.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public DocumentationGenerator(
6565
DocumentationSet = docSet;
6666
Context = docSet.Context;
6767
Resolver = docSet.LinkResolver;
68-
HtmlWriter = new HtmlWriter(DocumentationSet, _writeFileSystem, new DescriptionGenerator(), navigationHtmlWriter, legacyUrlMapper, positionalNavigation);
68+
HtmlWriter = new HtmlWriter(DocumentationSet, _writeFileSystem, new DescriptionGenerator(), navigationHtmlWriter, legacyUrlMapper,
69+
positionalNavigation);
6970
_documentationFileExporter =
7071
documentationExporter
7172
?? docSet.EnabledExtensions.FirstOrDefault(e => e.FileExporter != null)?.FileExporter
@@ -97,20 +98,20 @@ public async Task<GenerationResult> GenerateAll(Cancel ctx)
9798
{
9899
var result = new GenerationResult();
99100

100-
HashSet<string> offendingFiles = [];
101-
var outputSeenChanges = DateTimeOffset.MinValue;
102-
if (Context.SkipDocumentationState)
103-
DocumentationSet.ClearOutputDirectory();
104-
else
105-
{
106-
var generationState = GetPreviousGenerationState();
107-
if (Context.Force || generationState == null)
108-
DocumentationSet.ClearOutputDirectory();
101+
var generationState = Context.SkipDocumentationState ? null : GetPreviousGenerationState();
109102

110-
if (CompilationNotNeeded(generationState, out offendingFiles, out outputSeenChanges))
111-
return result;
103+
// clear output directory if force is true but never for assembler builds since these build multiple times to the output.
104+
if (Context is { AssemblerBuild: false, Force: true }
105+
// clear the output directory if force is false but generation state is null, except for assembler builds.
106+
|| (Context is { AssemblerBuild: false, Force: false } && generationState == null))
107+
{
108+
_logger.LogInformation($"Clearing output directory");
109+
DocumentationSet.ClearOutputDirectory();
112110
}
113111

112+
if (CompilationNotNeeded(generationState, out var offendingFiles, out var outputSeenChanges))
113+
return result;
114+
114115
_logger.LogInformation($"Fetching external links");
115116
_ = await Resolver.FetchLinks(ctx);
116117

src/tooling/docs-assembler/Navigation/AssemblerDocumentationSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public AssemblerDocumentationSet(
6969
CookiesWin = env.GoogleTagManager.CookiesWin
7070
},
7171
CanonicalBaseUrl = new Uri("https://www.elastic.co"), // Always use the production URL. In case a page is leaked to a search engine, it should point to the production site.
72-
SkipDocumentationState = true,
72+
AssemblerBuild = true
7373
};
7474
BuildContext = buildContext;
7575

0 commit comments

Comments
 (0)