add title variable and apply it to script too
This commit is contained in:
parent
16e4b237f6
commit
52a365835f
3 changed files with 13 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
= Summary
|
||||
= {{book.title}}
|
||||
|
||||
. link:topics/overview.adoc[Overview]
|
||||
.. link:topics/overview/recommended-reading.adoc[Recommended Reading]
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
"splitter"
|
||||
],
|
||||
"variables": {
|
||||
"title": "Keycloak Installation and Configuration Guide",
|
||||
"community": true,
|
||||
"product": false,
|
||||
"images": "keycloak-images",
|
||||
|
|
|
@ -2,12 +2,16 @@ import sys, os, re, json, shutil, errno
|
|||
|
||||
def transform(root, f, targetdir):
|
||||
full = os.path.join(root, f)
|
||||
print full
|
||||
input = open(full, 'r').read()
|
||||
dir = os.path.join(targetdir, root)
|
||||
if not os.path.exists(dir):
|
||||
os.makedirs(dir)
|
||||
output = open(os.path.join(dir, f), 'w')
|
||||
input = applyTransformation(input)
|
||||
output.write(input)
|
||||
|
||||
|
||||
def applyTransformation(input):
|
||||
for variable in re.findall(r"\{\{(.*?)\}\}", input):
|
||||
tmp = variable.replace('.', '_')
|
||||
input = input.replace(variable, tmp)
|
||||
|
@ -19,7 +23,8 @@ def transform(root, f, targetdir):
|
|||
exp = re.compile("[ ]*{% if (.*?) %}(.*?)[ ]*{% endif %}", re.DOTALL)
|
||||
input = re.sub(exp, "ifeval::[{\g<1>}==true]\g<2>endif::[]", input)
|
||||
input = re.sub(r"image:(\.\./)*", "image:", input)
|
||||
output.write(input)
|
||||
return input
|
||||
|
||||
|
||||
indir = 'topics'
|
||||
targetdir = 'target'
|
||||
|
@ -55,11 +60,7 @@ include::document-attributes.adoc[]
|
|||
""")
|
||||
|
||||
input = re.sub(r"[ ]*\.+\s*link:(.*)\[(.*)\]", "include::\g<1>[]", input)
|
||||
for variable in re.findall(r"[ ]*{% if (.*?) %}", input):
|
||||
tmp = variable.replace('.', '_')
|
||||
input = input.replace(variable, tmp)
|
||||
exp = re.compile("[ ]*{% if (.*?) %}(.*?)[ ]*{% endif %}", re.DOTALL)
|
||||
input = re.sub(exp, "ifeval::[{\g<1>}==true]\g<2>endif::[]", input)
|
||||
input = applyTransformation(input)
|
||||
output.write(input)
|
||||
|
||||
# parse book.json file and create document attributes
|
||||
|
@ -93,6 +94,8 @@ for attribute in attributeList:
|
|||
for k in attribute.keys():
|
||||
output.write(':book_' + k + ": " + attribute[k] + "\n")
|
||||
|
||||
print "Transformation complete!"
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue