View Single Post
Old 11-15-2019, 02:59 PM   #445
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,705
Karma: 205039118
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Is there any kind of simple algorithm that could be used to calculate a relative href between two files?

If one is creating a new xhtml file, I'm trying to think of a consistent way to come up with the proper src to a particular image file (already in the epub) based on the known factors.

Say I've created an xhtml file with my plugin whose href (relative to the opf file) is something like:

"book1/xhtml/newfile.xhtml"

and I have an image file with an href (relative to the opf file) of:

book1/images/myimage,jpg

I'm looking for some sort of reusable, failsafe function that could take two hrefs (from the various iter functions) as parameters (source and target) and give me a relative href from the first parameter's file to the second parameter's file.

Consider the two previously mentioned sample hrefs:

getRelativeHref('book1/xhtml/newfile.xhtml', 'book1/images/myimage,jpg')

needs to be able to return a value of '../images/myimage.jpg' so it can be used in an img tag in newfile.xhtml. Is that possible to do with any two files' hrefs in any epub structured in any way? Or will I need to build a relative href from the root of the epub up to be able to make it work under any conditions?

Or am I overthinking this?--which is entirely possible!

Last edited by DiapDealer; 11-15-2019 at 03:02 PM.
DiapDealer is offline   Reply With Quote