Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Author and Company field #415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions content/patterns/multicloud-gitops/_index.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
title: Multicloud GitOps
date: 2021-12-11
authors:
- Dan Macpherson
- Avani Bhatt
- Andrew Beekhof
company: Red Hat
tier: maintained
summary: This pattern helps you develop and deploy applications on an open hybrid cloud in a stable, simple, and secure way.
rh_products:
Expand Down
4 changes: 4 additions & 0 deletions layouts/partials/authors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ $authors := .Param "authors" | len }}
{{ range $index, $author := .Param "authors" }}
{{ if and (eq (add $index 1) $authors) (gt $authors 1) }} and {{ end }}{{ . }}{{ if and (gt $authors 2) (lt (add $index 1) $authors) }}, {{ end }}
{{ end }}
18 changes: 17 additions & 1 deletion layouts/partials/patterns-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="pf-c-panel pf-m-raised">
<div class="pf-c-panel__main">
<div class="pf-c-panel__main-body">
<div class="pf-l-grid">
<div class="pf-l-grid pf-m-gutter">
<div class="pf-l-grid__item pf-m-10-col">
<h1 class="pf-c-title pf-m-4xl">{{ .Title }}</h1>
</div>
Expand All @@ -25,6 +25,22 @@ <h1 class="pf-c-title pf-m-4xl">{{ .Title }}</h1>
</div>
{{ end }}
</div>
{{ if (isset .Params "authors") }}
<div class="pf-l-grid__item pf-m-3-col">
Author{{if (gt .Params.authors 1)}}s{{ end }}:
</div>
<div class="pf-l-grid__item pf-m-9-col">
{{ partial "authors.html" . }}
</div>
{{ end }}
{{ if (isset .Params "company") }}
<div class="pf-l-grid__item pf-m-3-col">
Company:
</div>
<div class="pf-l-grid__item pf-m-9-col">
{{ .Params.company }}
</div>
{{ end }}
<div class="pf-l-grid__item pf-m-3-col">
Validation status:
</div>
Expand Down
102 changes: 102 additions & 0 deletions layouts/partials/wfm-render-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/python
import xml.etree.ElementTree as ET
import glob
import subprocess
import argparse
import yaml
import os
import shutil
from urllib.parse import urlparse
from urllib.request import urlretrieve

def load_context_map(map_file):
with open(map_file, 'r') as file:
root = yaml.safe_load(file)
return root

def render_output(input_filename, attrs, id):
asciidoctor_command = ["asciidoctor", input_filename, "-a", "nofooter", "-a", "webfonts!", "-a", "stylesheet!", "-b", "xhtml5", "-o", "-"]
asciidoctor_command.extend(attrs)
asciidoctor_output = subprocess.Popen(asciidoctor_command, stdout=subprocess.PIPE)

xpath_command = ["xpath", "-e", "/html/body", "-q"]
xpath_output = subprocess.Popen(xpath_command, stdin=asciidoctor_output.stdout, stdout=subprocess.PIPE)

xmlstarlet_command = ["xmlstarlet", "ed", "--omit-decl", "-r", "/body", "-v", "div"]
xmlstarlet_output = subprocess.Popen(xmlstarlet_command, stdin=xpath_output.stdout, stdout=subprocess.PIPE)

final_output, _ = xmlstarlet_output.communicate()

if id is None:
output_filename = os.path.basename(input_filename).split('.')[0]
else:
output_filename = id

with open("output/%s.html" % output_filename , "w") as output_file:
output_file.write(final_output.decode('utf-8'))

def download_file(url):
remote_filename = urlparse(url)
local_filename = os.path.basename(remote_filename.path)
urlretrieve(url, local_filename)
return local_filename

def convert_href(link, self_context):
if link.startswith(("self.", "ext.")):
if link.startswith("self."):
link = link.removeprefix("self.")
link = self_context + '.' + link
elif link.startswith("ext."):
link = link.removeprefix("ext.")
ids = link.split('.')
context_id = ids[0]
module_id = ids[1]
link = "/context/%s/module/%s" % (context_id, module_id)
return link

if __name__ == '__main__':
parser = argparse.ArgumentParser("wfm-render-map")
parser.add_argument("map_file", help="The content map to render")
args = parser.parse_args()
root = load_context_map(args.map_file)
attrs = []

shutil.rmtree('output', ignore_errors=True)
os.mkdir('output')

if "attributes" in root.keys():
for attr in root['attributes']:
attrs+=['-a',"%s=%s" % (attr, root['attributes'][attr])]

for module in root['modules']:
if "id" in module.keys():
id = module['id']
else:
id = None

if "file" in module.keys():
render_output(module['file'] + ".adoc", attrs, id)
elif "pull" in module.keys():
downloaded_adoc = download_file(module['pull'])
render_output(downloaded_adoc, attrs, id)
os.remove(downloaded_adoc)

for file in glob.glob("output/*.html"):
tree = ET.parse(file)
html_root = tree.getroot()
for link in html_root.findall(".//a"):
link.attrib['href'] = convert_href(link.attrib['href'], root['id'])
tree.write(file)

for index, module in enumerate(root['modules']):
if "id" not in module:
if "file" in module:
module["id"] = os.path.basename(module['file'])
elif "pull" in module:
module["id"] = os.path.basename(module['pull']).split('.')[0]
module.pop("file", None)
module.pop("pull", None)
root['modules'][index] = module
output_map_filename = root["id"]
with open("output/%s.yaml" % output_map_filename , "w") as output_map_file:
yaml.dump(root, output_map_file)
29 changes: 29 additions & 0 deletions static/images/logos/RHlogo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading