Files
laralog/themes/sablog/views/show.blade.php
T
ak 8f1ff6e3f9 feat: 外链中转 /go——点击统计 + 拦截 + 隐藏真实链接
- redirects 表 + UrlRedirector:go_url() 站外链接改写为 /go/{hash}(确定性 hash、同 URL 复用、并发安全、缓存)
- /go/{hash} 302 跳转 + 点击计数 + 最后点击时间;停用状态 410(二次拦截);后台「外链中转」资源可查看点击量/启停/删除
- 接入点:正文外链(渲染器统一改写)、评论正文自动链接(comment_body)、评论作者网址、友链(侧边栏+友链页);站内/相对/mailto/tel/锚点不中转
- 测试 6 个(改写/计数/拦截/复用/渲染/评论正文);README 补充
2026-08-13 01:28:10 +08:00

108 lines
4.9 KiB
PHP

@php
$pageTitle = $post->title.' - '.$siteName;
$pageDescription = Str::limit(strip_tags($post->excerpt_or_fallback), 150);
$pageKeywords = $post->keywords ?: ($post->tags->pluck('name')->implode(','));
@endphp
@include('partials.head')
<body>
@include('partials.header')
<div id="page">
<main id="content">
@if(session('success'))
<div class="alert alert-success">{{ session('success') }}</div>
@endif
@if(session('error'))
<div class="alert alert-error">{{ session('error') }}</div>
@endif
<article class="post-full">
@if(! empty($toc))
<nav class="toc" aria-label="文章目录">
<details open>
<summary>目录</summary>
<ol class="toc-list">
@foreach($toc as $item)
<li class="toc-level-{{ $item['level'] }}">
<a href="#{{ $item['id'] }}">{{ $item['text'] }}</a>
</li>
@endforeach
</ol>
</details>
</nav>
@endif
@if($cover = $post->getFirstMedia('cover'))
<div class="post-cover"><img src="{{ $cover->getUrl('card') ?: $cover->getUrl() }}" alt="{{ $post->title }}"></div>
@endif
<h1 class="post-title">{{ $post->title }}</h1>
<div class="post-meta">
<time datetime="{{ $post->published_at->toIso8601String() }}">{{ $post->published_at->format(blog_setting('normaltime', 'Y-m-d H:i')) }}</time>
@if($post->author)<span>· {{ $post->author->name }}</span>@endif
@if($post->category)
<span>· <a href="{{ route('category.show', $post->category->slug ?: $post->category->id) }}">{{ $post->category->name }}</a></span>
@endif
<span>· 阅读 {{ $post->views }}</span>
</div>
@stack('theme:post_content_top')
<div class="post-content">
{!! $contentHtml !!}
</div>
@stack('theme:post_content_bottom')
@if($post->tags->isNotEmpty())
<div class="post-tags">
@foreach($post->tags as $tag)
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
@endforeach
</div>
@endif
</article>
@if(! $post->close_comment)
<section id="comments" class="comments-section">
<h2 class="section-title">评论 ({{ $comments->total() }})</h2>
@forelse($comments as $comment)
<div class="comment" id="comment-{{ $comment->id }}">
<div class="comment-head">
<strong>{{ $comment->author_name }}</strong>
@if($comment->author_url)<span>· <a href="{{ go_url($comment->author_url) }}" target="_blank" rel="noopener nofollow">访问主页</a></span>@endif
<span class="comment-time">· {{ $comment->created_at->format(blog_setting('comment_timeformat', 'Y-m-d H:i')) }}</span>
</div>
<div class="comment-body">{!! comment_body($comment->content) !!}</div>
</div>
@empty
<p class="empty">暂无评论</p>
@endforelse
{{ $comments->links('partials.pagination-links') }}
<form method="post" action="{{ route('comments.store', $post) }}" class="comment-form" id="comment-form">
@csrf
<div class="form-row">
@auth
<input type="hidden" name="author_name" value="{{ auth()->user()->name }}">
@else
<input type="text" name="author_name" placeholder="昵称 *" required value="{{ old('author_name') }}">
<input type="email" name="author_email" placeholder="邮箱(不公开)" value="{{ old('author_email') }}">
<input type="url" name="author_url" placeholder="网站(可选)" value="{{ old('author_url') }}">
@endauth
</div>
<div class="form-row">
<textarea name="content" rows="5" placeholder="写下你的评论..." required minlength="{{ blog_setting('comment_min_len', 2) }}">{{ old('content') }}</textarea>
</div>
<div class="honeypot"><label>网站 <input type="text" name="website" tabindex="-1" autocomplete="off"></label></div>
@error('content')<p class="error">{{ $message }}</p>@enderror
<button type="submit" class="btn">发表评论</button>
</form>
</section>
@endif
</main>
@include('partials.sidebar')
</div>{{-- #page --}}
@include('partials.footer')
<script>fetch("{{ route('track-view', $post) }}")</script>
@stack('theme:body_end')
</body>
</html>