Skip to content

Commit 3713694

Browse files
Albert KapitanovAlbert Kapitanov
Albert Kapitanov
authored and
Albert Kapitanov
committed
Fixed page preview caching
1 parent 610fdd4 commit 3713694

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

src/ITGlobal.MarkDocs.Core/Impl/PagePreview.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ITGlobal.MarkDocs.Cache;
1+
using ITGlobal.MarkDocs.Cache;
22
using ITGlobal.MarkDocs.Cache.Model;
33
using System.IO;
44

@@ -20,7 +20,7 @@ public PagePreview(ICacheReader cache, IDocumentation documentation, PagePreview
2020
public string Id => _model.Id;
2121
public IDocumentation Documentation { get; }
2222
public string RelativePath => _model.RelativePath;
23-
public ResourceType Type => ResourceType.Page;
23+
public ResourceType Type => ResourceType.PagePreview;
2424
public IPage Page { get; }
2525

2626
public Stream OpenRead() => _cache.Read(this);

src/ITGlobal.MarkDocs.Markdown/Format/Impl/Extensions/LaTeX/CodecogsGeneratedAsset.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Net.Http;
44
using ITGlobal.MarkDocs.Source;
@@ -37,7 +37,7 @@ public void Write(Stream stream)
3737
}
3838
catch (HttpRequestException e)
3939
{
40-
MarkdownPageRenderContext.Current?.Error($"Failed to render math markup. {e.Message}", _lineNumber);
40+
MarkdownPageRenderContext.CurrentNullable?.Error($"Failed to render math markup. {e.Message}", _lineNumber);
4141
}
4242
}
4343
}

src/ITGlobal.MarkDocs.Markdown/Format/Impl/Extensions/PlantUml/PlantUmlGeneratedContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Write(Stream stream)
3333
}
3434
catch (HttpRequestException e)
3535
{
36-
MarkdownPageRenderContext.Current?.Error($"Failed to render PlantUML markup. {e.Message}", _lineNumber);
36+
MarkdownPageRenderContext.CurrentNullable?.Error($"Failed to render PlantUML markup. {e.Message}", _lineNumber);
3737
}
3838
}
3939
}

src/ITGlobal.MarkDocs.Markdown/Format/Impl/MarkdownPageRenderContext.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
using System;
1+
using System;
22
using System.Threading;
33

44
namespace ITGlobal.MarkDocs.Format.Impl
55
{
66
internal static class MarkdownPageRenderContext
77
{
8+
89
public static bool IsPresent => CurrentState.Value != null;
910

10-
public static IPageRenderContext Current => Get(_ => _);
11+
public static IPageRenderContext Current => Get(_ => _, canBeNull: false);
12+
public static IPageRenderContext CurrentNullable => Get(_ => _, canBeNull: true);
1113

1214
public struct ScopeToken : IDisposable
1315
{
16+
1417
public void Dispose() => ClearContext();
18+
1519
}
1620

1721
public static ScopeToken Use(IPageRenderContext context)
@@ -24,15 +28,22 @@ public static ScopeToken Use(IPageRenderContext context)
2428

2529
private static readonly ThreadLocal<IPageRenderContext> CurrentState = new ThreadLocal<IPageRenderContext>();
2630

27-
private static T Get<T>(Func<IPageRenderContext, T> f)
31+
private static T Get<T>(Func<IPageRenderContext, T> f, bool canBeNull)
32+
where T : class
2833
{
2934
var state = CurrentState.Value;
3035
if (state == null)
3136
{
37+
if (canBeNull)
38+
{
39+
return null;
40+
}
41+
3242
throw new InvalidOperationException("No active MarkdownRenderingContext");
3343
}
3444

3545
return f(state);
3646
}
47+
3748
}
3849
}

0 commit comments

Comments
 (0)