|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Generate a realistic HTML file for benchmarking HTML rewriting.""" |
| 3 | + |
| 4 | + |
| 5 | +def generate_html(): |
| 6 | + """Generate a realistic HTML document with various elements.""" |
| 7 | + |
| 8 | + html = """<!DOCTYPE html> |
| 9 | +<html lang="en"> |
| 10 | +<head> |
| 11 | + <meta charset="UTF-8"> |
| 12 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 13 | + <title>Benchmark HTML Document</title> |
| 14 | + <link rel="stylesheet" href="/styles/main.css"> |
| 15 | + <link rel="stylesheet" href="/styles/theme.css"> |
| 16 | +</head> |
| 17 | +<body> |
| 18 | + <header> |
| 19 | + <nav class="navbar"> |
| 20 | + <div class="container"> |
| 21 | + <a href="/" class="logo">Benchmark Site</a> |
| 22 | + <ul class="nav-menu"> |
| 23 | + <li><a href="/home">Home</a></li> |
| 24 | + <li><a href="/about">About</a></li> |
| 25 | + <li><a href="/products">Products</a></li> |
| 26 | + <li><a href="https://external.com">External Link</a></li> |
| 27 | + <li><a href="/contact">Contact</a></li> |
| 28 | + </ul> |
| 29 | + </div> |
| 30 | + </nav> |
| 31 | + </header> |
| 32 | +
|
| 33 | + <main class="content"> |
| 34 | +""" |
| 35 | + |
| 36 | + # Generate multiple article sections |
| 37 | + for i in range(50): |
| 38 | + html += f""" |
| 39 | + <article class="post" id="post-{i}"> |
| 40 | + <div class="post-header"> |
| 41 | + <h2><a href="/posts/{i}">Article Title {i}</a></h2> |
| 42 | + <div class="meta"> |
| 43 | + <span class="author">Author {i % 10}</span> |
| 44 | + <span class="date">2024-12-{(i % 28) + 1:02d}</span> |
| 45 | + </div> |
| 46 | + </div> |
| 47 | +
|
| 48 | + <div class="post-content"> |
| 49 | + <img src="/images/article-{i}.jpg" alt="Article {i} image" class="featured-image"> |
| 50 | + <p>This is the introduction paragraph for article {i}. It contains some introductory text that describes what the article is about.</p> |
| 51 | +
|
| 52 | + <div class="post-body"> |
| 53 | + <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> |
| 54 | + <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> |
| 55 | +
|
| 56 | + <div class="callout"> |
| 57 | + <p>This is an important callout box with additional information.</p> |
| 58 | + </div> |
| 59 | +
|
| 60 | + <ul class="features"> |
| 61 | + <li><a href="/feature/{i}-1">Feature 1</a></li> |
| 62 | + <li><a href="/feature/{i}-2">Feature 2</a></li> |
| 63 | + <li><a href="/feature/{i}-3">Feature 3</a></li> |
| 64 | + </ul> |
| 65 | + </div> |
| 66 | +
|
| 67 | + <div class="post-footer"> |
| 68 | + <div class="tags"> |
| 69 | + <a href="/tag/technology" class="tag">Technology</a> |
| 70 | + <a href="/tag/programming" class="tag">Programming</a> |
| 71 | + <a href="/tag/web" class="tag">Web</a> |
| 72 | + </div> |
| 73 | + <div class="social-share"> |
| 74 | + <a href="https://twitter.com/share?url=post-{i}" class="share-btn twitter">Share</a> |
| 75 | + <a href="https://facebook.com/sharer?url=post-{i}" class="share-btn facebook">Share</a> |
| 76 | + <a href="https://linkedin.com/share?url=post-{i}" class="share-btn linkedin">Share</a> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + </div> |
| 80 | + </article> |
| 81 | +""" |
| 82 | + |
| 83 | + # Add footer |
| 84 | + html += """ |
| 85 | + </main> |
| 86 | +
|
| 87 | + <aside class="sidebar"> |
| 88 | + <div class="widget"> |
| 89 | + <h3>Popular Posts</h3> |
| 90 | + <ul> |
| 91 | + <li><a href="/popular/1">Popular Post 1</a></li> |
| 92 | + <li><a href="/popular/2">Popular Post 2</a></li> |
| 93 | + <li><a href="/popular/3">Popular Post 3</a></li> |
| 94 | + <li><a href="/popular/4">Popular Post 4</a></li> |
| 95 | + <li><a href="/popular/5">Popular Post 5</a></li> |
| 96 | + </ul> |
| 97 | + </div> |
| 98 | +
|
| 99 | + <div class="widget"> |
| 100 | + <h3>Categories</h3> |
| 101 | + <ul> |
| 102 | + <li><a href="/category/tech">Technology</a></li> |
| 103 | + <li><a href="/category/science">Science</a></li> |
| 104 | + <li><a href="/category/business">Business</a></li> |
| 105 | + <li><a href="/category/lifestyle">Lifestyle</a></li> |
| 106 | + </ul> |
| 107 | + </div> |
| 108 | +
|
| 109 | + <div class="widget ad-widget"> |
| 110 | + <img src="/ads/sidebar-ad.jpg" alt="Advertisement"> |
| 111 | + <a href="https://advertiser.com/product">Learn More</a> |
| 112 | + </div> |
| 113 | + </aside> |
| 114 | +
|
| 115 | + <footer> |
| 116 | + <div class="container"> |
| 117 | + <div class="footer-content"> |
| 118 | + <div class="footer-section"> |
| 119 | + <h4>About Us</h4> |
| 120 | + <p>We are a benchmark site for testing HTML rewriting performance.</p> |
| 121 | + <a href="/about">Read more</a> |
| 122 | + </div> |
| 123 | +
|
| 124 | + <div class="footer-section"> |
| 125 | + <h4>Quick Links</h4> |
| 126 | + <ul> |
| 127 | + <li><a href="/privacy">Privacy Policy</a></li> |
| 128 | + <li><a href="/terms">Terms of Service</a></li> |
| 129 | + <li><a href="/sitemap">Sitemap</a></li> |
| 130 | + <li><a href="https://github.com/example">GitHub</a></li> |
| 131 | + </ul> |
| 132 | + </div> |
| 133 | +
|
| 134 | + <div class="footer-section"> |
| 135 | + <h4>Contact</h4> |
| 136 | + <p>Email: <a href="mailto:[email protected]">[email protected]</a></p> |
| 137 | + <p>Phone: <a href="tel:+1234567890">+1 (234) 567-890</a></p> |
| 138 | + </div> |
| 139 | + </div> |
| 140 | +
|
| 141 | + <div class="footer-bottom"> |
| 142 | + <p>© 2024 Benchmark Site. All rights reserved.</p> |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + </footer> |
| 146 | +
|
| 147 | + <script src="/js/main.js"></script> |
| 148 | + <script src="/js/analytics.js"></script> |
| 149 | +</body> |
| 150 | +</html> |
| 151 | +""" |
| 152 | + |
| 153 | + return html |
| 154 | + |
| 155 | + |
| 156 | +def main(): |
| 157 | + html = generate_html() |
| 158 | + |
| 159 | + with open("default.input", "w") as f: |
| 160 | + f.write(html) |
| 161 | + |
| 162 | + print(f"Generated HTML file: {len(html)} bytes ({len(html) / 1024:.1f} KB)") |
| 163 | + |
| 164 | + |
| 165 | +if __name__ == "__main__": |
| 166 | + main() |
0 commit comments