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

Improve the list of HTML guides #8460

Merged
merged 2 commits into from
Mar 31, 2022
Merged
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
35 changes: 22 additions & 13 deletions utils/choosing_policy_page.py → utils/gen_html_guides_index.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
#!/usr/bin/python3

import argparse
import os
import pathlib
import sys
import yaml
from collections import namedtuple

import ssg.jinja
from utils.template_renderer import FlexibleLoader

# Helper script used to generate an HTML page to display guides.

Product = namedtuple("Product", ["id", "name", "profiles"])
Profile = namedtuple("Profile", ["id", "title"])


def create_index(data, template_name, output_filename):
html_jinja_template = os.path.join(
os.path.dirname(__file__), template_name)
env = ssg.jinja._get_jinja_environment(dict())
env.loader = FlexibleLoader(os.path.dirname(html_jinja_template))
result = ssg.jinja.process_file(html_jinja_template, data)
with open(output_filename, "wb") as f:
f.write(result.encode('utf8', 'replace'))


def get_data(ssg_root):
data = []
products = []
p = pathlib.Path(ssg_root)
for product_file in p.glob("**/product.yml"):
product_dir = product_file.parent
Expand All @@ -36,25 +51,19 @@ def get_data(ssg_root):
profile_title = profile_yaml["title"]
profile = Profile(id=profile_id, title=profile_title)
product.profiles.append(profile)
data.append(product)
products.append(product)
data = {"products": products}
return data


def print_data(data):
for product in data:
print(f'<h4>{product.name}</h4>')
print(f'<ul>')
for profile in product.profiles:
print(f'<li><a class="light-link" href="ssg-{product.id}-guide-{profile.id}.html">{profile.title}</a></li>')
print('</ul>')
print('<div class="brSpace"></div>')


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"ssg_root",
help="Path to the root directory of scap-security-guide")
parser.add_argument(
"output",
help="Path where the output HTML file should be generated")
args = parser.parse_args()
data = get_data(args.ssg_root)
print_data(data)
create_index(data, "html_guides_index_template.html", args.output)
2 changes: 1 addition & 1 deletion utils/generate_html_pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ echo "</html>" >> $STATS_DIR/index.html
# Generate Guides page
mkdir -p $PAGES_DIR/guides
cp -rf build/guides $PAGES_DIR
utils/choosing_policy_page.py . > $PAGES_DIR/guides/index.html
utils/gen_html_guides_index.py . $PAGES_DIR/guides/index.html


# Generate Mapping Tables page
Expand Down
25 changes: 25 additions & 0 deletions utils/html_guides_index_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Profiles in ComplianceAsCode</title>
<style>
</style>
</head>
<body>

<h1>Profiles in ComplianceAsCode</h1>

{{% for product in products|sort(attribute="name") %}}
<h4>{{{ product.name }}}</h4>
<ul>
{{% for profile in product.profiles|sort(attribute="title") %}}
<li>
<a href="ssg-{{{ product.id }}}-guide-{{{ profile.id }}}.html">{{{ profile.title }}}</a>
</li>
{{% endfor %}}
</ul>
{{% endfor %}}

</body>
</html>