From: Karim Hamidou Date: Sat, 12 Mar 2016 06:25:54 +0000 (-0800) Subject: WIP X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=870d4141c4f43226d884f36030e581b4d0711896;p=rfcspot.git WIP --- diff --git a/build.py b/build.py index 31d199c2..210f52f9 100644 --- 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) diff --git a/src/generate-site-index.py b/src/generate-site-index.py index 93bce6b0..2111f6ba 100644 --- a/src/generate-site-index.py +++ b/src/generate-site-index.py @@ -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" diff --git a/src/render_rfc.py b/src/render_rfc.py index d5e67f91..e126b5ea 100644 --- a/src/render_rfc.py +++ b/src/render_rfc.py @@ -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', '
') title = match.group(2) status = match.group(3) - metadata['title'] = title.strip() + metadata['title'] = title.strip().replace('\n', '') return """

{}

{}

@@ -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'

\1

', data) - abstract_regex = re.compile('(^Abstract)', re.MULTILINE) + abstract_regex = re.compile('(^Abstract)', re.MULTILINE | re.IGNORECASE) data = abstract_regex.sub(r'

\1

', 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"""

\1.\2.\3.\4 \5

- raw """.format(filename) data = lvl4_title_rx.sub(lvl4_template, data) diff --git a/templates/index.html b/templates/index.html index 60b88a96..adf5ecfc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -4,20 +4,60 @@ RFC Czar: RFC for the rest of us. + -
-

- RFCs for the rest of us.
-

-
- +
+ + + + + + + + + + + + +

RFCSpot

+

RFCs for the rest of us

+ +
+ + + {% for rfc in rfcs %} + + {% endfor %} + + +
+
+
+
- - +
+ + diff --git a/templates/rfc.html b/templates/rfc.html index 08724af5..6f2bcc41 100644 --- a/templates/rfc.html +++ b/templates/rfc.html @@ -3,7 +3,7 @@ {{ title }} - +