Skip to content

Commit

Permalink
added hierarchical export for single file
Browse files Browse the repository at this point in the history
  • Loading branch information
gcerik authored and MaxMelcher committed Oct 10, 2022
1 parent b943426 commit 4f530f4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion AzureDevOps.WikiPDFExport/WikiPDFExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task<bool> Export()
_wiki = new ExportedWikiDoc(_options.Path);

IWikiDirectoryScanner scanner = !string.IsNullOrEmpty(_options.Single)
? new SingleFileScanner(_options.Single, _logger)
? new SingleFileScanner(_options.Single, _wiki.exportPath(), _options, _logger)
: (_options.IncludeUnlistedPages
? new WikiDirectoryScanner(_wiki.exportPath(), _options, _logger)
: new WikiOptionFilesScanner(_wiki.exportPath(), _options, _logger));
Expand Down
40 changes: 27 additions & 13 deletions AzureDevOps.WikiPDFExport/WikiScanners/SingleFileScanner.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.TeamFoundation.TestManagement.WebApi;
using Microsoft.TeamFoundation.Wiki.WebApi;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace azuredevops_export_wiki
{
internal class SingleFileScanner : IWikiDirectoryScanner
internal class SingleFileScanner : WikiOptionFilesScanner
{
private readonly string singleFilePath;
private ILogger logger;

public SingleFileScanner(string filePath, ILogger logger)
public SingleFileScanner(string filePath, string wikiPath, Options options, ILogger logger)
: base(wikiPath, options, logger)
{
this.singleFilePath = filePath;
this.logger = logger;
}

public IList<MarkdownFile> Scan()
public override IList<MarkdownFile> Scan()
{
var filePath = Path.GetFullPath(singleFilePath);
var directory = new DirectoryInfo(Path.GetFullPath(filePath));
var allFiles = base.Scan();
var current = allFiles.FirstOrDefault(m => m.FileRelativePath.Contains(singleFilePath));
var idx = allFiles.IndexOf(current);

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

var relativePath = filePath.Substring(directory.FullName.Length);
if (allFiles.Count > idx)
{
foreach (var item in allFiles.Skip(idx + 1))
{
if (item.Level > current.Level)
{
result.Add(item);
}
else
break;
}
}

return new List<MarkdownFile>() {
new MarkdownFile(new FileInfo(filePath), relativePath, 0, "/")
};
return result;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class WikiOptionFilesScanner : WikiScannerBase, IWikiDirectoryScanner,
public WikiOptionFilesScanner(string wikiPath, Options options, ILogger logger)
: base(wikiPath, options, logger) { }

public IList<MarkdownFile> Scan()
public virtual IList<MarkdownFile> Scan()
{
return ReadOrderFiles(wikiPath, 0, excludeRegexes); // root level
}
Expand Down

0 comments on commit 4f530f4

Please sign in to comment.