Skip to content

Commit 3bd864c

Browse files
committed
pushState transition
1 parent cf55910 commit 3bd864c

File tree

15 files changed

+159
-100
lines changed

15 files changed

+159
-100
lines changed

assets/css/main.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
/* Swup page transition */
6+
html.is-changing .transition-fade {
7+
transition: opacity 0.2s ease;
8+
opacity: 1;
9+
}
10+
html.is-animating .transition-fade {
11+
opacity: 0;
12+
}
13+
14+
/* Hide particles/gradient on light theme */
15+
.gradient-overlay,
16+
.particles {
17+
transition: opacity 0.5s ease;
18+
}
19+
[data-theme="light"] .gradient-overlay,
20+
[data-theme="light"] .particles {
21+
opacity: 0 !important;
22+
}

assets/js/app.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Swup from 'swup';
2+
import SwupHeadPlugin from '@swup/head-plugin';
3+
import SwupScriptsPlugin from '@swup/scripts-plugin';
4+
5+
const swup = new Swup({
6+
containers: ['#site-header', 'main'],
7+
plugins: [
8+
new SwupHeadPlugin(),
9+
new SwupScriptsPlugin({ head: false, body: true, optin: true })
10+
]
11+
});
12+
13+
// テーマ切り替え(フェードアウト開始時にdata-theme変更 → CSS transitionが走る)
14+
swup.hooks.on('animation:out:start', (visit) => {
15+
document.body.dataset.theme = visit.to.url === '/' ? 'dark' : 'light';
16+
});
17+
18+
// コンテンツ差し替え後、レイアウト完了を待ってからフェードイン開始
19+
swup.hooks.before('animation:in:start', () => {
20+
return new Promise(resolve => {
21+
requestAnimationFrame(() => requestAnimationFrame(resolve));
22+
});
23+
});
24+
25+
// スクリプトcleanup(ページ離脱時にタイマー・リスナー除去)
26+
swup.hooks.on('visit:start', () => {
27+
if (window.__pageCleanup) {
28+
window.__pageCleanup();
29+
window.__pageCleanup = null;
30+
}
31+
});
32+
33+
// モバイルメニュー(イベントデリゲーションで差し替え後も動作)
34+
document.addEventListener('click', (e) => {
35+
if (e.target.closest('#mobile-menu-button')) {
36+
const menu = document.getElementById('mobile-menu');
37+
if (menu) menu.classList.toggle('hidden');
38+
}
39+
});

layouts/_default/baseof.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787
</style>
8888
{{ block "head" . }}{{ end }}
8989
</head>
90-
<body class="bg-black text-gray-100 flex flex-col min-h-screen">
90+
<body class="bg-white dark:bg-black text-gray-900 dark:text-gray-100 transition-colors duration-500 flex flex-col min-h-screen"
91+
data-theme="{{ if .IsHome }}dark{{ else }}light{{ end }}">
9192
<div class="gradient-overlay"></div>
9293
<div class="particles" id="particles"></div>
9394
<script>
@@ -131,9 +132,12 @@
131132
})();
132133
</script>
133134
{{ block "header" . }}{{ partial "header.html" . }}{{ end }}
134-
<main class="flex-grow flex flex-col relative z-10">
135+
<main class="flex-grow flex flex-col relative z-10 transition-fade">
135136
{{ block "main" . }}{{ end }}
136137
</main>
137138
{{ block "footer" . }}{{ partial "footer.html" . }}{{ end }}
139+
{{ $js := resources.Get "js/app.js" | js.Build }}
140+
{{ if hugo.IsProduction }}{{ $js = $js | fingerprint }}{{ end }}
141+
<script src="{{ $js.RelPermalink }}" type="module" data-swup-ignore-script></script>
138142
</body>
139143
</html>

layouts/_default/list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{{ define "main" }}
22
<div class="max-w-4xl mx-auto px-6 py-16">
3-
<h1 class="text-4xl md:text-5xl font-bold mb-8 text-gray-100">{{ .Title }}</h1>
3+
<h1 class="text-4xl md:text-5xl font-bold mb-8 text-gray-900 dark:text-gray-100">{{ .Title }}</h1>
44
{{ .Content }}
55
<ul class="space-y-3">
66
{{ range .Pages }}
77
<li>
8-
<a href="{{ .RelPermalink }}" class="text-blue-400 hover:text-blue-300 transition">{{ .Title }}</a>
8+
<a href="{{ .RelPermalink }}" class="text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 transition">{{ .Title }}</a>
99
</li>
1010
{{ end }}
1111
</ul>

