Skip to content

Restrict docset.yml configs that define toc.yml sections to ONLY link to sub toc.yml files #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/_docset.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
project: 'doc-builder'

Check notice on line 1 in docs/_docset.yml

View workflow job for this annotation

GitHub Actions / build

Substitution key 'ece' is not used in any file

Check notice on line 1 in docs/_docset.yml

View workflow job for this annotation

GitHub Actions / build

Substitution key 'eck' is not used in any file
max_toc_depth: 2
# indicates this documentation set is not linkable by assembler.
# relaxes a few restrictions around toc building and file placement
dev_docs: true
cross_links:
- docs-content
exclude:
Expand Down
14 changes: 12 additions & 2 deletions src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public record ConfigurationFile : DocumentationFile
private FeatureFlags? _featureFlags;
public FeatureFlags Features => _featureFlags ??= new FeatureFlags(_features);

/// This is a documentation set that is not linked to by assembler.
/// Setting this to true relaxes a few restrictions such as mixing toc references with file and folder reference
public bool DevelopmentDocs { get; }

public ConfigurationFile(BuildContext context)
: base(context.ConfigurationPath, context.DocumentationSourceDirectory)
{
Expand Down Expand Up @@ -74,6 +78,9 @@ public ConfigurationFile(BuildContext context)
case "max_toc_depth":
MaxTocDepth = int.TryParse(reader.ReadString(entry.Entry), out var maxTocDepth) ? maxTocDepth : 1;
break;
case "dev_docs":
DevelopmentDocs = bool.TryParse(reader.ReadString(entry.Entry), out var devDocs) && devDocs;
break;
case "exclude":
var excludes = YamlStreamReader.ReadStringArray(entry.Entry);
Exclude = [.. excludes.Where(s => !string.IsNullOrEmpty(s)).Select(Glob.Parse)];
Expand Down Expand Up @@ -111,8 +118,11 @@ public ConfigurationFile(BuildContext context)
{
case "toc":
var toc = new TableOfContentsConfiguration(this, _context, 0, "");
var entries = toc.ReadChildren(reader, entry.Entry);
TableOfContents = entries;
var children = toc.ReadChildren(reader, entry.Entry);
var tocEntries = children.OfType<TocReference>().ToArray();
if (!DevelopmentDocs && tocEntries.Length > 0 && children.Count != tocEntries.Length)
reader.EmitError("toc links to other toc sections it may only contain other toc references", entry.Key);
TableOfContents = children;
Files = toc.Files; //side-effect ripe for refactor
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Elastic.Markdown/IO/Configuration/ITocItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ public interface ITocItem;
public record FileReference(string Path, bool Found, bool Hidden, IReadOnlyCollection<ITocItem> Children) : ITocItem;

public record FolderReference(string Path, bool Found, bool InNav, IReadOnlyCollection<ITocItem> Children) : ITocItem;

public record TocReference(string Path, bool Found, bool InNav, IReadOnlyCollection<ITocItem> Children) : FolderReference(Path, Found, InNav, Children);
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public IReadOnlyCollection<ITocItem> ReadChildren(YamlStreamReader reader, KeyVa
foreach (var f in toc.Files)
_ = Files.Add(f);

return [new FolderReference($"{parentPath}".TrimStart(Path.DirectorySeparatorChar), folderFound, inNav, toc.TableOfContents)];
return [new TocReference($"{parentPath}".TrimStart(Path.DirectorySeparatorChar), folderFound, inNav, toc.TableOfContents)];
}

if (file is not null)
Expand Down
Loading