From d967a94eadf633c6cafd1e6fb92ef62513f99e61 Mon Sep 17 00:00:00 2001 From: Neo Zhang Jianyu Date: Mon, 11 Nov 2024 09:58:34 +0800 Subject: [PATCH] support copy all image to html folder (#247) Signed-off-by: ZhangJianyu --- conf.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/conf.py b/conf.py index 40e46375..35051272 100644 --- a/conf.py +++ b/conf.py @@ -4,6 +4,9 @@ import os import sys from datetime import datetime +import glob +import shutil + sys.path.insert(0, os.path.abspath('.')) @@ -131,10 +134,31 @@ # paths that contain custom static files (such as style sheets) html_static_path = ['sphinx/_static'] +def copy_images(src ,dst): + image_types = ["png", "svg"] + for image_type in image_types: + pattern = "{}/**/*.{}".format(src, image_type) + files = glob.glob(pattern, recursive = True) + for file in files: + sub_name = file.replace(src, '') + dst_filename = "{}{}".format(dst, sub_name) + folder = os.path.dirname(dst_filename) + if not os.path.exists(folder): + os.makedirs(folder) + shutil.copy(file, dst_filename) + +def copy_image_to_html(app, docname): + if app.builder.name == 'html': + if os.path.exists(app.srcdir) and os.path.exists(app.outdir): + copy_images(str(app.srcdir) ,str(app.outdir)) + else: + print("No existed {} or {}".format(app.srcdir ,app.outdir)) + def setup(app): app.add_css_file("opea-custom.css") app.add_js_file("opea-custom.js") + app.connect('build-finished', copy_image_to_html) # Disable "Created using Sphinx" in the HTML footer. Default is True. html_show_sphinx = False