layouts/_default/single.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{ define "main" }}
22
<article class="max-w-4xl mx-auto px-6 py-16">
3-
<h1 class="text-4xl md:text-5xl font-bold mb-8 text-gray-100">{{ .Title }}</h1>
4-
<div class="prose prose-lg prose-invert max-w-none">
3+
<h1 class="text-4xl md:text-5xl font-bold mb-8 text-gray-900 dark:text-gray-100">{{ .Title }}</h1>
4+
<div class="prose prose-lg dark:prose-invert max-w-none">
55
{{ .Content }}
66
</div>
77
</article>

layouts/blog/list.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{{ define "main" }}
2-
<div class="py-16 bg-white/5">
2+
<div class="py-16 bg-gray-50 dark:bg-white/5">
33
<div class="max-w-4xl mx-auto px-6">
4-
<h1 class="text-4xl md:text-5xl font-bold text-gray-100">{{ .Title }}</h1>
4+
<h1 class="text-4xl md:text-5xl font-bold text-gray-900 dark:text-gray-100">{{ .Title }}</h1>
55
</div>
66
</div>
77

88
<div class="max-w-4xl w-full mx-auto py-16 px-6">
99
<div class="space-y-8">
1010
{{ range .Pages }}
11-
<article class="border-b border-white/10 pb-8">
11+
<article class="border-b border-gray-200 dark:border-white/10 pb-8">
1212
<h2 class="text-2xl md:text-3xl font-bold mb-3">
13-
<a href="{{ .RelPermalink }}" class="text-gray-100 hover:text-white transition">{{ .Title }}</a>
13+
<a href="{{ .RelPermalink }}" class="text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-white transition">{{ .Title }}</a>
1414
</h2>
1515
<div class="text-sm text-gray-500">
1616
{{ .Date.Format "2006年1月2日" }}{{ if .Params.author }} {{ .Params.author }}{{ end }}

layouts/blog/single.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{{ define "main" }}
22
<div class="max-w-4xl mx-auto px-6 py-16">
33
<div class="mb-8">
4-
<a href="/blog/" class="text-sm text-gray-400 hover:text-white transition">← ブログ一覧に戻る</a>
4+
<a href="/blog/" class="text-sm text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition">← ブログ一覧に戻る</a>
55
</div>
66

77
<header class="mb-12">
8-
<h1 class="text-4xl md:text-5xl font-bold mb-4 text-gray-100">{{ .Title }}</h1>
8+
<h1 class="text-4xl md:text-5xl font-bold mb-4 text-gray-900 dark:text-gray-100">{{ .Title }}</h1>
99
<div class="text-sm text-gray-500">
1010
{{ .Date.Format "2006年1月2日" }}{{ if .Params.author }} {{ .Params.author }}{{ end }}
1111
</div>
1212
</header>
1313

14-
<div class="prose prose-lg prose-invert max-w-none">
14+
<div class="prose prose-lg dark:prose-invert max-w-none">
1515
{{ .Content }}
1616
</div>
1717
</div>

layouts/business/list.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{{ define "main" }}
22

3-
<div class="py-16 bg-white/5">
3+
<div class="py-16 bg-gray-50 dark:bg-white/5">
44
<div class="max-w-4xl mx-auto px-6">
5-
<h1 class="text-4xl md:text-5xl font-bold text-gray-100">{{ .Title }}</h1>
5+
<h1 class="text-4xl md:text-5xl font-bold text-gray-900 dark:text-gray-100">{{ .Title }}</h1>
66
</div>
77
</div>
88

99
<section class="max-w-4xl mx-auto py-16 px-6">
10-
<div class="prose prose-lg prose-invert max-w-none">
10+
<div class="prose prose-lg dark:prose-invert max-w-none">
1111
{{ .Content }}
1212
</div>
1313
</section>

0 commit comments

Comments
 (0)