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:
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()
# 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])
--- /dev/null
+<!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>