Convert HotDoc formatting for Hugo
The existing metadata and some inline codes need converting to work with
Hugo:
- Remove authors as we don't have an equivalent for that in Hugo
- Add in fields that the existing metadata doesn't have
- Include aliases to allow us to point to the new pages from a
redirect on designs.apertis.org
- Ensure we have a title (based on filename if one not present)
- Convert hotdoc code blocks to Hugo equivalent
- 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.
All frontmatter created in toml format to stay consistent with existing
documents.
Converted using the following python script:
```
import os
import re
import subprocess
import sys
import toml
import yaml
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("."):
if ".md" not in filename:
continue
print("%s: " % filename)
with open(filename, 'r+') as file:
contents = file.read()
if contents[0:3] == "+++":
# We have toml
data = toml.loads(contents.split("+++")[1])
doc = "+++".join(contents.split("+++")[2:])
elif contents[0:3] == "---":
# We have yaml
data = yaml.load(contents.split("---")[1])
doc = "---".join(contents.split("---")[2:])
else:
# No frontmatter
data = {}
doc = contents
if not "title" in data.keys():
data["title"] = filename.split(".")[0].replace('_', ' ').capitalize()
data["weight"] = 100
data["aliases"] = ["/old-developer/latest/%s" % filename.replace(".md", ".html")]
# Add aliases
latest = data['aliases'][0]
for version in ['v2019', 'v2020', 'v2021pre', 'v2022dev0']:
versioned = latest.replace("/latest/", "/%s/" % version)
data['aliases'].append(versioned)
data["outputs"] = ["html", "pdf-in"]
# Remove authors
if "authors" in data.keys():
del data["authors"]
# Switch HotDoc code blocks to hugo code blocks
pattern = re.compile("^---", re.MULTILINE)
doc = pattern.sub("```", doc)
# Hotdoc uses `[][Internal Title]` for internal links whilst Hugo uses `[](#internal-title)`
pattern = re.compile("\[\]\[(?P<link>.*?)\]")
doc = pattern.sub(link_munge, doc)
# Hotdoc allows empty links like `[](url)`
pattern = re.compile("[^!]\[\]\((?P<link>.*?)\)")
doc = pattern.sub(link_munge_2, doc)
# Media links not working
pattern = re.compile("!\[\]\((?P<url>.*?)\)")
doc = pattern.sub(url_munge, doc)
file.seek(0)
file.truncate()
file.write("+++\n")
file.write(toml.dumps(data))
file.write("+++")
file.write(doc)
```
Signed-off-by:
Martyn Welch <martyn.welch@collabora.com>
parent
453977a1
No related branches found
No related tags found
Showing
- content/developer/apis.md 8 additions, 10 deletionscontent/developer/apis.md
- content/developer/app-dev.md 9 additions, 13 deletionscontent/developer/app-dev.md
- content/developer/appdev-ade.md 8 additions, 10 deletionscontent/developer/appdev-ade.md
- content/developer/appdev-agents.md 8 additions, 13 deletionscontent/developer/appdev-agents.md
- content/developer/appdev-debugging.md 8 additions, 4 deletionscontent/developer/appdev-debugging.md
- content/developer/appdev-design.md 8 additions, 10 deletionscontent/developer/appdev-design.md
- content/developer/appdev-hello-world.md 21 additions, 25 deletionscontent/developer/appdev-hello-world.md
- content/developer/appdev-structure.md 27 additions, 22 deletionscontent/developer/appdev-structure.md
- content/developer/apps-core.md 8 additions, 9 deletionscontent/developer/apps-core.md
- content/developer/bundle-spec.md 82 additions, 85 deletionscontent/developer/bundle-spec.md
- content/developer/connectivity.md 8 additions, 9 deletionscontent/developer/connectivity.md
- content/developer/cross-build-toolchain.md 8 additions, 10 deletionscontent/developer/cross-build-toolchain.md
- content/developer/deployment-management.md 8 additions, 10 deletionscontent/developer/deployment-management.md
- content/developer/faq.md 8 additions, 10 deletionscontent/developer/faq.md
- content/developer/framework-app.md 8 additions, 9 deletionscontent/developer/framework-app.md
- content/developer/framework-ui.md 8 additions, 9 deletionscontent/developer/framework-ui.md
- content/developer/index.md 13 additions, 17 deletionscontent/developer/index.md
- content/developer/infrastructure-ui.md 8 additions, 9 deletionscontent/developer/infrastructure-ui.md
- content/developer/install.md 9 additions, 13 deletionscontent/developer/install.md
- content/developer/internet.md 8 additions, 9 deletionscontent/developer/internet.md
Loading
Please register or sign in to comment