aboutsummaryrefslogtreecommitdiff
path: root/website/tools/releases-toml.py
diff options
context:
space:
mode:
authorSergio Carlavilla Delgado <carlavilla@FreeBSD.org>2021-01-25 23:31:29 +0000
committerSergio Carlavilla Delgado <carlavilla@FreeBSD.org>2021-01-25 23:31:29 +0000
commit989d921f5d4ac8d8b7c831c13b8954ad1901be24 (patch)
treea5d768f9af4b55422fdf5b17064879ae1c7ce032 /website/tools/releases-toml.py
parent0cff342f42461c5081b98bce7581f43df319e4f4 (diff)
downloaddoc-989d921f5d4ac8d8b7c831c13b8954ad1901be24.tar.gz
doc-989d921f5d4ac8d8b7c831c13b8954ad1901be24.zip
Migrate doc to Hugo/AsciiDoctor
I'm very pleased to announce the release of our new website and documentation using the new toolchain with Hugo and AsciiDoctor. To get more information about the new toolchain please read the FreeBSD Documentation Project Primer[1], Hugo docs[2] and AsciiDoctor docs[3]. Acknowledgment: Benedict Reuschling <bcr@> Glen Barber <gjb@> Hiroki Sato <hrs@> Li-Wen Hsu <lwhsu@> Sean Chittenden <seanc@> The FreeBSD Foundation [1] https://docs.FreeBSD.org/en/books/fdp-primer/ [2] https://gohugo.io/documentation/ [3] https://docs.asciidoctor.org/home/ Approved by: doceng, core
Diffstat (limited to 'website/tools/releases-toml.py')
-rw-r--r--website/tools/releases-toml.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/website/tools/releases-toml.py b/website/tools/releases-toml.py
new file mode 100644
index 0000000000..2e0b72b688
--- /dev/null
+++ b/website/tools/releases-toml.py
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+"""
+BSD 2-Clause License
+
+Copyright (c) 2020-2021, The FreeBSD Project
+Copyright (c) 2020-2021, Sergio Carlavilla <carlavilla@FreeBSD.org>
+
+This script will convert the releases.adoc file to releases.toml
+in this way we can share the releases variables between AsciiDoctor and Hugo
+"""
+#!/usr/bin/env python3
+
+import sys, getopt
+import re
+
+variables = {}
+
+def getValueByKey(key):
+ return variables[key.replace("{", "").replace("}", "")].replace("\"", "")
+
+def loadVariables(path):
+ with open(path, 'r', encoding = 'utf-8') as releasesFile:
+ line = releasesFile.readline()
+
+ while line:
+ if (re.match(r"^:{1}[^\n]+", line)):
+ variable = re.sub(':', '', line.strip(), 1)
+ variable = re.sub(': ', '="', variable)
+ variable += "\""
+ data = variable.split("=")
+
+ if (len(data) == 2):
+ variables.update( {data[0] : data[1]} )
+
+ line = releasesFile.readline()
+
+def main(argv):
+ path = ''
+
+ try:
+ opts, args = getopt.getopt(argv,"hp:",["path="])
+ except getopt.GetoptError:
+ print('releases-toml.py -p <path>')
+ sys.exit(2)
+ for opt, arg in opts:
+ if opt == '-h':
+ print('releases-toml.py -p <path>')
+ sys.exit()
+ elif opt in ("-p", "--path"):
+ path = arg
+
+ releasesTOML = "# Code generated by the FreeBSD Documentation toolchain. DO NOT EDIT.\n"
+ releasesTOML += "# Please don't change this file manually but run `make` to update it.\n"
+ releasesTOML += "# For more information, please read the FreeBSD Documentation Project Primer\n"
+ releasesTOML += '\n'
+
+ loadVariables(path)
+
+ for key in variables:
+ foundBraces = re.search(r"\{.*?\}", variables[key])
+
+ if (foundBraces):
+ braces = foundBraces.group(0)
+ releasesTOML += key + "=" + variables[key].replace(braces, getValueByKey(braces)) + "\n"
+ else:
+ releasesTOML += key + "=" + variables[key] + "\n"
+
+ with open('./data/releases.toml', 'w', encoding = 'utf-8') as releasesTOMLFile:
+ releasesTOMLFile.write(releasesTOML)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])