From 9f779b87ae538345f742f539464442c14ad0505d Mon Sep 17 00:00:00 2001 From: yktsnet Date: Thu, 19 Nov 2026 09:27:42 +0000 Subject: [PATCH] feat: Fit the HTML file iframe to its content height MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HTML ファイルページの iframe は高さ 80vh 固定で中を送っていたため、スマホでは中と外のスクロールが取り合い、外側は iframe の外の端でしか送れなかった。 - srcdoc の末尾に、中身の高さを postMessage で親へ送る HTML_FIT_SCRIPT を足す(sandbox は allow-scripts のみのまま) - FILE_SCRIPT が送り元の iframe を確かめ、受け取った高さに伸ばす。上限は 50000px。100vh に余白を足した中身のように、同じ幅で伸び続ける場合は止める - JavaScript が無いときと高さが届くまでは、これまでどおり 80vh - 保証台帳と README を更新 Claude-Session: https://claude.ai/code/session_01V1Zinm1dJGihd2ZdPZCzjM --- README.en.md | 2 +- README.md | 2 +- codeview/layout.py | 22 ++++++++++++++++++++++ codeview/render.py | 20 ++++++++++++++++++-- codeview/style.py | 2 +- docs/guarantees/build.md | 3 ++- tests/test_build.py | 6 +++++- 7 files changed, 50 insertions(+), 7 deletions(-) diff --git a/README.en.md b/README.en.md index 1472c86..3ac73a9 100644 --- a/README.en.md +++ b/README.en.md @@ -7,7 +7,7 @@ Turns your local git repositories and their GitHub issues into static HTML, and serves them through Cloudflare Pages + Access as a code browser only you can read. - **Read every repo in one place**: your local repos listed by root, with the code highlighted -- **HTML documents render in place**: a `.html` file in a repo is shown rendered, with its source on the same page. Its scripts run in a sandbox, cut off from codeview +- **HTML documents render in place**: a `.html` file in a repo is shown rendered, with its source on the same page. Its scripts run in a sandbox, cut off from codeview. The frame grows to fit its content, so a phone scrolls the page as one - **All issues in one place too**: open issues from every repo in a single list - **Multiple GitHub accounts**: pull issues from separate accounts, such as personal and work, and keep them apart - **Light on a phone**: static HTML that reads without JavaScript, so it opens quickly while you're away diff --git a/README.md b/README.md index 54de1a7..98310d3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ 手元の git リポジトリ群と、その GitHub Issue を静的 HTML にまとめ、自分だけが読めるコードブラウザとして Cloudflare Pages + Access で配信する。 - **全リポを1か所で読める**: 手元のリポを置き場ごとに並べ、コードをハイライトして読める -- **HTML の資料もそのまま読める**: リポに置いた `.html` は描画した結果を出し、ソースも同じページで読める。中のスクリプトは sandbox で codeview から切り離す +- **HTML の資料もそのまま読める**: リポに置いた `.html` は描画した結果を出し、ソースも同じページで読める。中のスクリプトは sandbox で codeview から切り離す。iframe は中身の高さまで伸びるので、スマホでもスクロールが1本で済む - **Issue も1か所にまとまる**: 全リポの未消化の Issue を1つの一覧にする - **GitHub の複数アカウントに対応**: 個人用と仕事用のように、別々のアカウントの Issue を分けて取り込める - **スマホで軽い**: JavaScript なしでも読める静的 HTML なので、外出先でもすぐ開ける diff --git a/codeview/layout.py b/codeview/layout.py index 6c8f948..8ebc542 100644 --- a/codeview/layout.py +++ b/codeview/layout.py @@ -222,6 +222,28 @@ def cell(item, cls, arrow_l, arrow_r): if (mark(n)) history.replaceState(null, '', '#ln-' + n); }); + // iframe を中身の高さまで伸ばし、スクロールを外側の1本にまとめる。届くまでは CSS の 80vh のまま + const frames = [...document.querySelectorAll('iframe.htmlview')]; + if (frames.length) { + const CAP = 50000; + const state = new Map(); + window.addEventListener('message', (ev) => { + const f = frames.find((x) => x.contentWindow === ev.source); + const h = ev.data && ev.data.codeviewHeight; + if (!f || typeof h !== 'number' || !isFinite(h) || h <= 0) return; + // 100vh に余白を足した中身は、伸ばすたびに同じ幅だけ伸び返す。同じ伸びが続いたら止める + const s = state.get(f) || { cur: f.offsetHeight, step: 0, same: 0, frozen: false }; + if (s.frozen) return; + const step = h - s.cur; + s.same = step > 0 && step === s.step ? s.same + 1 : 0; + s.step = step; + if (s.same >= 2) { s.frozen = true; state.set(f, s); return; } + s.cur = Math.min(h, CAP); + state.set(f, s); + f.style.height = s.cur + 'px'; + }); + } + const wrap = document.getElementById('wrap'); if (wrap) { const KEY = 'codeview.wrap'; diff --git a/codeview/render.py b/codeview/render.py index 4a1de71..09f0245 100644 --- a/codeview/render.py +++ b/codeview/render.py @@ -81,18 +81,34 @@ def is_html(path: str) -> bool: return path.lower().endswith((".html", ".htm")) +# sandbox の外からは中身の高さを測れないので、中から親へ送らせる。送るのは数値だけ。 +# 末尾に足すので、閉じていない