ExcludeSchemes
This commit is contained in:
parent
40b12d17f9
commit
2b6e65b730
@ -46,7 +46,7 @@ internal static partial class HelperMarkdown
|
|||||||
internal static string[] GetFiles(AppSettings appSettings, string directory)
|
internal static string[] GetFiles(AppSettings appSettings, string directory)
|
||||||
{
|
{
|
||||||
string[] results = Directory.GetFiles(directory, "*.md", SearchOption.AllDirectories).
|
string[] results = Directory.GetFiles(directory, "*.md", SearchOption.AllDirectories).
|
||||||
Where(l => !appSettings.Exclude.Any(m => l.Contains(m))).ToArray();
|
Where(l => !appSettings.ExcludeDirectoryNames.Any(m => l.Contains(m))).ToArray();
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +151,14 @@ internal static partial class HelperMarkdown
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<(MarkdownFile, string[])> GetCollection(AppSettings appSettings, Record record)
|
||||||
|
{
|
||||||
|
List<(MarkdownFile, string[])> results;
|
||||||
|
string[] files = GetFiles(appSettings, record.Source);
|
||||||
|
results = GetCollection(appSettings, files);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
private static int SetFrontMatterAndH1(AppSettings appSettings, List<(MarkdownFile, string[])> collection)
|
private static int SetFrontMatterAndH1(AppSettings appSettings, List<(MarkdownFile, string[])> collection)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@ -342,8 +350,7 @@ internal static partial class HelperMarkdown
|
|||||||
private static Dictionary<string, List<MarkdownFile>> GetKeyValuePairs(AppSettings appSettings, Record record)
|
private static Dictionary<string, List<MarkdownFile>> GetKeyValuePairs(AppSettings appSettings, Record record)
|
||||||
{
|
{
|
||||||
Dictionary<string, List<MarkdownFile>> results;
|
Dictionary<string, List<MarkdownFile>> results;
|
||||||
string[] files = GetFiles(appSettings, record.Source);
|
List<(MarkdownFile MarkdownFile, string[] Lines)> collection = GetCollection(appSettings, record);
|
||||||
List<(MarkdownFile MarkdownFile, string[] Lines)> collection = GetCollection(appSettings, files);
|
|
||||||
results = GetKeyValuePairs(collection);
|
results = GetKeyValuePairs(collection);
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
@ -507,6 +514,50 @@ internal static partial class HelperMarkdown
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static (string?, string?) GetRelativePath(List<(MarkdownFile MarkdownFile, string[] Lines)> collection, MarkdownFile markdownFile, string file)
|
||||||
|
{
|
||||||
|
string? title;
|
||||||
|
string? relativePath;
|
||||||
|
List<(string RelativePath, string Title)> results = new();
|
||||||
|
foreach ((MarkdownFile MarkdownFile, string[] Lines) item in collection)
|
||||||
|
{
|
||||||
|
if (item.MarkdownFile.File != file)
|
||||||
|
continue;
|
||||||
|
results.Add((Path.GetRelativePath(markdownFile.Directory, Path.GetFullPath(item.MarkdownFile.File)), item.MarkdownFile.H1));
|
||||||
|
}
|
||||||
|
if (results.Count == 1)
|
||||||
|
(relativePath, title) = (results.First().RelativePath, results.First().Title);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
results.Clear();
|
||||||
|
string fileLowered = file.ToLower();
|
||||||
|
foreach ((MarkdownFile MarkdownFile, string[] Lines) item in collection)
|
||||||
|
{
|
||||||
|
if (item.MarkdownFile.File.ToLower() != fileLowered)
|
||||||
|
continue;
|
||||||
|
results.Add((Path.GetRelativePath(markdownFile.Directory, Path.GetFullPath(item.MarkdownFile.File)), item.MarkdownFile.H1));
|
||||||
|
}
|
||||||
|
if (results.Count == 1)
|
||||||
|
(relativePath, title) = (results.First().RelativePath, results.First().Title);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
results.Clear();
|
||||||
|
string fileFullPath = Path.GetFullPath(fileLowered);
|
||||||
|
foreach ((MarkdownFile MarkdownFile, string[] Lines) item in collection)
|
||||||
|
{
|
||||||
|
if (Path.GetFullPath(item.MarkdownFile.File).ToLower() != fileFullPath)
|
||||||
|
continue;
|
||||||
|
results.Add((Path.GetRelativePath(markdownFile.Directory, Path.GetFullPath(item.MarkdownFile.File)), item.MarkdownFile.H1));
|
||||||
|
}
|
||||||
|
if (results.Count == 1)
|
||||||
|
(relativePath, title) = (results.First().RelativePath, results.First().Title);
|
||||||
|
else
|
||||||
|
(relativePath, title) = (null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (relativePath, title);
|
||||||
|
}
|
||||||
|
|
||||||
private static int ConvertFileToSlugName(AppSettings appSettings, ILogger<Worker> logger, Record record, List<(MarkdownFile MarkdownFile, string[] Lines)> collection)
|
private static int ConvertFileToSlugName(AppSettings appSettings, ILogger<Worker> logger, Record record, List<(MarkdownFile MarkdownFile, string[] Lines)> collection)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@ -526,7 +577,7 @@ internal static partial class HelperMarkdown
|
|||||||
string segmentsALast;
|
string segmentsALast;
|
||||||
string? relativePath;
|
string? relativePath;
|
||||||
string segmentsBFirst;
|
string segmentsBFirst;
|
||||||
Dictionary<string, List<MarkdownFile>> keyValuePairs = record.StartAt is null ? GetKeyValuePairs(collection) : GetKeyValuePairs(appSettings, record);
|
List<(MarkdownFile MarkdownFile, string[] Lines)> sourceCollection = record.StartAt is null ? collection : GetCollection(appSettings, record);
|
||||||
foreach ((MarkdownFile markdownFile, string[] lines) in collection)
|
foreach ((MarkdownFile markdownFile, string[] lines) in collection)
|
||||||
{
|
{
|
||||||
if (markdownFile.FileNameWithoutExtension == "index")
|
if (markdownFile.FileNameWithoutExtension == "index")
|
||||||
@ -540,7 +591,7 @@ internal static partial class HelperMarkdown
|
|||||||
if (segmentsA.Length != 2)
|
if (segmentsA.Length != 2)
|
||||||
continue;
|
continue;
|
||||||
segmentsALast = segmentsA.Last();
|
segmentsALast = segmentsA.Last();
|
||||||
if (segmentsALast.StartsWith("http:") || segmentsALast.StartsWith("https:") || segmentsALast.StartsWith("rdp:") || segmentsALast.StartsWith("onenote:"))
|
if (appSettings.ExcludeSchemes.Any(l => segmentsALast.StartsWith(l)))
|
||||||
continue;
|
continue;
|
||||||
segmentsB = segmentsALast.Split(")");
|
segmentsB = segmentsALast.Split(")");
|
||||||
if (segmentsB.Length != 2)
|
if (segmentsB.Length != 2)
|
||||||
@ -554,7 +605,7 @@ internal static partial class HelperMarkdown
|
|||||||
checkFileName = fileName.ToLower().Replace("%20", "-").Replace(' ', '-');
|
checkFileName = fileName.ToLower().Replace("%20", "-").Replace(' ', '-');
|
||||||
checkName = Path.Combine(directory, checkFileName);
|
checkName = Path.Combine(directory, checkFileName);
|
||||||
segmentsC = segmentsA.First().Split('[');
|
segmentsC = segmentsA.First().Split('[');
|
||||||
(relativePath, title) = GetRelativePath(keyValuePairs, markdownFile, file);
|
(relativePath, title) = GetRelativePath(sourceCollection, markdownFile, file);
|
||||||
if (relativePath is null)
|
if (relativePath is null)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Didn't find {line} in <{file}>", lines[i], markdownFile.FileNameWithoutExtension);
|
logger.LogInformation("Didn't find {line} in <{file}>", lines[i], markdownFile.FileNameWithoutExtension);
|
||||||
@ -748,7 +799,7 @@ internal static partial class HelperMarkdown
|
|||||||
if (segmentsA.Length != 2)
|
if (segmentsA.Length != 2)
|
||||||
continue;
|
continue;
|
||||||
segmentsALast = segmentsA.Last();
|
segmentsALast = segmentsA.Last();
|
||||||
if (segmentsALast.StartsWith("http:") || segmentsALast.StartsWith("https:") || segmentsALast.StartsWith("rdp:") || segmentsALast.StartsWith("onenote:"))
|
if (appSettings.ExcludeSchemes.Any(l => segmentsALast.StartsWith(l)))
|
||||||
continue;
|
continue;
|
||||||
segmentsB = segmentsALast.Split(")");
|
segmentsB = segmentsALast.Split(")");
|
||||||
if (segmentsB.Length != 2)
|
if (segmentsB.Length != 2)
|
||||||
|
@ -5,7 +5,8 @@ namespace File_Folder_Helper.Models;
|
|||||||
|
|
||||||
public record AppSettings(string Company,
|
public record AppSettings(string Company,
|
||||||
string DefaultNoteType,
|
string DefaultNoteType,
|
||||||
string[] Exclude,
|
string[] ExcludeDirectoryNames,
|
||||||
|
string[] ExcludeSchemes,
|
||||||
string WorkingDirectoryName)
|
string WorkingDirectoryName)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@ public class AppSettings
|
|||||||
|
|
||||||
public string? Company { get; set; }
|
public string? Company { get; set; }
|
||||||
public string? DefaultNoteType { get; set; }
|
public string? DefaultNoteType { get; set; }
|
||||||
public string[]? Exclude { get; set; }
|
public string[]? ExcludeDirectoryNames { get; set; }
|
||||||
|
public string[]? ExcludeSchemes { get; set; }
|
||||||
public string? WorkingDirectoryName { get; set; }
|
public string? WorkingDirectoryName { get; set; }
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@ -25,14 +26,17 @@ public class AppSettings
|
|||||||
throw new NullReferenceException(nameof(appSettings.Company));
|
throw new NullReferenceException(nameof(appSettings.Company));
|
||||||
if (appSettings?.DefaultNoteType is null)
|
if (appSettings?.DefaultNoteType is null)
|
||||||
throw new NullReferenceException(nameof(appSettings.DefaultNoteType));
|
throw new NullReferenceException(nameof(appSettings.DefaultNoteType));
|
||||||
if (appSettings?.Exclude is null)
|
if (appSettings?.ExcludeDirectoryNames is null)
|
||||||
throw new NullReferenceException(nameof(appSettings.Exclude));
|
throw new NullReferenceException(nameof(appSettings.ExcludeDirectoryNames));
|
||||||
|
if (appSettings?.ExcludeSchemes is null)
|
||||||
|
throw new NullReferenceException(nameof(appSettings.ExcludeSchemes));
|
||||||
if (appSettings?.WorkingDirectoryName is null)
|
if (appSettings?.WorkingDirectoryName is null)
|
||||||
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
|
throw new NullReferenceException(nameof(appSettings.WorkingDirectoryName));
|
||||||
result = new(
|
result = new(
|
||||||
appSettings.Company,
|
appSettings.Company,
|
||||||
appSettings.DefaultNoteType,
|
appSettings.DefaultNoteType,
|
||||||
appSettings.Exclude,
|
appSettings.ExcludeDirectoryNames,
|
||||||
|
appSettings.ExcludeSchemes,
|
||||||
appSettings.WorkingDirectoryName
|
appSettings.WorkingDirectoryName
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user