Skip to content

Commit c9be3f5

Browse files
authored
Remove page category from search index (#2762)
1 parent c340a06 commit c9be3f5

File tree

2 files changed

+76
-21
lines changed

2 files changed

+76
-21
lines changed

CHANGELOG.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## Unreleased
7+
8+
### Changed
9+
10+
* Page category is removed from the search index and now everything is in section category. ([#2762], [#2413])
11+
612
## Version [v1.15.0] - 2025-10-22
713

814
### Changed
915

10-
* The HTML output shows a warning now when the search index size is too big (500Kib). ([#2423], [#2753])
11-
* In the HTML output, the search modal can now be navigated using using up and down keys. ([#2761])
16+
* Created a warning for when the search index size is too big (500Kib). ([#2423], [#2753])
17+
* In the HTML output, the search modal can now be navigated using up and down keys. ([#2761])
1218

1319
### Other
1420

@@ -2061,6 +2067,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20612067
[#2406]: https://github.com/JuliaDocs/Documenter.jl/issues/2406
20622068
[#2408]: https://github.com/JuliaDocs/Documenter.jl/issues/2408
20632069
[#2410]: https://github.com/JuliaDocs/Documenter.jl/issues/2410
2070+
[#2413]: https://github.com/JuliaDocs/Documenter.jl/issues/2413
20642071
[#2414]: https://github.com/JuliaDocs/Documenter.jl/issues/2414
20652072
[#2415]: https://github.com/JuliaDocs/Documenter.jl/issues/2415
20662073
[#2423]: https://github.com/JuliaDocs/Documenter.jl/issues/2423
@@ -2146,6 +2153,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21462153
[#2750]: https://github.com/JuliaDocs/Documenter.jl/issues/2750
21472154
[#2753]: https://github.com/JuliaDocs/Documenter.jl/issues/2753
21482155
[#2761]: https://github.com/JuliaDocs/Documenter.jl/issues/2761
2156+
[#2762]: https://github.com/JuliaDocs/Documenter.jl/issues/2762
21492157
[#2774]: https://github.com/JuliaDocs/Documenter.jl/issues/2774
21502158
[JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953
21512159
[JuliaLang/julia#38054]: https://github.com/JuliaLang/julia/issues/38054

src/html/HTMLWriter.jl

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -725,15 +725,6 @@ function SearchRecord(ctx::HTMLContext, navnode; fragment = "", title = nothing,
725725
)
726726
end
727727

728-
function SearchRecord(ctx::HTMLContext, navnode, node::Node, element::Documenter.AnchoredHeader)
729-
a = element.anchor
730-
return SearchRecord(
731-
ctx, navnode;
732-
fragment = Documenter.anchor_fragment(a),
733-
title = mdflatten(node), # AnchoredHeader has Heading as single child
734-
category = "section"
735-
)
736-
end
737728

738729
function SearchRecord(ctx, navnode, node::Node, ::MarkdownAST.AbstractElement)
739730
return SearchRecord(ctx, navnode; text = mdflatten(node))
@@ -745,12 +736,62 @@ const _SEARCHRECORD_IGNORED_BLOCK_TYPES = Union{
745736
Documenter.DocsNodesBlock,
746737
Documenter.SetupNode,
747738
}
748-
function searchrecord(ctx::HTMLContext, navnode::Documenter.NavNode, node::Node)
749-
# Skip indexing special at-blocks
750-
if node.element isa _SEARCHRECORD_IGNORED_BLOCK_TYPES
751-
return nothing
739+
740+
# Content segment for grouping content by sections
741+
struct ContentSegment
742+
section_header::Union{Node, Nothing}
743+
content_nodes::Vector{Node} # Content nodes belonging to this section
744+
end
745+
746+
# Segment page content by sections for improved search indexing
747+
function segment_page_by_sections(page_mdast::Node)
748+
segments = ContentSegment[]
749+
current = ContentSegment(nothing, Node[])
750+
751+
for node in page_mdast.children
752+
if node.element isa Documenter.AnchoredHeader
753+
# Save previous segment if it has content or a header
754+
if !isempty(current.content_nodes) || current.section_header !== nothing
755+
push!(segments, current)
756+
end
757+
# Start new section
758+
current = ContentSegment(node, Node[])
759+
else
760+
# Skip nodes that shouldn't be indexed
761+
if !(node.element isa _SEARCHRECORD_IGNORED_BLOCK_TYPES)
762+
push!(current.content_nodes, node)
763+
end
764+
end
765+
end
766+
767+
# Add final segment
768+
if !isempty(current.content_nodes) || current.section_header !== nothing
769+
push!(segments, current)
770+
end
771+
772+
return segments
773+
end
774+
775+
# Create search record for a content segment
776+
function searchrecord(ctx::HTMLContext, navnode::Documenter.NavNode, segment::ContentSegment)
777+
text = join([mdflatten(node) for node in segment.content_nodes], "\n\n")
778+
779+
if segment.section_header === nothing
780+
title = nothing
781+
fragment = ""
782+
else
783+
a = segment.section_header.element.anchor
784+
title = mdflatten(segment.section_header)
785+
fragment = Documenter.anchor_fragment(a)
752786
end
753-
return SearchRecord(ctx, navnode, node, node.element)
787+
788+
return SearchRecord(
789+
ctx, navnode;
790+
fragment,
791+
title,
792+
category = "section",
793+
text
794+
)
754795
end
755796

756797
function JSON.lower(rec::SearchRecord)
@@ -1749,11 +1790,17 @@ end
17491790

17501791
function domify(dctx::DCtx)
17511792
ctx, navnode = dctx.ctx, dctx.navnode
1752-
return map(getpage(ctx, navnode).mdast.children) do node
1753-
rec = searchrecord(ctx, navnode, node)
1754-
if !isnothing(rec)
1755-
push!(ctx.search_index, rec)
1756-
end
1793+
page_mdast = getpage(ctx, navnode).mdast
1794+
1795+
# Generate search index using custom segmentation, with pages merged together
1796+
segments = segment_page_by_sections(page_mdast)
1797+
for segment in segments
1798+
search_record = searchrecord(ctx, navnode, segment)
1799+
push!(ctx.search_index, search_record)
1800+
end
1801+
1802+
# Generate HTML as before - process each child node individually
1803+
return map(page_mdast.children) do node
17571804
domify(dctx, node, node.element)
17581805
end
17591806
end

0 commit comments

Comments
 (0)