Fix links in imported designs
A lot of the links in the imported designs are broken:
- HotDoc allowed a `[][link]` format that Hugo doesn't understand
- HotDoc allowed relative links without text, which Hugo doesn't handle
- The location of the images and other media has changed
- The format used for internal page references has is different
Additionally, fix up touched links to other Apertis pages to use the
Hugo "ref" shortcode, which reduces the risk of leaving hanging links.
Conversion completed with the following python script:
```
import os
import re
import sys
def url_munge(match):
url = match.group('url').strip('.')
if url[0] != "/":
url = "/%s" % url
url = url.replace("media", "images")
link = ("" % url)
return link
def link_munge(match):
link = match.group('link')
new = link.replace("(", "")
new = new.replace(")", "")
new = new.replace("`", "")
new = new.replace("?", "")
new = new.replace(":", "")
new = new.replace(",", "")
new = new.replace("–", "")
new = new.replace("“", "")
new = new.replace("”", "")
new = new.replace(".", "")
new = new.replace(" ", "-")
new = new.lower()
new = (" [%s]( {{< ref \"#%s\" >}} )" % (link, new))
return new
def link_munge_2(match):
link = match.group('link')
new = link.replace("#", "")
new = new.replace("-", " ")
new = new.replace(".md", "")
if not "http" in link:
link = " {{< ref \"%s\" >}} " % link
new = ("[%s](%s)" % (new, link))
return new
for filename in os.listdir(sys.argv[1]):
#print("%s: " % filename)
with open(filename, 'r+') as file:
contents = file.read()
# Hotdoc uses `[][Internal Title]` for internal links whilst Hugo uses `[](#internal-title)`
pattern = re.compile("\[\]\[(?P<link>.*?)\]")
contents = pattern.sub(link_munge, contents)
# Hotdoc allows empty links like `[](url)`
pattern = re.compile("[^!]\[\]\((?P<link>.*?)\)")
contents = pattern.sub(link_munge_2, contents)
# Media links not working
pattern = re.compile("!\[\]\((?P<url>.*?)\)")
contents = pattern.sub(url_munge, contents)
file.seek(0)
file.truncate()
file.write(contents)
```
Signed-off-by:
Martyn Welch <martyn.welch@collabora.com>
parent
35d4de00
No related branches found
No related tags found
Showing
- content/designs/application-bundle-metadata.md 14 additions, 14 deletionscontent/designs/application-bundle-metadata.md
- content/designs/application-entry-points.md 1 addition, 1 deletioncontent/designs/application-entry-points.md
- content/designs/application-framework.md 3 additions, 3 deletionscontent/designs/application-framework.md
- content/designs/application-layout.md 30 additions, 31 deletionscontent/designs/application-layout.md
- content/designs/applications.md 22 additions, 22 deletionscontent/designs/applications.md
- content/designs/audio-management.md 13 additions, 13 deletionscontent/designs/audio-management.md
- content/designs/canterbury-legacy-application-framework.md 2 additions, 2 deletionscontent/designs/canterbury-legacy-application-framework.md
- content/designs/closing-ci-loop.md 6 additions, 7 deletionscontent/designs/closing-ci-loop.md
- content/designs/clutter.md 2 additions, 2 deletionscontent/designs/clutter.md
- content/designs/connectivity.md 11 additions, 11 deletionscontent/designs/connectivity.md
- content/designs/contacts.md 14 additions, 14 deletionscontent/designs/contacts.md
- content/designs/debug-and-logging.md 35 additions, 35 deletionscontent/designs/debug-and-logging.md
- content/designs/geolocation-and-navigation.md 94 additions, 94 deletionscontent/designs/geolocation-and-navigation.md
- content/designs/global-search.md 9 additions, 9 deletionscontent/designs/global-search.md
- content/designs/hardkeys.md 1 addition, 1 deletioncontent/designs/hardkeys.md
- content/designs/inter-domain-communication.md 143 additions, 143 deletionscontent/designs/inter-domain-communication.md
- content/designs/internationalization.md 9 additions, 9 deletionscontent/designs/internationalization.md
- content/designs/license-validation.md 1 addition, 1 deletioncontent/designs/license-validation.md
- content/designs/list.md 96 additions, 103 deletionscontent/designs/list.md
- content/designs/long-term-reproducibility.md 5 additions, 5 deletionscontent/designs/long-term-reproducibility.md
Loading
Please register or sign in to comment