]> khamidou — GitHub mirrors - rfcspot.git/commitdiff
better build script
authorKarim Hamidou <karim@MacBook.local>
Tue, 16 Feb 2016 05:51:43 +0000 (21:51 -0800)
committerKarim Hamidou <karim@MacBook.local>
Tue, 16 Feb 2016 05:51:43 +0000 (21:51 -0800)
build.py
src/generate-site-index.py
templates/index.html [new file with mode: 0644]

index 2c649cda752b28af8d0484596939eba92acedae5..1dd40d2cc69976a7fbf1b563220a691fea5ede33 100644 (file)
--- 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()
index 49b2be97a9e77e4e5e6d93004fec4f9fddccc7d8..93bce6b07d498b9e3966f09ad26f309ebc92cfba 100644 (file)
@@ -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 (file)
index 0000000..445b61d
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="content-type" content="text/html;charset=utf-8">
+  <title>RFC Czar: RFC for the rest of us.</title>
+  <link rel="stylesheet" href="rfc.css">
+</head>
+<body>
+<div id='container'>
+  <div id="background"></div>
+  <table cellspacing=0 cellpadding=0>
+  <thead>
+    <tr>
+      <th class=docs><h1>RFC Czar</h1></th>
+      <th class=code></th>
+    </tr>
+  </thead>
+  <tbody>
+    <tr id='section-{{ num }}'>
+      <td class=docs>
+        <p>
+            RFC Czar gives you access to all the IETF RFCs, in an easy-to-understand two column format.
+        </p>
+        <p>
+            Try it on an <a href=''>example RFC</a>.
+        </p>
+      </td>
+      <td class=code>
+        <div class='highlight'>
+            <b>Related Stack Overflow questions:</b>
+            <ul>
+                {% for question in questions %}
+                    <li><a href={{ question['url'] }}>{{ question['title'] }}</a></li>
+                {% endfor %}
+            </ul>
+        </div>
+      </td>
+    </tr>
+  </table>
+</div>
+</body>