-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix: Download image to cache_path #23
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,17 +157,16 @@ 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()) | ||
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']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find that remote images with See also my comment here #23 (comment) |
||
env.remote_images[img['remote_uri']] = 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']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change needed? I'm not completely up to speed about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to add file by self -- because we return a image node, it will be processed by sphinx's env collector. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In contrast to line 163 which seems necessary (see https://github.com/sphinx-contrib/images/pull/23/files/4d656516ca9453f46d158ca29a20fe8e22ff5674#r660153218) line 170 does not appear to be necessary, local images are copied to the Edit: clarity |
||
|
||
img['content'] = description.astext() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused about this, do you need to
os.path.join
the relative path to/
? Is this actually the URL that Sphinx will use to reference the image in the HTML? If it's actually that it might make sense to useurllib.parse.urljoin
in order to make it more obvious what you're doing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I wrote a confusing comment :'(.
The prefixed
/
means the uri is "relative to source dir"(rootof sphinx project) but not "relative to current document's dir". Without it, sphinx will try load image fromsrcdir/foo/bar/_images
, while ourcache_path
issrcdir/_images/
.And the URI is actualy a filesystem path here, so I think we need
os.path.join
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My testing shows me thumbnail directives with
:download: true
were copied correctly to_build/html/_images/
and the URL set correctly before this PR (e.g. in 0.9.3).Thumbnail directives (local or remote) in
index.html
turn into_images/<imagefile>
-URLs and thumbnail directives insubdir/subfile.rst
turn into../_images/<imagefile>
-URLs (because the html-file resides in a subdirectory compared to index.html../_images
are used).Edit: clarity