Skip to content

Commit 14c14a1

Browse files
committed
make links on object holding anchors
1 parent 745780a commit 14c14a1

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/Elastic.Markdown/IO/State/LinkReference.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
namespace Elastic.Markdown.IO.State;
99

10+
public record LinkMetadata
11+
{
12+
[JsonPropertyName("anchors")]
13+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
14+
public required string[]? Anchors { get; init; } = [];
15+
}
16+
1017
public record LinkReference
1118
{
1219
[JsonPropertyName("origin")]
@@ -17,7 +24,7 @@ public record LinkReference
1724

1825
/// Mapping of relative filepath and all the page's anchors for deeplinks
1926
[JsonPropertyName("links")]
20-
public required Dictionary<string, string[]> Links { get; init; } = [];
27+
public required Dictionary<string, LinkMetadata> Links { get; init; } = [];
2128

2229
[JsonPropertyName("cross_links")]
2330
public required string[] CrossLinks { get; init; } = [];
@@ -27,7 +34,11 @@ public static LinkReference Create(DocumentationSet set)
2734
var crossLinks = set.Context.Collector.CrossLinks.ToHashSet().ToArray();
2835
var links = set.MarkdownFiles.Values
2936
.Select(m => (m.RelativePath, m.Anchors))
30-
.ToDictionary(k => k.RelativePath, v => v.Anchors.ToArray());
37+
.ToDictionary(k => k.RelativePath, v =>
38+
{
39+
var anchors = v.Anchors.Count == 0 ? null : v.Anchors.ToArray();
40+
return new LinkMetadata { Anchors = anchors };
41+
});
3142
return new LinkReference
3243
{
3344
UrlPathPrefix = set.Context.UrlPathPrefix,

tests/authoring/Generator/LinkReferenceFile.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ Through various means $$$including-this-inline-syntax$$$
5959
},
6060
"url_path_prefix": "",
6161
"links": {
62-
"file.md": [],
63-
"index.md": [
64-
"including-this-inline-syntax",
65-
"this-anchor-is-autogenerated",
66-
"and-anchored"
67-
]
62+
"file.md": {},
63+
"index.md": {
64+
"anchors":[
65+
"including-this-inline-syntax",
66+
"this-anchor-is-autogenerated",
67+
"and-anchored"
68+
]
69+
}
6870
},
6971
"cross_links": []
7072
}

0 commit comments

Comments
 (0)