Merge lp:~dholbach/developer-ubuntu-com/1511676 into lp:developer-ubuntu-com

Proposed by Daniel Holbach on 2015-10-30
Status: Merged
Approved by: David Callé on 2015-11-06
Approved revision: 159
Merged at revision: 165
Proposed branch: lp:~dholbach/developer-ubuntu-com/1511676
Merge into: lp:developer-ubuntu-com
Diff against target: 60 lines (+16/-10)
1 file modified
developer_portal/management/commands/import-external-docs-branches.py (+16/-10)
To merge this branch: bzr merge lp:~dholbach/developer-ubuntu-com/1511676
Reviewer Review Type Date Requested Status
David Callé 2015-10-30 Approve on 2015-11-06
Michael Hall 2015-10-30 Pending
Ubuntu App Developer site developers 2015-10-30 Pending
Review via email: mp+276253@code.launchpad.net

Commit Message

Fix links within imported markdown docs.

To post a comment you must log in.
David Callé (davidc3) wrote :

Works great! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'developer_portal/management/commands/import-external-docs-branches.py'
2--- developer_portal/management/commands/import-external-docs-branches.py 2015-10-30 10:34:06 +0000
3+++ developer_portal/management/commands/import-external-docs-branches.py 2015-10-30 12:56:05 +0000
4@@ -100,12 +100,19 @@
5 "</code></pre>",
6 "</code></pre></div><div class=\"eight-col\">")
7
8- def replace_links(self, titles):
9+ def replace_links(self, titles, url_map):
10 for title in titles:
11- url = u"/snappy/guides/%s/%s" % (
12- self.release_alias, slugify(title))
13- link = u"<a href=\"%s\">%s</a>" % (url, titles[title])
14- self.html = self.html.replace(os.path.basename(title), link)
15+ local_md_fn = os.path.basename(title)
16+ url = u'/'+url_map[title]
17+ # Replace links of the form <a href="/path/somefile.md"> first
18+ href = u"<a href=\"{}\">".format(url)
19+ md_href = u"<a href=\"{}\">".format(local_md_fn)
20+ self.html = self.html.replace(md_href, href)
21+
22+ # Now we can replace free-standing "somefile.md" references in
23+ # the HTML
24+ link = href + u"{}</a>".format(titles[title])
25+ self.html = self.html.replace(local_md_fn, link)
26
27 def publish(self):
28 '''Publishes pages in their branch alias namespace.'''
29@@ -153,6 +160,7 @@
30
31 class LocalBranch:
32 titles = {}
33+ url_map = {}
34
35 def __init__(self, dirname, external_branch, db_actions):
36 self.dirname = dirname
37@@ -181,8 +189,11 @@
38 self.db_actions)
39 self.md_files += [md_file]
40 self.titles[md_file.fn] = md_file.title
41+ self.url_map[md_file.fn] = md_file.full_url
42 if not self.index_doc:
43 self._create_fake_index_doc()
44+ for md_file in self.md_files:
45+ md_file.replace_links(self.titles, self.url_map)
46
47 def remove_old_pages(self):
48 imported_page_urls = set([md_file.full_url
49@@ -246,11 +257,6 @@
50 if self.release_alias != 'current':
51 self.index_doc_title += ' (%s)' % self.release_alias
52
53- def import_markdown(self):
54- LocalBranch.import_markdown(self)
55- for md_file in self.md_files:
56- md_file.replace_links(self.titles)
57-
58
59 def get_or_create_page(title, full_url, menu_title=None,
60 in_navigation=True, redirect=None, html=None):

Subscribers

People subscribed via source and target branches