summaryrefslogtreecommitdiffstats
path: root/doc-publik
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-03-20 09:56:05 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-03-20 09:56:05 (GMT)
commitb610944c51d0c08f41cdb6ee130d763550337449 (patch)
tree77a414a610909d9d46692a9c718b1e47ae772022 /doc-publik
parentea13ac31d086284b62577db2401ffb77d19b9605 (diff)
downloadmisc-fred-b610944c51d0c08f41cdb6ee130d763550337449.zip
misc-fred-b610944c51d0c08f41cdb6ee130d763550337449.tar.gz
misc-fred-b610944c51d0c08f41cdb6ee130d763550337449.tar.bz2
doc: add support for crosslinks
Diffstat (limited to 'doc-publik')
-rw-r--r--doc-publik/update-publik-doc-from-mallard.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/doc-publik/update-publik-doc-from-mallard.py b/doc-publik/update-publik-doc-from-mallard.py
index df01a55..2bfc08e 100644
--- a/doc-publik/update-publik-doc-from-mallard.py
+++ b/doc-publik/update-publik-doc-from-mallard.py
@@ -1,3 +1,4 @@
+import urlparse
from bs4 import BeautifulSoup
import html5lib
import requests
@@ -15,6 +16,19 @@ for cell in TextCell.objects.filter(slug__startswith='mallard-'):
document = BeautifulSoup(resp.content, 'html5lib')
content = document.find('div', 'body')
more_info = document.find('div', 'sect sect-links')
+ for a in document.find_all('a'):
+ href = a.attrs['href']
+ parsed = urlparse.urlparse(href)
+ if parsed.netloc:
+ continue
+ if '/' in parsed.path:
+ continue
+ try:
+ target_cell = TextCell.objects.get(slug='mallard-%s' % parsed.path.replace('.html', ''))
+ except TextCell.DoesNotExist:
+ continue
+ a.attrs['href'] = target_cell.page.get_online_url()
+
new_content = unicode(content).replace(unicode(more_info), '')
cell.text = new_content
cell.save()