Example #1
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]
    parser = argparse.ArgumentParser(description=__doc__)
    args = parser.parse_args(argv)

    templates = {t for t in glob.glob("%s/*.html" % templates_path)}
    for template_name in templates:
        print("Extracting template %r links" % template_name)
        with open(template_name) as t:
            links = extract_links(t.read())
        if links:
            print("%i links found" % len(links))
            for url in links:
                template_name = url_to_template(url)
                path, ext = os.path.splitext(template_name)
                if ext == ".html":
                    # Transform path/to/page.html into path/to/page/index.html
                    path = path + "/index.html"
                else:
                    path += ext
                output = compile_dir + path
                compile_template(template_name, output)
        else:
            print("No links found")
    output = compile_dir + "/index.html"
    compile_template("index.html", output)
    for entry in Entry.objects.all():
        output = compile_dir + entry.slug + "index.html"
        compile_template("entry.html", output, context={"entry": entry})
    for snippet in Snippet.objects.all():
        output = compile_dir + snippet.slug + "index.html"
        compile_template("snippet.html", output, context={"snippet": snippet})
Example #2
0
 def test_without_relative(self):
     "Tests that an empty list is returned if no relative links are found"
     template = """\
     <html>
         <head>
             <link href="http://url/style.css">
         </head>
         <body>
             <a href="http://some-url/">Link</a>
         </body>
     </html>
     """
     self.assertEqual({"http://url/style.css", "http://some-url/"}, extract_links(template))
Example #3
0
 def test_with_relative(self):
     "Tests that a list is returned with relative links found"
     template = """\
     <html>
         <head>
             <link href="/style.css">
         </head>
         <body>
             <a href="/some-url/">Link</a>
         </body>
     </html>
     """
     self.assertEqual({"/style.css", "/some-url/"}, extract_links(template))