From 1f705bd488c3ff082c16e85c1ea153a89aa5f705 Mon Sep 17 00:00:00 2001 From: Shengyu Zhang Date: Wed, 16 Jun 2021 20:54:23 +0800 Subject: [PATCH 1/4] Fix: Download iamge to cache_path --- sphinxcontrib/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinxcontrib/images.py b/sphinxcontrib/images.py index b8523f1..63f4275 100644 --- a/sphinxcontrib/images.py +++ b/sphinxcontrib/images.py @@ -157,7 +157,7 @@ def run(self): if self.is_remote(self.arguments[0]): img['remote'] = True if download: - img['uri'] = os.path.join('_images', hashlib.sha1(self.arguments[0].encode()).hexdigest()) + img['uri'] = os.path.join(conf['cache_path'], hashlib.sha1(self.arguments[0].encode()).hexdigest()) img['remote_uri'] = self.arguments[0] env.remote_images[img['remote_uri']] = img['uri'] env.images.add_file('', img['uri']) From f9084e007946c7db5c93d367c72944e060a1eaeb Mon Sep 17 00:00:00 2001 From: Shengyu Zhang Date: Thu, 17 Jun 2021 21:50:44 +0800 Subject: [PATCH 2/4] URI of image node should be prefixed with '/' --- sphinxcontrib/images.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sphinxcontrib/images.py b/sphinxcontrib/images.py index 63f4275..914c0b5 100644 --- a/sphinxcontrib/images.py +++ b/sphinxcontrib/images.py @@ -157,10 +157,11 @@ def run(self): if self.is_remote(self.arguments[0]): img['remote'] = True if download: - img['uri'] = os.path.join(conf['cache_path'], hashlib.sha1(self.arguments[0].encode()).hexdigest()) + reluri = os.path.join(conf['cache_path'], hashlib.sha1(self.arguments[0].encode()).hexdigest()) + img['uri'] = os.path.join('/', reluri) # relative to source dir img['remote_uri'] = self.arguments[0] - env.remote_images[img['remote_uri']] = img['uri'] - env.images.add_file('', img['uri']) + env.remote_images[img['remote_uri']] = reluri + env.images.add_file('', reluri) else: img['uri'] = self.arguments[0] img['remote_uri'] = self.arguments[0] From 4d656516ca9453f46d158ca29a20fe8e22ff5674 Mon Sep 17 00:00:00 2001 From: Shengyu Zhang Date: Thu, 17 Jun 2021 21:51:07 +0800 Subject: [PATCH 3/4] No need to add file to env by self --- sphinxcontrib/images.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/sphinxcontrib/images.py b/sphinxcontrib/images.py index 914c0b5..7c49e17 100644 --- a/sphinxcontrib/images.py +++ b/sphinxcontrib/images.py @@ -161,14 +161,12 @@ def run(self): img['uri'] = os.path.join('/', reluri) # relative to source dir img['remote_uri'] = self.arguments[0] env.remote_images[img['remote_uri']] = reluri - env.images.add_file('', reluri) else: img['uri'] = self.arguments[0] img['remote_uri'] = self.arguments[0] else: img['uri'] = self.arguments[0] img['remote'] = False - env.images.add_file('', img['uri']) img['content'] = description.astext() From 747bf4820722d3f6d55cef0a3d091ac1c403d859 Mon Sep 17 00:00:00 2001 From: Shengyu Zhang Date: Fri, 13 Aug 2021 14:19:51 +0800 Subject: [PATCH 4/4] Manually copy downloaded image to env --- sphinxcontrib/images.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sphinxcontrib/images.py b/sphinxcontrib/images.py index 7c49e17..76bd65d 100644 --- a/sphinxcontrib/images.py +++ b/sphinxcontrib/images.py @@ -161,6 +161,7 @@ def run(self): img['uri'] = os.path.join('/', reluri) # relative to source dir img['remote_uri'] = self.arguments[0] env.remote_images[img['remote_uri']] = reluri + env.images.add_file('', img['uri']) else: img['uri'] = self.arguments[0] img['remote_uri'] = self.arguments[0]