plugin blog_import_dokuwiki: fixes wrong URL when a substitution occurs twice
This commit is contained in:
parent
de3eaeeeeb
commit
657c234406
1 changed files with 7 additions and 7 deletions
|
|
@ -247,7 +247,7 @@ class Importer(DokuWiki):
|
|||
tgt = '/blog/%s/%s" target="#"' % (profile_jid.user, backlink)
|
||||
text = text.replace(src, tgt)
|
||||
|
||||
subs = []
|
||||
subs = {}
|
||||
|
||||
link_pattern = r"""<(img|a)[^>]* (src|href)="([^"]+)"[^>]*>"""
|
||||
for tag in re.finditer(link_pattern, text):
|
||||
|
|
@ -257,10 +257,10 @@ class Importer(DokuWiki):
|
|||
continue
|
||||
if self.media_repo:
|
||||
self.moveMedia(link, subs)
|
||||
else:
|
||||
subs.append((link, urlparse.urljoin(self.url, link)))
|
||||
elif link not in subs:
|
||||
subs[link] = urlparse.urljoin(self.url, link)
|
||||
|
||||
for url, new_url in subs:
|
||||
for url, new_url in subs.iteritems():
|
||||
text = text.replace(url, new_url)
|
||||
return text
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ class Importer(DokuWiki):
|
|||
"""Move a media from the DokuWiki host to the new repository.
|
||||
|
||||
@param link (unicode): media link
|
||||
@param subs (set(couple)): substitutions list
|
||||
@param subs (dict): substitutions data
|
||||
"""
|
||||
url = urlparse.urljoin(self.url, link)
|
||||
user_media = re.match(r"(/lib/exe/\w+.php\?)(.*)", link)
|
||||
|
|
@ -282,7 +282,7 @@ class Importer(DokuWiki):
|
|||
log.warning("No media found in fetch URL: %s" % user_media.group(2))
|
||||
return
|
||||
if re.match(r"^\w*://", media): # external URL to link directly
|
||||
subs.append((link, media))
|
||||
subs[link] = media
|
||||
return
|
||||
try: # create thumbnail
|
||||
thumb_width = params["w"][0]
|
||||
|
|
@ -308,7 +308,7 @@ class Importer(DokuWiki):
|
|||
self.createThumbnail(filepath, thumbnail, thumb_width)
|
||||
|
||||
new_url = os.path.join(self.media_repo, filename)
|
||||
subs.append((link, new_url))
|
||||
subs[link] = new_url
|
||||
|
||||
def downloadMedia(self, source, dest):
|
||||
"""Copy media to localhost.
|
||||
|
|
|
|||
Loading…
Reference in a new issue