Skip to content

Commit 6866477

Browse files
committed
feat エントリーのアラート表示をalpineからvanillaに変更
1 parent a246431 commit 6866477

File tree

9 files changed

+61
-85
lines changed

9 files changed

+61
-85
lines changed

src/develop/admin/entry/unit/extend.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@
2424
</table>
2525
<!-- END custom_unit_space -->
2626

27+
<!-- BEGIN custom_outline -->
28+
<p>ここに目次(アウトライン)が表示されます</p>
29+
<!-- END custom_outline -->
30+
2731
<!-- BEGIN custom_sample -->
2832
<!-- END custom_sample -->

src/develop/include/calendar/month-side.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h3 class="text-lg font-bold">{year}年{month}月</h3>
1616
<!-- END spacer -->
1717
<!-- BEGIN none -->
1818
<div class="flex items-center justify-center px-0.5 py-1.5 text-sm text-center [&:nth-child(n+6)]:text-red-600">
19-
<span class="flex items-center justify-center w-7 h-7<!-- BEGIN_IF [{day}/eq/%{d}] -->text-indigo-600 font-bold<!-- END_IF -->">{day}</span>
19+
<span class="flex items-center justify-center w-7 h-7<!-- BEGIN_IF [{day}/eq/%{d}] --> text-indigo-600 font-bold<!-- END_IF -->">{day}</span>
2020
</div>
2121
<!-- END none -->
2222
<!-- BEGIN link -->

src/develop/include/entry/body.html

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
<!-- BEGIN pageHeader:veil -->
1111
<header class="text-gray-900">
12-
<p x-show="isOldEntry" class="flex items-center gap-3 w-full mb-8 p-4 rounded-md bg-yellow-50 text-yellow-700 text-sm">
12+
<p id="js-outdated-alert" class="hidden items-center gap-3 w-full mb-8 p-4 rounded-md bg-yellow-50 text-yellow-700 text-sm" data-updated-at="{date#}[date('Y-m-d')]">
1313
<span class="text-yellow-400">
1414
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-5">
1515
<path fill-rule="evenodd" d="M9.401 3.003c1.155-2 4.043-2 5.197 0l7.355 12.748c1.154 2-.29 4.5-2.599 4.5H4.645c-2.309 0-3.752-2.5-2.598-4.5L9.4 3.003ZM12 8.25a.75.75 0 0 1 .75.75v3.75a.75.75 0 0 1-1.5 0V9a.75.75 0 0 1 .75-.75Zm0 8.25a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Z" clip-rule="evenodd" />
1616
</svg>
1717
</span>
18-
<span>この記事は最終更新日から<span x-text="elapsedYears"></span>年以上経過しています。</span>
18+
<span>この記事は最終更新日から<span id="js-outdated-year"></span>年以上経過しています。</span>
1919
</p>
2020
<!-- BEGIN title:veil -->
2121
<h1 class="font-bold text-2xl entry-title"><a href="{titleUrl}">{title}</a></h1>
@@ -54,21 +54,6 @@ <h1 class="font-bold text-2xl entry-title"><a href="{titleUrl}">{title}</a></h1>
5454
data-anchorName="heading-$1"
5555
data-levelLimit="2"
5656
data-exceptClass="js-except">
57-
<details class=" p-4 rounded-md bg-gray-50 [&:not(:has(li))]:hidden [&_svg]:open:-rotate-180" open>
58-
<summary class="flex items-center gap-x-4">
59-
<p class="not-prose font-bold">目次</p>
60-
<p class="not-prose text-indigo-600 cursor-pointer">
61-
<span class="inline-flex items-center gap-x-2">
62-
<span class="label-close inline">非表示</span>
63-
<span class="label-open hidden">表示</span>
64-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColo</svg>r" class="size-3">
65-
<path fill-rule="evenodd" d="M12.53 16.28a.75.75 0 0 1-1.06 0l-7.5-7.5a.75.75 0 0 1 1.06-1.06L12 14.69l6.97-6.97a.75.75 0 1 1 1.06 1.06l-7.5 7.5Z" clip-rule="evenodd" />
66-
</svg>
67-
</span>
68-
</p>
69-
</summary>
70-
<div class="js-outline-yield text-sm"></div>
71-
</details>
7257
@include("/include/unit.html")
7358
</div>
7459
</div>
@@ -90,7 +75,7 @@ <h1 class="font-bold text-2xl entry-title"><a href="{titleUrl}">{title}</a></h1>
9075
<!-- END_IF -->
9176
</div>
9277
<!-- END entry:loop -->
93-
78+
9479
<!-- BEGIN pager:veil -->
9580
<div class="mt-10">
9681
@include("/include/parts/serial-navi.html")

src/develop/include/parts/navigation-pc.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ul class="flex flex-wrap items-center list-none leading-6 [&_a.stay]:border-b-2 [&_a.stay]:border-solid [&_a.stay]:border-indigo-600">
2-
<li class="mx-5 font-medium text-center group">
2+
<li class="mx-4 font-medium text-center group">
33
<a href="%{HOME_URL}" class="js-child-toggle [&.is-active+div]:opacity-100 [&.is-active+div]:pointer-events-auto [&.is-active_span.nav-icon]:-rotate-180 <!-- BEGIN_IF [%{CCD}/neq/contact/_and_/%{ECD}/neq/profile.html] -->stay<!-- END_IF --> flex items-center gap-2 h-14 px-1 hover:opacity-70">
44
<span>Blogs</span>
55
<span class="text-gray-400 transition-transform nav-icon">
@@ -22,12 +22,12 @@ <h2 class="inline-block mr-12 pr-12 py-2 border-r border-gray-200 font-normal">B
2222
</div>
2323
</div>
2424
</li>
25-
<li class="mx-5 font-medium text-center">
25+
<li class="mx-4 font-medium text-center">
2626
<a href="%{HOME_URL}profile.html" class="js-link_match_location-full flex items-center h-14 px-1 hover:opacity-70">
2727
<span>Profile</span>
2828
</a>
2929
</li>
30-
<li class="ml-5 font-medium text-center">
30+
<li class="ml-4 font-medium text-center">
3131
<a href="%{HOME_URL}contact/" class="js-link_match_location-category flex items-center h-14 px-1 hover:opacity-70">
3232
<span>Contact</span>
3333
</a>

