def stamp_excerpt(kb_app: kb,
                  sphinx_app: Sphinx,
                  doctree: doctree):
    """ Walk the tree and extract excert into resource.excerpt """

    # First, find out which resource this is. Won't be easy.
    resources = sphinx_app.env.resources
    confdir = sphinx_app.confdir
    source = PurePath(doctree.attributes['source'])

    # Get the relative path inside the docs dir, without .rst, then
    # get the resource
    docname = str(source.relative_to(confdir)).split('.rst')[0]
    resource = resources.get(docname)

    if resource:
        # Stamp the excerpt on the resource
        excerpt = getattr(resource.props, 'excerpt', False)
        auto_excerpt = getattr(resource.props, 'auto_excerpt', False)
        if excerpt:
            resource.excerpt = excerpt
        elif not auto_excerpt:
            resource.excerpt = None
        else:
            # Extract the excerpt based on the number of paragraphs
            # in auto_excerpt
            resource.excerpt = get_rst_excerpt(doctree, auto_excerpt)
def stamp_excerpt ( kb_app : kb , sphinx_app : Sphinx , doctree : doctree ) : resources = sphinx_app . env . resources confdir = sphinx_app . confdir source = PurePath ( doctree . attributes [ 'source' ] ) docname = str ( source . relative_to ( confdir ) ) . split ( '.rst' ) [ 0 ] resource = resources . get ( docname ) if resource : excerpt = getattr ( resource . props , 'excerpt' , False ) auto_excerpt = getattr ( resource . props , 'auto_excerpt' , False ) if excerpt : resource . excerpt = excerpt elif not auto_excerpt : resource . excerpt = None else : resource . excerpt = get_rst_excerpt ( doctree , auto_excerpt )
Walk the tree and extract excert into resource.excerpt