Skip to content

Commit

Permalink
Scss/Sass files are now invalidated whenever any other Scss/Sass file…
Browse files Browse the repository at this point in the history
…s change (#1019)
  • Loading branch information
daveaglick committed Jan 9, 2024
1 parent 0d10c5e commit 9f6882d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.0.0-beta.60

- Added extra cache invalidation logic to ensure Sass/Scss files are invalidated whenever any other Sass/Scss files are changed since those are likely imports (#1019).
- Added a new `WebKeys.ChangedFiles` setting to propagate the list of changed files when using the `preview` or `serve` command.
- Updated Statiq Framework reference to version [1.0.0-beta.72](https://github.com/statiqdev/Statiq.Framework/releases/tag/v1.0.0-beta.72).

# 1.0.0-beta.59

- Updated Statiq Framework reference to version [1.0.0-beta.71](https://github.com/statiqdev/Statiq.Framework/releases/tag/v1.0.0-beta.71).
Expand Down
4 changes: 4 additions & 0 deletions src/Statiq.Web/Commands/PreviewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ protected override async Task<ExitCode> ExecutionTriggeredAsync(
logger.LogInformation($"{changedFile} has changed");
}
}

// Use a setting to propagate the list of changed files
engineManager.Engine.Settings[WebKeys.ChangedFiles] = changedFiles;

if (forceExecution || changedFiles.Count > 0)
{
if (changedFiles.Count > 0)
Expand Down
4 changes: 4 additions & 0 deletions src/Statiq.Web/Commands/ServeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ protected override async Task<int> ExecuteEngineAsync(
}
}

// Use a setting to propagate the list of changed files
engineManager.Engine.Settings[WebKeys.ChangedFiles] = changedFiles;

// If files have changed, reload
if (changedFiles.Count > 0)
{
logger.LogInformation($"{changedFiles.Count} files have changed, re-loading");
Expand Down
9 changes: 8 additions & 1 deletion src/Statiq.Web/Templates/Templates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using Statiq.Common;
using Statiq.Core;
Expand All @@ -22,7 +23,13 @@ public Templates()
{
// Assets
Add(MediaTypes.Less, new Template(ContentType.Asset, Phase.Process, new CacheDocuments { new CompileLess() }));
Add(MediaTypes.Sass, new Template(ContentType.Asset, Phase.Process, new CacheDocuments { new CompileSass().WithCompactOutputStyle() }));
Add(MediaTypes.Sass, new Template(
ContentType.Asset,
Phase.Process,
new CacheDocuments { new CompileSass().WithCompactOutputStyle() }
.InvalidateDocumentsWhere(
Config.FromContext(
ctx => ctx.GetList<string>(WebKeys.ChangedFiles)?.Any(x => MediaTypes.IsMediaType(x, MediaTypes.Sass, MediaTypes.Scss)) == true))));
Add(MediaTypes.Scss, this[MediaTypes.Sass]);

// Data
Expand Down
5 changes: 5 additions & 0 deletions src/Statiq.Web/WebKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ public static class WebKeys
/// </summary>
public const string IgnoreInvalidXrefs = nameof(IgnoreInvalidXrefs);

/// <summary>
/// Set by the preview and serve commands to indicate which files have changed and triggered execution.
/// </summary>
public const string ChangedFiles = nameof(ChangedFiles);

////////// Document

/// <summary>
Expand Down

0 comments on commit 9f6882d

Please sign in to comment.