src/develop/include/unit/extend.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,23 @@
66
<hr class="my-8">
77
<!-- END unit#custom_hr -->
88

9+
<!-- BEGIN unit#custom_outline -->
10+
<details class="p-4 rounded-md bg-gray-50 [&:not(:has(li))]:hidden [&_span.label-open]:open:hidden [&:not([open])_span.label-close]:hidden [&_svg]:open:-rotate-180" open>
11+
<summary class="flex items-center gap-x-4">
12+
<p class="not-prose font-bold">目次</p>
13+
<p class="not-prose text-indigo-600 cursor-pointer">
14+
<span class="inline-flex items-center gap-x-1 text-sm">
15+
<span class="label-close">非表示</span>
16+
<span class="label-open">表示</span>
17+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-3 transition-transform">
18+
<path fill-rule="evenodd" d="M12.53 16.28a.75.75 0 0 1-1.06 0l-7.5-7.5a.75.75 0 0 1 1.06-1.06L12 14.69l6.97-6.97a.75.75 0 1 1 1.06 1.06l-7.5 7.5Z" clip-rule="evenodd" />
19+
</svg>
20+
</span>
21+
</p>
22+
</summary>
23+
<div class="js-outline-yield text-sm"></div>
24+
</details>
25+
<!-- END unit#custom_outline -->
26+
927
<!-- BEGIN unit#custom_sample -->
1028
<!-- END unit#custom_sample -->

src/develop/src/js/alpinejs/oldEntryAlert.component.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/develop/src/js/alpinejs/sideMenu.component.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 「この記事は最終更新日から年以上経過しています」の警告表示
3+
*/
4+
5+
export default () => {
6+
function _checkOutdated(element) {
7+
const updatedAt = new Date(element.dataset.updatedAt);
8+
const now = new Date();
9+
const diff = now.getTime() - updatedAt.getTime();
10+
const diffDays = diff / (1000 * 60 * 60 * 24);
11+
return [diffDays > 365, Math.floor(diffDays / 365)];
12+
}
13+
14+
const outdatedAlert = document.getElementById('js-outdated-alert');
15+
const outdatedYear = document.getElementById('js-outdated-year');
16+
17+
if(outdatedAlert && _checkOutdated(outdatedAlert)[0]) {
18+
outdatedYear.textContent = _checkOutdated(outdatedAlert)[1];
19+
outdatedAlert.classList.remove('hidden');
20+
outdatedAlert.classList.add('flex');
21+
}
22+
};

src/develop/src/js/main.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import 'vite/modulepreload-polyfill'
33
// import collapse from '@alpinejs/collapse';
44
import htmx from 'htmx.org';
55
import domContentLoaded from 'dom-content-loaded';
6-
// import Dispatcher from 'a-dispatcher';
6+
import Dispatcher from 'a-dispatcher';
77
import fonts from './fonts';
8+
import entryOutdated from './entryOutdated';
89
import scrollToInvalid from './scrollToInvalid';
910
import './lib/polyfill';
1011
import {
@@ -145,7 +146,7 @@ async function main() {
145146
/**
146147
* Dispatcher
147148
*/
148-
// const dispatcher = new Dispatcher();
149+
const dispatcher = new Dispatcher();
149150

150151
// ダイナミックインポート
151152
// dispatcher.addRoute('^/app.html$', async () => {
@@ -155,8 +156,9 @@ async function main() {
155156

156157
// 通常のバンドル
157158
// dispatcher.addRoute('^/example/$', examplePage);
159+
dispatcher.addRoute('.html$', entryOutdated);
158160

159-
// dispatcher.run(window.location.pathname);
161+
dispatcher.run(window.location.pathname);
160162

161163
/**
162164
* Content Ready
@@ -165,18 +167,18 @@ async function main() {
165167
/* PC nav */
166168
const childToggle = document.querySelectorAll('.js-child-toggle');
167169
childToggle && childToggle.forEach((toggle) => {
168-
toggle.addEventListener('click', (e) => {
169-
e.preventDefault();
170-
const _self = e.currentTarget;
170+
toggle.addEventListener('click', (event) => {
171+
event.preventDefault();
172+
const _self = event.currentTarget;
171173
_self.classList.toggle('is-active');
172174
});
173175
});
174176

175177
/* SP menu */
176178
const menu = document.querySelector('.js-menu');
177179
const menuToggle = document.querySelector('.js-menu-toggle');
178-
menuToggle && menuToggle.addEventListener('click', (e) => {
179-
const _self = e.currentTarget;
180+
menuToggle && menuToggle.addEventListener('click', (event) => {
181+
const _self = event.currentTarget;
180182
_self.classList.toggle('is-active');
181183
menu.classList.toggle('is-active');
182184
});

0 commit comments

Comments
 (0)