Make Favoritter installable as a Progressive Web App with offline
static asset caching and Web Share Target API for Android.
New files:
- internal/handler/pwa.go: handlers for manifest, service worker,
and share target
- web/static/sw.js: service worker (cache-first static, network-first
HTML) with {{BASE_PATH}} placeholder for subpath deployments
- web/static/icons/: placeholder PWA icons (192, 512, 512-maskable)
Key design decisions:
- Share target uses GET (not POST) to avoid CSRF token issues — Android
apps cannot provide CSRF tokens
- Manifest is generated dynamically to inject BasePath into start_url,
scope, icon paths, and share_target action
- Service worker served at /sw.js with Cache-Control: no-cache and
BasePath injected via string replacement
- handleShare extracts URLs from Android's "text" field as fallback
(many apps put the URL there instead of "url")
- handleFaveNew replaced with handleFaveNewPreFill that reads url,
description, notes from query params (enables share + bookmarklets)
- SW registration in app.js reads base-path from <meta> tag (CSP-safe)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
67 lines
2.7 KiB
HTML
67 lines
2.7 KiB
HTML
{{define "base.html"}}<!DOCTYPE html>
|
|
<html lang="nb">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>{{if .Title}}{{.Title}} — {{end}}{{.SiteName}}</title>
|
|
<link rel="stylesheet" href="{{basePath}}/static/vendor/pico.min.css">
|
|
<link rel="stylesheet" href="{{basePath}}/static/css/style.css">
|
|
<meta name="theme-color" content="#1095c1">
|
|
<link rel="manifest" href="{{basePath}}/manifest.json">
|
|
<link rel="icon" type="image/png" sizes="192x192" href="{{basePath}}/static/icons/icon-192.png">
|
|
<link rel="apple-touch-icon" href="{{basePath}}/static/icons/icon-192.png">
|
|
<meta name="base-path" content="{{basePath}}">
|
|
{{block "head" .}}{{end}}
|
|
</head>
|
|
<body>
|
|
<a href="#main-content" class="skip-link">Hopp til hovedinnhold</a>
|
|
|
|
<header class="container">
|
|
<nav aria-label="Hovednavigasjon">
|
|
<ul>
|
|
<li><a href="{{basePath}}/" class="site-title"><strong>{{.SiteName}}</strong></a></li>
|
|
</ul>
|
|
<ul>
|
|
{{if .User}}
|
|
<li><a href="{{basePath}}/faves">Mine favoritter</a></li>
|
|
<li><a href="{{basePath}}/u/{{.User.Username}}">Profil</a></li>
|
|
{{if .User.IsAdmin}}
|
|
<li><a href="{{basePath}}/admin">Admin</a></li>
|
|
{{end}}
|
|
<li>
|
|
<form method="POST" action="{{basePath}}/logout" class="inline-form">
|
|
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
|
|
<button type="submit" class="outline secondary nav-button">Logg ut</button>
|
|
</form>
|
|
</li>
|
|
{{else}}
|
|
<li><a href="{{basePath}}/login">Logg inn</a></li>
|
|
<li><a href="{{basePath}}/signup">Registrer</a></li>
|
|
{{end}}
|
|
</ul>
|
|
</nav>
|
|
</header>
|
|
|
|
<main id="main-content" class="container">
|
|
{{if .Flash}}
|
|
<div class="flash flash-{{.FlashType}}" role="alert">
|
|
{{.Flash}}
|
|
</div>
|
|
{{end}}
|
|
{{block "content" .}}{{end}}
|
|
</main>
|
|
|
|
<footer class="container">
|
|
<hr>
|
|
<p>
|
|
<small>
|
|
Drevet av <a href="https://kode.naiv.no/olemd/favoritter" target="_blank" rel="noopener">Favoritter</a>
|
|
— fri programvare under <a href="https://www.gnu.org/licenses/agpl-3.0.html" target="_blank" rel="noopener" hreflang="en">AGPL-3.0</a>
|
|
</small>
|
|
</p>
|
|
</footer>
|
|
|
|
<script src="{{basePath}}/static/vendor/htmx.min.js"></script>
|
|
<script src="{{basePath}}/static/js/app.js"></script>
|
|
</body>
|
|
</html>{{end}}
|