|
| 1 | +{% comment %} |
| 2 | +Displays another page inside an iframe with source code on the left and the page on the right |
| 3 | + |
| 4 | +For maintainers: Set the url to display using the iframe_content_url variable in the frontmatter. |
| 5 | +{% endcomment %} |
| 6 | + |
| 7 | +<!doctype html> |
| 8 | + |
| 9 | +<html lang="en"> |
| 10 | + <head> |
| 11 | + <title>{{ page.title | escape }} - Docs - Data Commons</title> |
| 12 | + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 13 | + <meta |
| 14 | + name="viewport" |
| 15 | + content="width=device-width, initial-scale=1, shrink-to-fit=no" |
| 16 | + /> |
| 17 | + <link rel="icon" href="/assets/images/favicon.png" type="image/png" /> |
| 18 | + <link |
| 19 | + href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@300;400;500;700" |
| 20 | + rel="stylesheet" |
| 21 | + /> |
| 22 | + <link |
| 23 | + href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@300;400;500;700" |
| 24 | + rel="stylesheet" |
| 25 | + /> |
| 26 | + <link |
| 27 | + href="https://fonts.googleapis.com/css2?family=Public+Sans:wght@600&family=Roboto&family=Material+Icons&display=swap" |
| 28 | + rel="stylesheet" |
| 29 | + /> |
| 30 | + <link href="/assets/css/styles.css" rel="stylesheet" /> |
| 31 | + <link href="/assets/css/code-preview.css" rel="stylesheet" /> |
| 32 | + <!-- Syntax highlighting for code --> |
| 33 | + <link |
| 34 | + rel="stylesheet" |
| 35 | + href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css" |
| 36 | + /> |
| 37 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> |
| 38 | + </head> |
| 39 | + <body> |
| 40 | + <div id="main"> |
| 41 | + {% include header.html %} |
| 42 | + <main id="{{ main_id }}" class="container-fluid"> |
| 43 | + <div id="content"> |
| 44 | + <div id="source-code"> |
| 45 | + <h3>Source Code</h3> |
| 46 | + <pre><code id="code-target" class="language-html">Loading source code...</code></pre> |
| 47 | + </div> |
| 48 | + <div id="preview"> |
| 49 | + <h3>Output</h3> |
| 50 | + <iframe |
| 51 | + id="iframe" |
| 52 | + title="{{ page.title | escape }} Rendered Output" |
| 53 | + src="{{ page.iframe_content_url | escape}}" |
| 54 | + sandbox="allow-scripts allow-popups" |
| 55 | + ></iframe> |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + </main> |
| 59 | + {% include footer.html %} |
| 60 | + </div> |
| 61 | + <script> |
| 62 | + // Fetch the source code for the page and display it in the source code |
| 63 | + // div. |
| 64 | + const fileUrl = "{{ page.iframe_content_url | escape }}"; |
| 65 | + fetch(fileUrl) |
| 66 | + .then((response) => { |
| 67 | + if (!response.ok) throw new Error("Network response was not ok"); |
| 68 | + return response.text(); |
| 69 | + }) |
| 70 | + .then((data) => { |
| 71 | + // Escape the HTML so it doesn't render as actual elements |
| 72 | + const codeTarget = document.getElementById("code-target"); |
| 73 | + codeTarget.textContent = data; |
| 74 | + Prism.highlightElement(codeTarget); |
| 75 | + }) |
| 76 | + .catch((err) => { |
| 77 | + document.getElementById("code-target").textContent = |
| 78 | + "Error loading source: " + err.message; |
| 79 | + }); |
| 80 | + </script> |
| 81 | + {% include scripts.html %} |
| 82 | + </body> |
| 83 | +</html> |
0 commit comments