Skip to content

Commit

Permalink
Update to latest Statiq packages + search index fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alanta committed Aug 7, 2021
1 parent 840a795 commit b0b9584
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Gemfile.lock
.sass-cache
*~
.jekyll-cache
cache
11 changes: 5 additions & 6 deletions MemoirsTheme.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Kontent.Statiq" Version="1.0.0-beta0008" />
<PackageReference Include="LunrCore" Version="2.3.8.5" />
<PackageReference Include="Kontent.Statiq" Version="1.0.0-*" />
<PackageReference Include="LunrCore" Version="2.3.9" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.9" />
<PackageReference Include="NUglify" Version="1.11.0" />
<PackageReference Include="Statiq.App" Version="1.0.0-beta.29" />
<PackageReference Include="Statiq.Lunr" Version="1.0.0-beta.29" />
<PackageReference Include="Statiq.Sass" Version="1.0.0-beta.29" />
<PackageReference Include="Statiq.Web" Version="1.0.0-beta.14" />
<PackageReference Include="Statiq.App" Version="1.0.0-*" />
<PackageReference Include="Statiq.Sass" Version="1.0.0-*" />
<PackageReference Include="Statiq.Web" Version="1.0.0-*" />
</ItemGroup>

</Project>
4 changes: 1 addition & 3 deletions Modules/HtmlOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ protected override async Task<IEnumerable<IDocument>> ExecuteInputAsync(IDocumen
}

context.LogInformation(input, $"Content minified by {minifiedContent.Code.Length*100M/original.Length:N2}%");
return (await input.CloneAsync(content: minifiedContent.Code)).Yield();


return (input.Clone(content: minifiedContent.Code)).Yield();
}
}
}
59 changes: 59 additions & 0 deletions Modules/LunrIndexDocItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Statiq.Common;

namespace MemoirsTheme.Modules
{
/// <summary>
/// A search item for a document.
/// </summary>
public class LunrIndexDocItem
{
/// <summary>
/// The document the search item points to.
/// </summary>
public IDocument Document { get; set; }

/// <summary>
/// The title of the search item.
/// </summary>
public string Title { get; set; }

/// <summary>
/// The description of the search item.
/// </summary>
public string Description { get; set; }

/// <summary>
/// The content of the search item.
/// </summary>
public string Content { get; set; }

/// <summary>
/// Any tags for the search item.
/// </summary>
public string Tags { get; set; }

/// <summary>
/// Creates the search item.
/// </summary>
/// <param name="document">The document this search item should point to.</param>
/// <param name="title">The title of the search item.</param>
/// <param name="content">The search item content.</param>
public LunrIndexDocItem(IDocument document, string title, string content)
{
Document = document;
Title = title;
Content = content;
Tags = "";
Description = "";
}

/// <summary>
/// Gets a link to the search item result.
/// </summary>
/// <param name="context">The current execution context.</param>
/// <param name="includeHost"><c>true</c> to include the hostname, <c>false otherwise</c>.</param>
/// <returns>A link to the search item.</returns>
public string GetLink(IExecutionContext context, bool includeHost) =>
context.GetLink(Document, includeHost);
}
}
7 changes: 3 additions & 4 deletions Modules/LunrIndexer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using MemoirsTheme.Pipelines;
using Statiq.Common;
using Statiq.SearchIndex;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -34,7 +33,7 @@ protected override async Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecu

foreach (IDocument doc in context.Inputs)
{
var searchItem = doc[SearchIndex.SearchItemKey] as ILunrIndexItem;
var searchItem = doc[SearchIndex.SearchItemKey] as LunrIndexDocItem;
if (searchItem == null)
continue;

Expand Down Expand Up @@ -62,8 +61,8 @@ protected override async Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecu
}
});

return new[] { (await context.CreateDocumentAsync(destination: "index.js",
$@"var documents={System.Text.Json.JsonSerializer.Serialize(documents)};{Environment.NewLine}var data='{idx.ToJson()}';{Environment.NewLine}")) };
return new[] { context.CreateDocument(destination: "index.js",
$@"var documents={System.Text.Json.JsonSerializer.Serialize(documents)};{Environment.NewLine}var data='{idx.ToJson()}';{Environment.NewLine}") };

}
}
Expand Down
1 change: 0 additions & 1 deletion Pipelines/Pages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Statiq.Common;
using Statiq.Core;
using Statiq.Razor;
using Statiq.SearchIndex;
using System.Linq;

namespace MemoirsTheme.Pipelines
Expand Down
1 change: 0 additions & 1 deletion Pipelines/Posts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Statiq.Common;
using Statiq.Core;
using Statiq.Razor;
using Statiq.SearchIndex;
using System.Linq;

namespace MemoirsTheme.Pipelines
Expand Down
3 changes: 1 addition & 2 deletions Pipelines/SearchIndex.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using MemoirsTheme.Modules;
using Statiq.Common;
using Statiq.Core;
using Statiq.SearchIndex;
using System.Linq;
using Pipeline = Statiq.Core.Pipeline;

namespace MemoirsTheme.Pipelines
{
public class SearchIndex : Pipeline
{
public const string SearchItemKey = GenerateLunrIndexKeys.LunrIndexItem;
public const string SearchItemKey = "SearchItem";
public SearchIndex()
{
Dependencies.AddRange(nameof(Posts));
Expand Down

0 comments on commit b0b9584

Please sign in to comment.