Skip to content

Commit 28abc4c

Browse files
NetdocsCopilot
andcommitted
fix(tags): only hide shadow tags in production builds
The TagsPlugin's summary already documented that shadow tags are hidden "in production", but the implementation keyed the decision off serve vs. build (hideShadow = shadow && !(IsServe && shadow_on_serve)). That hid shadow tags on every non-serve build, including dev/nonprod deploys, so authors lost visibility of Draft/Internal/ToDo tags on the preview site. Gate hiding on Options.IsProduction so shadow tags are: - visible in `serve` and dev (non-prod) builds, and - hidden only in production (`--prod`) builds, with shadow_on_serve still keeping them visible under `serve --prod`. Add regression tests covering the production/development/serve cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f3badde commit 28abc4c

2 files changed

Lines changed: 62 additions & 3 deletions

File tree

src/Netdocs.Plugins/TagsPlugin.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public void Configure(IPluginContext ctx)
3131

3232
public Task OnBuildStartAsync(SiteContext site, CancellationToken ct)
3333
{
34-
var hideShadow = _shadow && !(site.Options.IsServe && _shadowOnServe);
34+
// Shadow tags are hidden only in production builds, so authors still see Draft/Internal/
35+
// ToDo tags on the dev site and in `serve`. `shadow_on_serve` keeps them visible even when
36+
// serving a production build (e.g. `serve --prod`).
37+
var hideShadow = _shadow && site.Options.IsProduction && !(site.Options.IsServe && _shadowOnServe);
3538
var index = new SortedDictionary<string, List<Page>>(StringComparer.OrdinalIgnoreCase);
3639

3740
foreach (var page in site.Pages)

tests/Netdocs.Core.Tests/TagsPluginTests.cs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ public void AddAsset(string sourcePath, string destRelative) { }
4545
FrontMatter = new Dictionary<string, object?>(),
4646
};
4747

48-
private static SiteContext BuildSite(params Page[] pages)
48+
private static SiteContext BuildSite(params Page[] pages) => BuildSite(new BuildOptions(), pages);
49+
50+
private static SiteContext BuildSite(BuildOptions options, params Page[] pages)
4951
{
5052
var site = new SiteContext
5153
{
5254
Config = new SiteConfig { ProjectRoot = Path.GetTempPath() },
53-
Options = new BuildOptions(),
55+
Options = options,
5456
LoggerFactory = NullLoggerFactory.Instance,
5557
};
5658
foreach (var p in pages) site.Pages.Add(p);
@@ -64,6 +66,18 @@ private static TagsPlugin Configured()
6466
return plugin;
6567
}
6668

69+
private static TagsPlugin ConfiguredWithShadow()
70+
{
71+
var plugin = new TagsPlugin();
72+
plugin.Configure(new FakeContext(new Dictionary<string, object?>
73+
{
74+
["export"] = false,
75+
["shadow"] = true,
76+
["shadow_tags"] = new List<object?> { "Draft", "Internal", "ToDo" },
77+
}));
78+
return plugin;
79+
}
80+
6781
[Fact]
6882
public async Task BareMarker_RendersFullIndex()
6983
{
@@ -175,4 +189,46 @@ public async Task Heading_Anchor_SlugifiesSpacesAndPunctuationPerSegment()
175189
Assert.Contains("{ #tag:energy-monitoring }", index.RawMarkdown);
176190
Assert.Contains("{ #tag:development/net }", index.RawMarkdown);
177191
}
192+
193+
[Fact]
194+
public async Task ShadowTags_HiddenInProductionBuild()
195+
{
196+
var draft = Tagged("draft.md", "Draft Page", "Draft", "Process");
197+
var index = Marker("tags/index.md", "<!-- material/tags -->");
198+
var site = BuildSite(new BuildOptions { IsProduction = true }, draft, index);
199+
200+
await ConfiguredWithShadow().OnBuildStartAsync(site, CancellationToken.None);
201+
202+
// The shadow tag is dropped from the index, but non-shadow tags on the same page remain.
203+
Assert.DoesNotContain("## Draft", index.RawMarkdown);
204+
Assert.Contains("## Process", index.RawMarkdown);
205+
Assert.Equal(new[] { "Process" }, (IEnumerable<string>)draft.Meta["tags"]!);
206+
}
207+
208+
[Fact]
209+
public async Task ShadowTags_VisibleInDevelopmentBuild()
210+
{
211+
var draft = Tagged("draft.md", "Draft Page", "Draft", "Process");
212+
var index = Marker("tags/index.md", "<!-- material/tags -->");
213+
// Non-production build (e.g. the nonprod/dev deploy) keeps shadow tags visible.
214+
var site = BuildSite(new BuildOptions { IsProduction = false }, draft, index);
215+
216+
await ConfiguredWithShadow().OnBuildStartAsync(site, CancellationToken.None);
217+
218+
Assert.Contains("## Draft", index.RawMarkdown);
219+
Assert.Contains("## Process", index.RawMarkdown);
220+
}
221+
222+
[Fact]
223+
public async Task ShadowTags_VisibleWhenServingProductionBuild()
224+
{
225+
var draft = Tagged("draft.md", "Draft Page", "Draft");
226+
var index = Marker("tags/index.md", "<!-- material/tags -->");
227+
// shadow_on_serve (default true) keeps them visible even under `serve --prod`.
228+
var site = BuildSite(new BuildOptions { IsProduction = true, IsServe = true }, draft, index);
229+
230+
await ConfiguredWithShadow().OnBuildStartAsync(site, CancellationToken.None);
231+
232+
Assert.Contains("## Draft", index.RawMarkdown);
233+
}
178234
}

0 commit comments

Comments
 (0)