@@ -47,8 +47,10 @@ def extract_kinds(s:Snippet) -> str:
4747
4848
4949def extract_excerpt (s :Snippet ) -> str :
50- if isinstance (s , WithTitle ) and s .title is not None :
50+ if isinstance (s , Document ) and s .title is not None :
5151 return '<' + s .title .text + '>'
52+ elif isinstance (s , Section ) and s .title is not None :
53+ return '[' + s .title .text + ']'
5254 return ''
5355
5456
@@ -83,7 +85,7 @@ def on_config_inited(app:Sphinx, appcfg:SphinxConfig) -> None:
8385 try :
8486 cache .load ()
8587 except Exception as e :
86- logger .warning ("failed to laod cache: %s" % e )
88+ logger .warning ("[snippet] failed to laod cache: %s" % e )
8789
8890
8991def on_env_get_outdated (app :Sphinx , env :BuildEnvironment , added :Set [str ],
@@ -97,12 +99,13 @@ def on_env_get_outdated(app:Sphinx, env:BuildEnvironment, added:Set[str],
9799def on_doctree_resolved (app :Sphinx , doctree :nodes .document , docname :str ) -> None :
98100 if not isinstance (doctree , nodes .document ):
99101 # XXX: It may caused by ablog
100- logger .debug ('node %s is not nodes.document' , type (doctree ), location = doctree )
102+ logger .debug ('[snippet] node %s is not nodes.document' , type (doctree ), location = doctree )
101103 return
102104
103105 pats = app .config .snippet_patterns
104106 doc = cache .setdefault ((app .config .project , docname ), [])
105- for s , n in pick (doctree ):
107+ snippets = pick (doctree )
108+ for s , n in snippets :
106109 if not is_matched (pats , s , docname ):
107110 continue
108111 doc .append (Item (snippet = s ,
@@ -116,6 +119,9 @@ def on_doctree_resolved(app:Sphinx, doctree:nodes.document, docname:str) -> None
116119 if len (doc ) == 0 :
117120 del cache [(app .config .project , docname )]
118121
122+ logger .debug ('[snippet] picked %s/%s snippetes in %s' ,
123+ len (doc ), len (snippets ), docname )
124+
119125
120126def on_builder_finished (app :Sphinx , exception ) -> None :
121127 cache .dump ()
0 commit comments