Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support copy all image to html folder #247

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import os
import sys
from datetime import datetime
import glob
import shutil


sys.path.insert(0, os.path.abspath('.'))

Expand Down Expand Up @@ -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
Expand Down