import subprocess
from os import listdir
from os.path import isfile, join, getmtime
-from convert_txt_rfc_to_html import convert_rfc_html
-from src.format_rfc import format_rfc, ProcessingError
-TMP_DIR = 'html_rfcs'
def list_files(directory):
return [f for f in listdir(directory)
- if isfile(join(directory, f)) and f.endswith('.html')]
+ if isfile(join(directory, f))]
def execute(command):
return subprocess.call(command)
def build_file(infile, outfile):
print "Building {}".format(outfile)
- try:
- format_rfc(infile, outfile)
- except ProcessingError:
- print "Skipping {}".format(infile)
+ execute(['python', 'src/render_rfc.py', infile, outfile])
def copy_static(out_dir):
print "Copying static files."
src_path = join(src_dir, filename)
dest_path = join(dest_dir, filename)
+ if '.txt' in dest_path:
+ dest_path = dest_path.split('.txt')[0] + '.html'
+
if filename not in dest_files:
build_file(src_path, dest_path)
src_dir = sys.argv[1]
dest_dir = sys.argv[2]
- #convert_rfc_html(src_dir, TMP_DIR)
- #build_rfcs(TMP_DIR, dest_dir)
+ #build_rfcs(src_dir, dest_dir)
copy_static(dest_dir)
generate_site_index(dest_dir)
# generate-site-index --- create an index.html page for the site.
+import os
import sys
+import json
+from os import listdir
from jinja2 import Environment, FileSystemLoader
+def build_metadata_index(folder):
+ metadata_table = {}
+
+ metadata_files = [os.path.join(folder, f) for f in listdir(folder) if '.json' in f]
+ for metadata in metadata_files:
+ with open(metadata) as fd:
+ metadata = json.load(fd)
+ if 'rfc' in metadata:
+ metadata_table[metadata['rfc']] = metadata
+
+ return metadata_table
+
def main(rfcs, outfile):
+ rfcs = build_metadata_index(rfcs)
+
env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('index.html')
- dct = dict()
+ dct = dict(rfcs=rfcs.values())
rendered = template.render(**dct)
with open(outfile, 'w+') as fd:
fd.write(rendered.encode('utf-8'))
+
if __name__ == '__main__':
if len(sys.argv) != 3:
print "usage: generate-site-index rfcs/ index.html"
def cleanup_author_header(data, **kwargs):
- rfc_number_regexp = re.compile(r'^Request for Comments:\s+(\d+)', re.MULTILINE)
- rfc_number = rfc_number_regexp.match(data)
+ rfc_number_regexp = re.compile(r'Request for Comments:\s+(\d+)', re.MULTILINE | re.IGNORECASE)
+ rfc_number = rfc_number_regexp.search(data)
if rfc_number is not None:
metadata['rfc'] = int(rfc_number.group(1))
- header_regexp = re.compile('(^Network Working Group.+?\n\n)(.+)\n\n(Status of this Memo)', re.MULTILINE | re.DOTALL)
+ header_regexp = re.compile('(^Network Working Group.+?\n\n)(.+)\n\n(Status of this Memo)', re.MULTILINE | re.DOTALL | re.IGNORECASE)
def format_match(match):
header = match.group(1).replace('\n', '<br>')
title = match.group(2)
status = match.group(3)
- metadata['title'] = title.strip()
+ metadata['title'] = title.strip().replace('\n', '')
return """<p>{}</p>
<h1>{}</h1>
# Clean up abstract and copyright notice
- copyright_regex = re.compile('(^Copyright Notice)', re.MULTILINE)
+ copyright_regex = re.compile('(^Copyright Notice)', re.MULTILINE | re.IGNORECASE)
data = copyright_regex.sub(r'<h2>\1</h2>', data)
- abstract_regex = re.compile('(^Abstract)', re.MULTILINE)
+ abstract_regex = re.compile('(^Abstract)', re.MULTILINE | re.IGNORECASE)
data = abstract_regex.sub(r'<h2>\1</h2>', data)
return data
# and lvl3_title_rx.
lvl4_title_rx = re.compile(r"^(\d+)\.(\d+)\.(\d+)\.(\d+)\.*(.*)$", re.MULTILINE)
lvl4_template = r"""<a name="section-\1.\2.\3.\4"><h4>\1.\2.\3.\4 \5</h4></a>
- <a href="raw/{}" class="rawLink">raw</a>
""".format(filename)
data = lvl4_title_rx.sub(lvl4_template, data)
<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="static/css/rfc.css">
+ <link rel="stylesheet" href="static/css/awesomplete.css">
</head>
<body>
- <div class="homepage">
- <h2 class="centered">
- RFCs for the rest of us.<br>
- </h2>
- <div>
- <input type="text" placeholder="Type an RFC name or keywords"></input>
+ <div id="background"></div>
+ <table cellspacing=0 cellpadding=0>
+ <thead>
+ <tr>
+ <th class=docs><h1>RFCSpot</h1></th>
+ <th class=code></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr id='section-{{ num }}'>
+ <td class=docs>
+ <h3>RFCs for the rest of us</h3>
+
+ <form id='searchForm'>
+ <input list="rfcs" />
+ <datalist id="rfcs">
+ {% for rfc in rfcs %}
+ <option label="RFC{{ rfc['rfc'] }} {{ rfc['title'] }}" value="{{ rfc['rfc'] }}"></option>
+ {% endfor %}
+ </datalist>
+ <input type="submit" />
+ </form>
+ </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>
- </div>
- <script type='text/javascript' src='rfc.js'></script>
+ </td>
+ </tr>
+ </table>
+ <script type='text/javascript' src='static/js/jquery-1.12.1.min.js'></script>
+ <script type='text/javascript' src='static/js/awesomplete.min.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
- $("p.rfcparagraph").append('<a>raw</a>').click(function() { alert('YOLO') });
+ var handleSearches = function() {
+ var val = $('rfcs').val()
+ debugger
+ if (val == null)
+ return;
+
+ alert('rfc' + val + '.html');
+ };
+
+ $('#searchForm').click(handleSearches);
});
</script>
</body>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>{{ title }}</title>
- <link rel="stylesheet" href="rfc.css">
+ <link rel="stylesheet" href="static/css/rfc.css">
</head>
<body>
<div id='container'>