code: def build_legacy_redirect(tvm_path):
      def legacy_redirect(app, docname):  # Sphinx expects two arguments
          if app.builder.name == "html":
              src = Template(redirect_template)
  
              for frm, to in legacy_redirects:
                  frm = (
                      tvm_path.resolve()
                      / "docs"
                      / "_build"
                      / "html"
                      / frm
                  )
                  redirect = src.substitute({"to": to})
                  os.makedirs(os.path.dirname(frm), exist_ok=True)
                  with open(frm, "w") as f:
                      f.write(redirect)
  
      return legacy_redirect
  
imports: from string import Template
  import json
  import os
label_desc: Use image node_id 1 for calling a global function with example usage: build_legacy_redirect(tvm_path) and returns: legacy_redirect