Skip to content

Commit

Permalink
Fixup for Statiq beta 32 (#30)
Browse files Browse the repository at this point in the history
Fixes #29
  • Loading branch information
alanta authored Jan 22, 2021
1 parent 7a2f45e commit a09be6a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 31 deletions.
10 changes: 5 additions & 5 deletions Kontent.Statiq.Tests/Kontent.Statiq.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
<ItemGroup>
<PackageReference Include="FakeItEasy" Version="6.2.1" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
<PackageReference Include="RichardSzalay.MockHttp" Version="6.0.0" />
<PackageReference Include="Statiq.Core" Version="1.0.0-beta.31" />
<PackageReference Include="Statiq.Razor" Version="1.0.0-beta.31" />
<PackageReference Include="Statiq.Testing" Version="1.0.0-beta.31" />
<PackageReference Include="Statiq.Core" Version="1.0.0-beta.32" />
<PackageReference Include="Statiq.Razor" Version="1.0.0-beta.32" />
<PackageReference Include="Statiq.Testing" Version="1.0.0-beta.32" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<PackageReference Include="coverlet.collector" Version="3.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
10 changes: 5 additions & 5 deletions Kontent.Statiq/Kontent.Statiq.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Kentico.Kontent.Delivery" Version="14.1.0" />
<PackageReference Include="Kentico.Kontent.ImageTransformation" Version="14.1.0" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.13.1.21947">
<PackageReference Include="Kentico.Kontent.Delivery" Version="14.2.1" />
<PackageReference Include="Kentico.Kontent.ImageTransformation" Version="14.2.1" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.17.0.26580">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Statiq.Common" Version="1.0.0-beta.31" />
<PackageReference Include="Statiq.Core" Version="1.0.0-beta.31" />
<PackageReference Include="Statiq.Common" Version="1.0.0-beta.32" />
<PackageReference Include="Statiq.Core" Version="1.0.0-beta.32" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 3 additions & 7 deletions Kontent.Statiq/Kontent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ protected override async Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecu
{
var nextBatch = await feed.FetchNextBatchAsync();

var documentTasks = nextBatch.Items.Select(item => KontentDocumentHelpers.CreateDocument(context, item, GetContent)).ToArray();
var outputDocuments = nextBatch.Items.Select(item => KontentDocumentHelpers.CreateDocument(context, item, GetContent)).ToArray();

var documentBatch = await Task.WhenAll(documentTasks);

documents.AddRange(documentBatch);
documents.AddRange(outputDocuments);
}

return documents;
Expand All @@ -70,9 +68,7 @@ protected override async Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecu
{
var items = await _client.GetItemsAsync<TContentModel>(QueryParameters);

var documentTasks = items.Items.Select(item => KontentDocumentHelpers.CreateDocument(context, item, GetContent)).ToArray();

return await Task.WhenAll(documentTasks);
return items.Items.Select(item => KontentDocumentHelpers.CreateDocument(context, item, GetContent)).ToArray();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Kontent.Statiq/KontentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Config<IEnumerable<IDocument>> GetChildren<TContentType>(Func<TCon
{
if (getChildren == null) throw new ArgumentNullException(nameof(getChildren));

return Config.FromDocument<IEnumerable<IDocument>>( async (doc, ctx) =>
return Config.FromDocument<IEnumerable<IDocument>>( (doc, ctx) =>
{
var list = new List<IDocument>();
var parent = doc.AsKontent<TContentType>();
Expand All @@ -30,7 +30,7 @@ public static Config<IEnumerable<IDocument>> GetChildren<TContentType>(Func<TCon
var children = getChildren(parent)?.ToArray() ?? Array.Empty<object>();
foreach (var item in children)
{
list.Add(await KontentDocumentHelpers.CreateDocument(ctx, item, null));
list.Add(KontentDocumentHelpers.CreateDocument(ctx, item, null));
}
}
Expand Down
14 changes: 7 additions & 7 deletions Kontent.Statiq/KontentDocumentHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ namespace Kontent.Statiq
/// </summary>
internal static class KontentDocumentHelpers
{
internal static async Task<IDocument> CreateDocument<TContentModel>(IExecutionContext context, TContentModel item, Func<TContentModel, string>? getContent) where TContentModel : class
internal static IDocument CreateDocument<TContentModel>(IExecutionContext context, TContentModel item, Func<TContentModel, string>? getContent) where TContentModel : class
{
var props = typeof(TContentModel).GetProperties(BindingFlags.Instance | BindingFlags.FlattenHierarchy |
BindingFlags.GetProperty | BindingFlags.Public);

var content = getContent?.Invoke(item) ?? "";

return await CreateDocumentInternal(context, item, props, content).ConfigureAwait(false);
return CreateDocumentInternal(context, item, props, content);

}

internal static async Task<IDocument> CreateDocument(IExecutionContext context, object item, Func<object, string>? getContent)
internal static IDocument CreateDocument(IExecutionContext context, object item, Func<object, string>? getContent)
{
var props = item.GetType().GetProperties(BindingFlags.Instance | BindingFlags.FlattenHierarchy |
BindingFlags.GetProperty | BindingFlags.Public);

var content = getContent?.Invoke(item) ?? "";
return await CreateDocumentInternal(context, item, props, content).ConfigureAwait(false);

return CreateDocumentInternal(context, item, props, content);
}

private static Task<IDocument> CreateDocumentInternal(IExecutionContext context, object item, PropertyInfo[] props, string content )
private static IDocument CreateDocumentInternal(IExecutionContext context, object item, PropertyInfo[] props, string content )
{
var metadata = new List<KeyValuePair<string, object>>
{
Expand All @@ -43,7 +43,7 @@ private static Task<IDocument> CreateDocumentInternal(IExecutionContext context,

MapSystemMetadata(item, props, metadata);

return context.CreateDocumentAsync(metadata, content, "text/html");
return context.CreateDocument(metadata, content, "text/html");
}

/// <summary>
Expand Down
4 changes: 1 addition & 3 deletions Kontent.Statiq/KontentImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocumen
downloadUrls.AddRange(downloads);
}
}


var localPath = KontentAssetHelper.GetLocalFileName(imageSource, localBasePath);

Expand Down Expand Up @@ -125,7 +124,7 @@ protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocumen

return input.Clone(
new[] { new KeyValuePair<string, object>(KontentKeys.Images.Downloads, downloadUrls.ToArray()) },
await context.GetContentProviderAsync(
context.GetContentProvider(
html.ToHtml(), // Note that AngleSharp always injects <html> and <body> tags so can't use this module with HTML fragments
MediaTypes.Html)).Yield();
}
Expand All @@ -137,7 +136,6 @@ private static bool IsImageMetaTag(IElement element)
&& ( element.GetAttribute(AttributeNames.Content)?.StartsWith("http", StringComparison.OrdinalIgnoreCase) ?? false);
}


private bool SkipImage(string uri)
{
return (!IsRemoteUrl(uri) || !(_urlFilter?.Invoke(uri) ?? true));
Expand Down
4 changes: 2 additions & 2 deletions Kontent.Statiq/KontentTaxonomyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static async Task<IEnumerable<IDocument>> CreateDocument(IExecutionCont
}

var metadata = BuildRootNode(item, treePath, terms);
var root = await context.CreateDocumentAsync(metadata, "", "text/html");
var root = context.CreateDocument(metadata, "", "text/html");
return root.Yield();
}

Expand Down Expand Up @@ -81,7 +81,7 @@ private static async Task<IDocument> CreateDocument(IExecutionContext context, I
metadata.Add(new KeyValuePair<string, object>(KontentKeys.Taxonomy.Terms, item.Terms.ToArray()));
}

return await context.CreateDocumentAsync(metadata, "", "text/html");
return context.CreateDocument(metadata, "", "text/html");
}
}
}

0 comments on commit a09be6a

Please sign in to comment.