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 の外からは中身の高さを測れないので、中から親へ送らせる。送るのは数値だけ。 +# 末尾に足すので、閉じていない