From ab94a03cbf668fd6d6efc45e4962be5fb7984bc3 Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Mon, 15 Feb 2016 21:51:43 -0800 Subject: [PATCH] better build script --- build.py | 16 +++++++++++++-- src/generate-site-index.py | 19 ++++++++++++++---- templates/index.html | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 templates/index.html diff --git a/build.py b/build.py index 2c649cda..1dd40d2c 100644 --- a/build.py +++ b/build.py @@ -11,12 +11,22 @@ def list_files(directory): return [f for f in listdir(directory) if isfile(join(directory, f)) and f.endswith('.html')] +def execute(command): + return subprocess.call(command) def build_file(infile, outfile): command = ['python', 'src/format-rfc.py', infile, outfile] - print " ".join(command) - return subprocess.call(command) + execute(command) + +def copy_css(out_dir): + print "Copying CSS." + command = ['cp', 'rfc.css', out_dir] + execute(command) +def generate_site_index(out_dir): + print "Creating index file." + command = ['python', 'src/generate-site-index.py', out_dir, join(out_dir, 'index.html')] + execute(command) def main(): if len(sys.argv) != 3: @@ -39,6 +49,8 @@ def main(): if getmtime(src_path) > getmtime(dest_path): build_file(src_path, dest_path) + copy_css(dest_dir) + generate_site_index(dest_dir) if __name__ == '__main__': main() diff --git a/src/generate-site-index.py b/src/generate-site-index.py index 49b2be97..93bce6b0 100644 --- a/src/generate-site-index.py +++ b/src/generate-site-index.py @@ -1,8 +1,19 @@ # generate-site-index --- create an index.html page for the site. -def main(): - +import sys +from jinja2 import Environment, FileSystemLoader + +def main(rfcs, outfile): + env = Environment(loader=FileSystemLoader('templates')) + template = env.get_template('index.html') + + dct = dict() + rendered = template.render(**dct) + + with open(outfile, 'w+') as fd: + fd.write(rendered.encode('utf-8')) + if __name__ == '__main__': - if len(sys.argv) != 2: + if len(sys.argv) != 3: print "usage: generate-site-index rfcs/ index.html" - main() + main(sys.argv[1], sys.argv[2]) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 00000000..445b61d6 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,41 @@ + + + + + RFC Czar: RFC for the rest of us. + + + +
+
+ + + + + + + + + + + + +

RFC Czar

+

+ RFC Czar gives you access to all the IETF RFCs, in an easy-to-understand two column format. +

+

+ Try it on an example RFC. +

+
+
+ Related Stack Overflow questions: + +
+
+
+ -- 2.43.0