@@ -10,19 +10,30 @@ public record DetectionRuleOverviewRef : FileRef
1010{
1111 public IReadOnlyCollection < string > DetectionRuleFolders { get ; }
1212
13+ /// <summary>Optional path to a markdown file whose content prefixes the deprecated rules listing page.</summary>
14+ public string ? DeprecatedFile { get ; init ; }
15+
16+ /// <summary>
17+ /// The resolved deprecated-rules overview FileRef that should appear as a sibling to this ref in the nav.
18+ /// Set by <c>ResolveRuleOverviewReference</c> when a <c>_deprecated</c> subfolder is detected.
19+ /// </summary>
20+ public FileRef ? DeprecatedSiblingRef { get ; init ; }
21+
1322 public DetectionRuleOverviewRef (
1423 string pathRelativeToDocumentationSet ,
1524 string pathRelativeToContainer ,
1625 IReadOnlyCollection < string > detectionRulesFolders ,
1726 IReadOnlyCollection < ITableOfContentsItem > children ,
18- string context
27+ string context ,
28+ string ? deprecatedFile = null
1929 ) : base ( pathRelativeToDocumentationSet , pathRelativeToContainer , false , children , context )
2030 {
2131 PathRelativeToDocumentationSet = pathRelativeToDocumentationSet ;
2232 PathRelativeToContainer = pathRelativeToContainer ;
2333 DetectionRuleFolders = detectionRulesFolders ;
2434 Children = children ;
2535 Context = context ;
36+ DeprecatedFile = deprecatedFile ;
2637 }
2738
2839 public static IReadOnlyCollection < ITableOfContentsItem > CreateTableOfContentItems ( IReadOnlyCollection < IDirectoryInfo > sourceFolders , string context , IDirectoryInfo baseDirectory )
@@ -38,6 +49,18 @@ public static IReadOnlyCollection<ITableOfContentsItem> CreateTableOfContentItem
3849 . ToArray ( ) ;
3950 }
4051
52+ public static IReadOnlyCollection < ITableOfContentsItem > CreateDeprecatedTableOfContentItems ( IReadOnlyCollection < IDirectoryInfo > sourceFolders , string context , IDirectoryInfo baseDirectory )
53+ {
54+ var tocItems = new List < ITableOfContentsItem > ( ) ;
55+ foreach ( var detectionRuleFolder in sourceFolders )
56+ {
57+ var children = ReadDeprecatedDetectionRuleFolder ( detectionRuleFolder , context , baseDirectory ) ;
58+ tocItems . AddRange ( children ) ;
59+ }
60+
61+ return tocItems . ToArray ( ) ;
62+ }
63+
4164 private static IReadOnlyCollection < ITableOfContentsItem > ReadDetectionRuleFolder ( IDirectoryInfo directory , string context , IDirectoryInfo baseDirectory )
4265 {
4366 IReadOnlyCollection < ITableOfContentsItem > children = directory
@@ -62,4 +85,25 @@ private static IReadOnlyCollection<ITableOfContentsItem> ReadDetectionRuleFolder
6285
6386 return children ;
6487 }
88+
89+ private static IReadOnlyCollection < ITableOfContentsItem > ReadDeprecatedDetectionRuleFolder ( IDirectoryInfo directory , string context , IDirectoryInfo baseDirectory )
90+ {
91+ IReadOnlyCollection < ITableOfContentsItem > children = directory
92+ . EnumerateFiles ( "*.*" , SearchOption . AllDirectories )
93+ . Where ( f => ! f . Attributes . HasFlag ( FileAttributes . Hidden ) && ! f . Attributes . HasFlag ( FileAttributes . System ) )
94+ . Where ( f => ! f . Directory ! . Attributes . HasFlag ( FileAttributes . Hidden ) && ! f . Directory ! . Attributes . HasFlag ( FileAttributes . System ) )
95+ // skip symlinks
96+ . Where ( f => f . LinkTarget == null )
97+ . Where ( f => f . Extension == ".toml" )
98+ // only include files inside _deprecated subdirectories
99+ . Where ( f => f . FullName . Contains ( $ "{ Path . DirectorySeparatorChar } _deprecated{ Path . DirectorySeparatorChar } ") )
100+ . Select ( f =>
101+ {
102+ var relativePath = Path . GetRelativePath ( baseDirectory . Parent ! . FullName , f . FullName ) ;
103+ return ( ITableOfContentsItem ) new DetectionRuleRef ( f , relativePath , context ) ;
104+ } )
105+ . ToArray ( ) ;
106+
107+ return children ;
108+ }
65109}
0 commit comments