@@ -88,8 +88,11 @@ def convert_node(self, node):
8888 """
8989 Transforms a `CodeSampleNode` into a `nodes.section` named after the code sample name.
9090
91- Moves all sibling nodes that are after the `CodeSampleNode` in the documement under this new
91+ Moves all sibling nodes that are after the `CodeSampleNode` in the document under this new
9292 section.
93+
94+ Adds a "See Also" section at the end with links to all relevant APIs as per the samples's
95+ `relevant-api` attribute.
9396 """
9497 parent = node .parent
9598 siblings_to_move = []
@@ -111,6 +114,31 @@ def convert_node(self, node):
111114 for sibling in siblings_to_move :
112115 parent .remove (sibling )
113116
117+ # Add a "See Also" section at the end with links to relevant APIs
118+ if node ["relevant-api" ]:
119+ see_also_section = nodes .section (ids = ["see-also" ])
120+ see_also_section += nodes .title (text = "See also" )
121+
122+ for api in node ["relevant-api" ]:
123+ desc_node = addnodes .desc ()
124+ desc_node ["domain" ] = "c"
125+ desc_node ["objtype" ] = "group"
126+
127+ title_signode = addnodes .desc_signature ()
128+ api_xref = addnodes .pending_xref (
129+ "" ,
130+ refdomain = "c" ,
131+ reftype = "group" ,
132+ reftarget = api ,
133+ refwarn = True ,
134+ )
135+ api_xref += nodes .Text (api )
136+ title_signode += api_xref
137+ desc_node += title_signode
138+ see_also_section += desc_node
139+
140+ new_section += see_also_section
141+
114142 # Set sample description as the meta description of the document for improved SEO
115143 meta_description = nodes .meta ()
116144 meta_description ["name" ] = "description"
@@ -231,6 +259,7 @@ def run(self):
231259 code_sample_node = CodeSampleNode ()
232260 code_sample_node ["id" ] = code_sample_id
233261 code_sample_node ["name" ] = name
262+ code_sample_node ["relevant-api" ] = relevant_api_list
234263 code_sample_node += description_node
235264
236265 return [code_sample_node ]
0 commit comments