From 33ea221a1263aef4f89709f68e78be91db03ea74 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 11 Apr 2026 22:41:30 -0400 Subject: [PATCH] Add GitHub corner link to source files Octocat banner in the upper right links to the .md source file for each page. Directory indexes link to index.md, regular pages to their .md, and the homepage falls back to the repo root. Co-Authored-By: Claude Opus 4.6 (1M context) --- engine.py | 2 ++ tuftecms/blueprints/content.py | 2 ++ tuftecms/static/images/github-banner.svg | 5 +++ tuftecms/templates/base.html | 42 ++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 tuftecms/static/images/github-banner.svg diff --git a/engine.py b/engine.py index 5ba40e1..ad8782a 100644 --- a/engine.py +++ b/engine.py @@ -1483,6 +1483,7 @@ async def catch_all(req, resp, *, path): content=content_data["content"], title=content_data["title"], metadata=content_data.get("metadata", {}), + github_file=f"data/{path}.md", reading_time=content_data.get("reading_time"), word_count=content_data.get("word_count"), tags=content_data.get("tags", []), @@ -1553,6 +1554,7 @@ async def catch_all(req, resp, *, path): metadata=content_data.get("metadata", {}), items=items, current_path=f"/{path}", + github_file=f"data/{path}/index.md", current_year=datetime.now().year, reading_time=content_data.get("reading_time"), word_count=content_data.get("word_count"), diff --git a/tuftecms/blueprints/content.py b/tuftecms/blueprints/content.py index 47dcf6a..eb60f61 100644 --- a/tuftecms/blueprints/content.py +++ b/tuftecms/blueprints/content.py @@ -440,6 +440,7 @@ def serve_content(path): metadata=content_data["metadata"], items=items, current_path=f"/{path}", + github_file=f"data/{path}/index.md", current_year=datetime.now().year, reading_time=content_data.get("reading_time"), word_count=content_data.get("word_count"), @@ -581,6 +582,7 @@ def serve_content(path): title=content_data["title"], metadata=content_data["metadata"], current_path=f"/{path}", + github_file=f"data/{path}.md", current_year=datetime.now().year, reading_time=content_data.get("reading_time"), word_count=content_data.get("word_count"), diff --git a/tuftecms/static/images/github-banner.svg b/tuftecms/static/images/github-banner.svg new file mode 100644 index 0000000..c47d9dc --- /dev/null +++ b/tuftecms/static/images/github-banner.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/tuftecms/templates/base.html b/tuftecms/templates/base.html index 298c4c1..d8891c3 100644 --- a/tuftecms/templates/base.html +++ b/tuftecms/templates/base.html @@ -183,6 +183,39 @@ } } + .github-corner { + position: fixed; + top: 0; + right: 0; + z-index: 9998; + opacity: 0.85; + transition: opacity 0.3s ease; + } + + .github-corner:hover { + opacity: 0.8; + } + + .github-corner-img { + width: 80px; + height: 80px; + } + + body.dark-mode .github-corner { + opacity: 0.25; + } + + body.dark-mode .github-corner-img { + filter: invert(1); + } + + @media (max-width: 760px) { + .github-corner-img { + width: 50px; + height: 50px; + } + } + .theme-toggle { position: fixed; bottom: 2rem; @@ -409,6 +442,15 @@
+ {% set github_base = 'https://github.com/kennethreitz/kennethreitz.org' %} + {% if github_file %} + + {% else %} + + {% endif %} + View on GitHub + +