@@ -35,15 +35,16 @@ def pick(
3535 """
3636 # FIXME: Why doctree.source is always None?
3737 if not doctree .attributes .get ('source' ):
38- logger .debug ('Skip document without source' )
38+ logger .debug ('Skip document %s: no source' , docname )
3939 return []
4040
4141 metadata = app .env .metadata .get (docname , {})
4242 if 'no-search' in metadata or 'nosearch' in metadata :
43- logger .debug ('Skip document with nosearch metadata' )
43+ logger .debug ('Skip document %s: have :no[-]search: metadata' , docname )
4444 return []
4545
4646 # Walk doctree and pick snippets.
47+
4748 picker = SnippetPicker (doctree )
4849 doctree .walkabout (picker )
4950
@@ -83,13 +84,14 @@ def depart_section(self, node: nodes.section) -> None:
8384 section = self ._sections .pop ()
8485 assert section == node
8586
87+ # Always pick document.
88+ if len (self ._sections ) == 0 :
89+ self .snippets .append ((Document (self .document ), node ))
90+ return
8691 # Skip non-leaf section without content
8792 if self ._is_empty_non_leaf_section (node ):
8893 return
89- if len (self ._sections ) == 0 :
90- self .snippets .append ((Document (self .document ), node ))
91- else :
92- self .snippets .append ((Section (node ), node ))
94+ self .snippets .append ((Section (node ), node ))
9395
9496 def unknown_visit (self , node : nodes .Node ) -> None :
9597 pass # Ignore any unknown node
0 commit comments