HTMLを綺麗に

This commit is contained in:
2025-11-08 18:12:08 +09:00
parent adaf7622ae
commit 8513c530f5
7 changed files with 114 additions and 103 deletions

View File

@@ -42,7 +42,7 @@ class Template {
*/
public function addCss(string $name): void {
$this->custCss[] =
'<link rel="stylesheet" type="text/css" href="/static/style-'.$name.'.css" />';
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/style-{$name}.css\" />\n";
$this->assign('custCss', $this->custCss);
}

View File

@@ -1,16 +1,27 @@
{@ include(common/header) @}
{@ include(common/search) @}
<div class="news-article">
{@ if (isset($meta->thumbnail) && $meta->thumbnail != '') @}
{@ if (isset($meta->thumbnail) && $meta->thumbnail != '') @}
<div class="thumbnail{{ isset($meta->thumborient) && $meta->thumborient != 'center' ? ' '.$meta->thumborient : '' }}">
<img src="/static/article/{{ $meta->thumbnail }}" alt="" />
</div>
{@ endif @}
{@ endif @}
<div class="meta">
<div class="meta-date">{{ $meta->date }}</div>
<div class="meta-author">{{ $meta->author }}</div>
{@ if (isset($meta->category) && !empty($meta->category) && $meta->category[0] !== '') @}
{@ foreach ($meta->category as $cat) @}
<div class="meta-category">
{{ $cat }}
</div>
{@ endforeach @}
{@ endif @}
</div>
<h1 class="title">{{{ $meta->title }}}</h1>
{{{ $article }}}
{{{ $article }}}
</div>
{@ include(common/footer) @}

View File

@@ -5,4 +5,4 @@
</footer>
</div>
</body>
</html>
</html>

View File

@@ -7,15 +7,15 @@
<title>{{ SITEINFO['title'] }}: {{ $pagetit }}</title>
<link rel="stylesheet" type="text/css" href="/static/style.css" />
{@ if (isset($custCss) && !empty($custCss) && !is_bool($custCss)) @}
{@ foreach ($custCss as $css) @}
{@ foreach ($custCss as $css) @}
{{{ $css }}}
{@ endforeach @}
{@ endforeach @}
{@ endif @}
{@ if (isset($meta)) @}
<meta name="author" content="{{ $meta->author }}" />
{@ if (isset($meta->thumbnail)) @}
{@ if (isset($meta->thumbnail)) @}
<meta name="thumbnail" content="/static/{{ $meta->thumbnail }}" />
{@ endif @}
{@ endif @}
{@ endif @}
<meta name="description" content="{{ $description }}" />
<meta name="keywords" content="{{ SITEINFO['tags'].',' }}{@ if (isset($meta)) @}{@ foreach ($meta->category as $cat) @}{{ $cat.',' }}{@ endforeach @}{@ endif @}" />
@@ -24,23 +24,23 @@
<meta property="og:description" content="{{ $description }}" />
<meta property="og:type" content="{{ isset($meta) && isset($meta->thumbnail) ? 'article' : 'website' }}" />
<meta property="og:url" content="{{ isset($_SERVER['REQUEST_URI']) ? 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] : 'https://'.$_SERVER['HTTP_HOST'] }}" />
{@ if (isset($meta) && isset($meta->thumbnail)) @}
{@ if (isset($meta) && isset($meta->thumbnail)) @}
<meta property="og:image" content="https://{{ $_SERVER['HTTP_HOST'] }}/static/article/{{ $meta->thumbnail }}" />
{@ endif @}
{@ endif @}
{@ if (TWITTER_HANDLE != '') @}
{@ if (TWITTER_HANDLE != '') @}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:card" content="{{ TWITTER_HANDLE }}" />
<meta name="twitter:title" content="{{ SITEINFO['title'] }}: {{ $pagetit }}" />
<meta name="twitter:url" content="{{ isset($_SERVER['REQUEST_URI']) ? 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] : 'https://'.$_SERVER['HTTP_HOST'] }}" />
<meta name="twitter:description" content="{{ $description }}" />
{@ if (isset($meta) && isset($meta->thumbnail)) @}
{@ if (isset($meta) && isset($meta->thumbnail)) @}
<meta name="twitter:image:src" content="https://{{ $_SERVER['HTTP_HOST'] }}/static/article/{{ $meta->thumbnail }}" />
{@ endif @}
{@ endif @}
{@ if (ATOM_ENABLED) @}
{@ endif @}
{@ endif @}
{@ if (ATOM_ENABLED) @}
<link rel="alternate" type="application/atom+xml" title="{{ SITEINFO['title'] }} feed" href="/blog.atom" />
{@ endif @}
{@ endif @}
</head>
<body>
<div class="container">
@@ -50,10 +50,10 @@
</div>
<nav>
{@ foreach ($menu as $m) @}
{@ if ($m['show']) @}
{@ if ($m['show']) @}
<a class="{{ $m['class'] }}{{ $curPage == $m['page'] ? ' active' : '' }}" href="{{ $m['href'] }}">{{ $m['text'] }}</a>
{@ endif @}
{@ endif @}
{@ endforeach @}
</nav>
</header>
<main>
<main>

View File

@@ -1,23 +1,21 @@
<article class="news-card">
{@ if (isset($post['thumbnail']) && $post['thumbnail'] != '') @}
<div class="news-image">
<a href="/{{ $section }}/{{ $post['slug'] }}">
<img src="/static/article/{{ $post['thumbnail'] }}" alt="{{ $post['title'] }}" loading="lazy" />
</a>
<article class="news-card">
{@ if (isset($post['thumbnail']) && $post['thumbnail'] != '') @}
<div class="news-image">
<a href="/{{ $section }}/{{ $post['slug'] }}">
<img src="/static/article/{{ $post['thumbnail'] }}" alt="{{ $post['title'] }}" loading="lazy" />
</a>
</div>
{@ endif @}
<div class="news-content">
<div class="news-meta">
<span class="news-date">{{ $post['date'] }}</span>
{@ foreach ($post['category'] as $cat) @}
<span class="news-category">{{ $cat }}</span>
{@ endforeach @}
</div>
{@ endif @}
<div class="news-content">
<div class="news-meta">
<span class="news-date">{{ $post['date'] }}</span>
{# {@ if (isset($post['category']) && is_array($post['category'])) @} #}
{@ foreach ($post['category'] as $cat) @}
<span class="news-category">{{ $cat }}</span>
{@ endforeach @}
{# {@ endif @} #}
</div>
<h2 class="news-title">
<a href="/{{ $section }}/{{ $post['slug'] }}{{{ isset($_GET['q']) ? '?q='.urlencode($_GET['q']) : '' }}}">{{{ $post['title'] }}}</a>
</h2>
<p class="news-preview">{{{ $post['preview'] }}}</p>
</div>
</article>
<h2 class="news-title">
<a href="/{{ $section }}/{{ $post['slug'] }}{{{ isset($_GET['q']) ? '?q='.urlencode($_GET['q']) : '' }}}">{{{ $post['title'] }}}</a>
</h2>
<p class="news-preview">{{{ $post['preview'] }}}</p>
</div>
</article>

View File

@@ -1,71 +1,71 @@
{@ if (isset($totalPages) && $totalPages > 1) @}
{@ if (isset($totalPages) && $totalPages > 1) @}
<div class="pagination">
{# 検索クエリがある場合はページネーションリンクに含める #}
{$ $queryParams = [] $}
{@ if (isset($_GET['q']) && !empty($_GET['q'])) @}
{$ $queryParams['q'] = $_GET['q'] $}
{@ endif @}
{# 検索クエリがある場合はページネーションリンクに含める #}
{$ $queryParams = [] $}
{@ if (isset($_GET['q']) && !empty($_GET['q'])) @}
{$ $queryParams['q'] = $_GET['q'] $}
{@ endif @}
{# 前のページへのリンク #}
{@ if (isset($currentPage) && $currentPage > 1) @}
{$ $prevParams = $queryParams $}
{$ $prevParams['page'] = $currentPage - 1 $}
{$ $prevQueryString = http_build_query($prevParams) $}
{# 前のページへのリンク #}
{@ if (isset($currentPage) && $currentPage > 1) @}
{$ $prevParams = $queryParams $}
{$ $prevParams['page'] = $currentPage - 1 $}
{$ $prevQueryString = http_build_query($prevParams) $}
<a href="?{{ $prevQueryString }}" class="page-link">&laquo; 前</a>
{@ endif @}
{@ endif @}
{# 表示するページ番号の範囲を計算(モバイル対応の為) #}
{# 最大表示ページ数 #}
{$ $rangeSize = 2 $}
{$ $startPage = max(1, $currentPage - floor($rangeSize / 2)) $}
{$ $endPage = min($totalPages, $startPage + $rangeSize - 1) $}
{# 表示するページ番号の範囲を計算(モバイル対応の為) #}
{# 最大表示ページ数 #}
{$ $rangeSize = 2 $}
{$ $startPage = max(1, $currentPage - floor($rangeSize / 2)) $}
{$ $endPage = min($totalPages, $startPage + $rangeSize - 1) $}
{# 範囲の調整 #}
{@ if ($endPage - $startPage + 1 < $rangeSize && $startPage > 1) @}
{$ $startPage = max(1, $endPage - $rangeSize + 1) $}
{@ endif @}
{# 範囲の調整 #}
{@ if ($endPage - $startPage + 1 < $rangeSize && $startPage > 1) @}
{$ $startPage = max(1, $endPage - $rangeSize + 1) $}
{@ endif @}
{# 最初のページへのリンク(多数のページがある場合) #}
{@ if ($startPage > 1) @}
{$ $firstParams = $queryParams $}
{$ $firstParams['page'] = 1 $}
{$ $firstQueryString = http_build_query($firstParams) $}
{# 最初のページへのリンク(多数のページがある場合) #}
{@ if ($startPage > 1) @}
{$ $firstParams = $queryParams $}
{$ $firstParams['page'] = 1 $}
{$ $firstQueryString = http_build_query($firstParams) $}
<a href="?{{ $firstQueryString }}" class="page-link">1</a>
{@ if ($startPage > 2) @}
{@ if ($startPage > 2) @}
<span class="page-ellipsis">...</span>
{@ endif @}
{@ endif @}
{@ endif @}
{@ endif @}
{@ for ($i = $startPage; $i <= $endPage; $i++) @}
{$ $pageParams = $queryParams $}
{$ $pageParams['page'] = $i $}
{$ $pageQueryString = http_build_query($pageParams) $}
{@ for ($i = $startPage; $i <= $endPage; $i++) @}
{$ $pageParams = $queryParams $}
{$ $pageParams['page'] = $i $}
{$ $pageQueryString = http_build_query($pageParams) $}
{@ if ($i == $currentPage) @}
<span class="page-current" aria-current="page">{{ $i }}</span>
{@ else @}
<a href="?{{ $pageQueryString }}" class="page-link">{{ $i }}</a>
{@ endif @}
{@ endfor @}
{@ if ($i == $currentPage) @}
<span class="page-current" aria-current="page">{{ $i }}</span>
{@ else @}
<a href="?{{ $pageQueryString }}" class="page-link">{{ $i }}</a>
{@ endif @}
{@ endfor @}
{@ if ($endPage < $totalPages) @}
{# 最後のページへのリンク(多数のページがある場合) #}
{$ $lastParams = $queryParams $}
{$ $lastParams['page'] = $totalPages $}
{$ $lastQueryString = http_build_query($lastParams) $}
{@ if ($endPage < $totalPages - 1) @}
<span class="page-ellipsis">...</span>
{@ endif @}
<a href="?{{ $lastQueryString }}" class="page-link">{{ $totalPages }}</a>
{@ endif @}
{@ if ($endPage < $totalPages) @}
{# 最後のページへのリンク(多数のページがある場合) #}
{$ $lastParams = $queryParams $}
{$ $lastParams['page'] = $totalPages $}
{$ $lastQueryString = http_build_query($lastParams) $}
{@ if ($endPage < $totalPages - 1) @}
<span class="page-ellipsis">...</span>
{@ endif @}
<a href="?{{ $lastQueryString }}" class="page-link">{{ $totalPages }}</a>
{@ endif @}
{# 次のページへのリンク #}
{@ if (isset($currentPage) && $currentPage < $totalPages) @}
{$ $nextParams = $queryParams $}
{$ $nextParams['page'] = $currentPage + 1 $}
{$ $nextQueryString = http_build_query($nextParams) $}
<a href="?{{ $nextQueryString }}" class="page-link">次 &raquo;</a>
{@ endif @}
{# 次のページへのリンク #}
{@ if (isset($currentPage) && $currentPage < $totalPages) @}
{$ $nextParams = $queryParams $}
{$ $nextParams['page'] = $currentPage + 1 $}
{$ $nextQueryString = http_build_query($nextParams) $}
<a href="?{{ $nextQueryString }}" class="page-link">次 &raquo;</a>
{@ endif @}
</div>
{@ endif @}
{@ endif @}

View File

@@ -1,9 +1,11 @@
{@ include(common/header) @}
{@ include(common/search) @}
<div class="news-grid">
{@ foreach ($posts as $post) @}
{@ include(common/newscard) @}
{@ endforeach @}
{@ foreach ($posts as $post) @}
{@ include(common/newscard) @}
{@ endforeach @}
</div>
{@ include(common/pagination) @}
{@ include(common/pagination) @}
{@ include(common/footer) @}