Skip to content

Commit 4f530f4

Browse files
gcerikMaxMelcher
authored andcommitted
added hierarchical export for single file
1 parent b943426 commit 4f530f4

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

AzureDevOps.WikiPDFExport/WikiPDFExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public async Task<bool> Export()
109109
_wiki = new ExportedWikiDoc(_options.Path);
110110

111111
IWikiDirectoryScanner scanner = !string.IsNullOrEmpty(_options.Single)
112-
? new SingleFileScanner(_options.Single, _logger)
112+
? new SingleFileScanner(_options.Single, _wiki.exportPath(), _options, _logger)
113113
: (_options.IncludeUnlistedPages
114114
? new WikiDirectoryScanner(_wiki.exportPath(), _options, _logger)
115115
: new WikiOptionFilesScanner(_wiki.exportPath(), _options, _logger));

AzureDevOps.WikiPDFExport/WikiScanners/SingleFileScanner.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
using Microsoft.Extensions.Logging;
2+
using Microsoft.Extensions.Options;
3+
using Microsoft.TeamFoundation.TestManagement.WebApi;
4+
using Microsoft.TeamFoundation.Wiki.WebApi;
25
using System;
36
using System.Collections.Generic;
47
using System.IO;
8+
using System.Linq;
59

610
namespace azuredevops_export_wiki
711
{
8-
internal class SingleFileScanner : IWikiDirectoryScanner
12+
internal class SingleFileScanner : WikiOptionFilesScanner
913
{
1014
private readonly string singleFilePath;
11-
private ILogger logger;
1215

13-
public SingleFileScanner(string filePath, ILogger logger)
16+
public SingleFileScanner(string filePath, string wikiPath, Options options, ILogger logger)
17+
: base(wikiPath, options, logger)
1418
{
1519
this.singleFilePath = filePath;
16-
this.logger = logger;
1720
}
1821

19-
public IList<MarkdownFile> Scan()
22+
public override IList<MarkdownFile> Scan()
2023
{
21-
var filePath = Path.GetFullPath(singleFilePath);
22-
var directory = new DirectoryInfo(Path.GetFullPath(filePath));
24+
var allFiles = base.Scan();
25+
var current = allFiles.FirstOrDefault(m => m.FileRelativePath.Contains(singleFilePath));
26+
var idx = allFiles.IndexOf(current);
2327

24-
if (!File.Exists(filePath))
28+
if (current is null || idx == -1)
2529
{
26-
logger.Log($"Single-File [-s] {filePath} specified not found" + filePath, LogLevel.Error);
30+
logger.Log($"Single-File [-s] {singleFilePath} specified not found" + singleFilePath, LogLevel.Error);
2731
throw new ArgumentException($"{singleFilePath} not found");
2832
}
33+
var result = new List<MarkdownFile>() { current };
2934

30-
var relativePath = filePath.Substring(directory.FullName.Length);
35+
if (allFiles.Count > idx)
36+
{
37+
foreach (var item in allFiles.Skip(idx + 1))
38+
{
39+
if (item.Level > current.Level)
40+
{
41+
result.Add(item);
42+
}
43+
else
44+
break;
45+
}
46+
}
3147

32-
return new List<MarkdownFile>() {
33-
new MarkdownFile(new FileInfo(filePath), relativePath, 0, "/")
34-
};
48+
return result;
3549
}
3650

3751
}

AzureDevOps.WikiPDFExport/WikiScanners/WikiOptionFilesScanner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class WikiOptionFilesScanner : WikiScannerBase, IWikiDirectoryScanner,
1212
public WikiOptionFilesScanner(string wikiPath, Options options, ILogger logger)
1313
: base(wikiPath, options, logger) { }
1414

15-
public IList<MarkdownFile> Scan()
15+
public virtual IList<MarkdownFile> Scan()
1616
{
1717
return ReadOrderFiles(wikiPath, 0, excludeRegexes); // root level
1818
}

0 commit comments

Comments
 (0)