Files
ak f1b9d1e1c3 refactor: 外链中转拆为内置插件 neatstudio.link-tracker
- 插件承载全部逻辑:redirects 迁移(hasTable 兼容旧库)、Redirect 模型、UrlRedirector、/go 路由+控制器、Filament 外链中转资源
- 核心只留 hook 接入点:
  - tracked_url() 助手走 link.redirect 过滤器(评论正文/作者网址/友链模板统一调用)
  - 正文外链改写移到插件的 post.rendered 过滤器(优先级 20,晚于会员付费过滤)
- 停用插件:链接恢复直连、内容不受影响;后台「管理 → 外链中转」查看点击量/启停
- 测试更新为插件上下文(含无过滤器降级断言);97 通过
2026-08-13 02:05:32 +08:00

113 lines
5.4 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 class="container main-layout">
<main class="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>
@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="{{ tracked_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
@if($errors->has('author_name'))<p class="error">{{ $errors->first('author_name') }}</p>@endif
<button type="submit" class="btn">发表评论</button>
</form>
</section>
@endif
</main>
@include('partials.sidebar')
</div>
@include('partials.footer')
<script>fetch("{{ route('track-view', $post) }}")</script>
@stack('theme:body_end')
</body>
</html>