def replace_url(self, url): parsed = urlparse(url) if parsed.scheme: return url else: dirname = path.dirname(self.output_path) filepath = path.join(dirname, parsed.path) filepath = path.normpath(path.abspath(filepath)) resolved = self.env.resolver.resolve_source_to_url(filepath, url) relative = urlpath.relpath(self.output_url, resolved) return relative
def replace_url(source_url, output_url, url): # If path is an absolute one, keep it parsed = urlparse.urlparse(url) if not parsed.scheme and not parsed.path.startswith("/"): abs_source_url = urlparse.urljoin(source_url, url) # relpath() will not detect this case if urlparse.urlparse(abs_source_url).scheme: return abs_source_url # rewritten url: relative path from new location (output) # to location of referenced file (source + current url) url = urlpath.relpath(output_url, abs_source_url) return url
def replace_url(source_url, output_url, url): # If path is an absolute one, keep it parsed = urlparse.urlparse(url) if not parsed.scheme and not parsed.path.startswith('/'): abs_source_url = urlparse.urljoin(source_url, url) # relpath() will not detect this case if urlparse.urlparse(abs_source_url).scheme: return abs_source_url # rewritten url: relative path from new location (output) # to location of referenced file (source + current url) url = urlpath.relpath(output_url, abs_source_url) return url