| Name | Message | Date |
|---|---|---|
| 📄 AppSettings.cs | 4 days ago | |
| 📄 NoteCacheJsonContext.cs | 4 days ago | |
| 📄 NoteCacheStore.cs | 4 days ago | |
| 📄 NoteContentCache.cs | 3 days ago | |
| 📄 NotePreviewBuilder.cs | 3 days ago |
📄
src/Storage/NotePreviewBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
namespace NotesApp.Storage; // Shared by NoteViewActivity (recomputing its own preview after loading/saving) and // NoteListActivity (recomputing a row's preview whenever NoteContentCache finishes fetching // that note's full body) - both need the exact same rules, or the list and the editor would // disagree on what a note's preview looks like. public static class NotePreviewBuilder { private const int MaxLength = 300; public static string Build(string content) { var withoutFrontmatter = StripFrontmatter(content); var trimmed = withoutFrontmatter.Length > MaxLength ? withoutFrontmatter[..MaxLength] : withoutFrontmatter; var lastNewline = trimmed.LastIndexOf('\n'); return lastNewline > 0 ? trimmed[..lastNewline] : trimmed; } private static string StripFrontmatter(string content) { var lines = content.Split( ["\n", "\r\n"], StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries ); if (lines is []) return content; var firstLine = lines[0]; if (firstLine.Any(c => c != '-')) return content; for (var i = 1; i < lines.Length; i++) { var line = lines[i]; if (line.Length == firstLine.Length && line.All(c => c == '-')) return string.Join('\n', lines[(i + 1)..]); } return content; } }