]> khamidou — GitHub mirrors - rfcspot.git/commitdiff
WIP
authorKarim Hamidou <khamidou@gmail.com>
Sat, 12 Mar 2016 06:25:54 +0000 (22:25 -0800)
committerKarim Hamidou <khamidou@gmail.com>
Sat, 12 Mar 2016 06:25:54 +0000 (22:25 -0800)
build.py
src/generate-site-index.py
src/render_rfc.py
templates/index.html
templates/rfc.html

index 31d199c2e56686ee60a7cc75a49010e16af74b5d..210f52f91ece59f724b887f9b1391961625de714 100644 (file)
--- a/build.py
+++ b/build.py
@@ -6,14 +6,11 @@ import sys
 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)
@@ -21,10 +18,7 @@ def execute(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."
@@ -44,6 +38,9 @@ def build_rfcs(src_dir, dest_dir):
         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)
 
@@ -59,8 +56,7 @@ def main():
     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)
 
index 93bce6b07d498b9e3966f09ad26f309ebc92cfba..2111f6baaee5ffd8e5cef2e836c19acba6813942 100644 (file)
@@ -1,17 +1,35 @@
 # 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"
index d5e67f91b0bc054206bfa2d48a9c8a95f7e2d7ad..e126b5ea1598a1e9ec10975aeca038b30cf43aaa 100644 (file)
@@ -13,20 +13,20 @@ metadata = dict()
 
 
 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>
@@ -36,10 +36,10 @@ def cleanup_author_header(data, **kwargs):
 
 
     # 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
@@ -130,7 +130,6 @@ def anchor_titles(data, **kwargs):
     # 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)
index 60b88a9633e1fa7845d8e4ded5e25915224388e1..adf5ecfc720e36145f222003124788bddd107f8a 100644 (file)
@@ -4,20 +4,60 @@
   <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>
index 08724af51254a4090d3684b95c9ce71a2be26960..6f2bcc41bf5bb18e3169e591b93c5f2d2f340230 100644 (file)
@@ -3,7 +3,7 @@
 <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'>