Compare commits
13
Commits
43dc8f9856
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79dfa0d88c | ||
|
|
f5987e7cc2 | ||
|
|
f6a9a8ea50 | ||
|
|
46428ce02f | ||
|
|
e0c709ad5c | ||
|
|
66ce4bce0a | ||
|
|
d5e68ab6fc | ||
|
|
6f1a25f7fa | ||
|
|
1add059bcc | ||
|
|
06e73d49d0 | ||
|
|
9fdbb55218 | ||
|
|
2301f7075e | ||
|
|
b491c8ac86 |
@@ -0,0 +1,58 @@
|
|||||||
|
name: Build and Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
verify:
|
||||||
|
runs-on: laralog-ci
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.neatcn.com/gouki/action-checkout@v4
|
||||||
|
- name: Verify CI runtime
|
||||||
|
run: |
|
||||||
|
php -r 'exit(PHP_VERSION_ID >= 80200 ? 0 : 1);'
|
||||||
|
node --version
|
||||||
|
composer --version
|
||||||
|
- name: Prepare env (sqlite for package discovery)
|
||||||
|
run: |
|
||||||
|
cp .env.example .env
|
||||||
|
mkdir -p database
|
||||||
|
touch database/database.sqlite
|
||||||
|
- name: Install backend dependencies
|
||||||
|
run: |
|
||||||
|
composer install --no-interaction --prefer-dist --ignore-platform-req=ext-exif
|
||||||
|
npm install
|
||||||
|
- name: Build backend assets
|
||||||
|
run: npm run build
|
||||||
|
- name: Persist built assets for deploy job
|
||||||
|
run: |
|
||||||
|
dest="/ci-artifacts/build-${{ gitea.sha }}"
|
||||||
|
test -d /ci-artifacts
|
||||||
|
rm -rf "$dest"
|
||||||
|
mkdir -p "$dest"
|
||||||
|
cp -a public/build/. "$dest/"
|
||||||
|
test -f "$dest/manifest.json"
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
needs: verify
|
||||||
|
runs-on: production
|
||||||
|
steps:
|
||||||
|
- uses: https://gitea.neatcn.com/gouki/action-checkout@v4
|
||||||
|
- name: Restore built assets from runner host
|
||||||
|
run: |
|
||||||
|
src="/opt/laralog/ci-artifacts/build-${{ gitea.sha }}"
|
||||||
|
test -d "$src"
|
||||||
|
mkdir -p public/build
|
||||||
|
cp -a "$src/." public/build/
|
||||||
|
test -f public/build/manifest.json
|
||||||
|
- uses: https://gitea.neatcn.com/gouki/deployment-toolkit/actions/laravel-release@v1.0.6
|
||||||
|
with:
|
||||||
|
source-dir: .
|
||||||
|
deploy-root: /opt/1panel/apps/openresty/openresty/www/sites/laralog.neatstudio.com/index
|
||||||
|
container-deploy-root: /www/sites/laralog.neatstudio.com/index
|
||||||
|
php-container: php83-ex
|
||||||
|
healthcheck-url: https://laralog.neatstudio.com/up
|
||||||
|
backup-command: "mysqldump -h10.0.4.7 -ularalog -p'Laralog#2026' laralog | gzip > /opt/laralog/backups/laralog-${{ gitea.sha }}.sql.gz"
|
||||||
|
release-id: ${{ gitea.sha }}
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main, master, develop]
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
services:
|
|
||||||
mysql:
|
|
||||||
image: mysql:8.0
|
|
||||||
env:
|
|
||||||
MYSQL_ROOT_PASSWORD: root
|
|
||||||
MYSQL_DATABASE: laralog_test
|
|
||||||
ports:
|
|
||||||
- 3306:3306
|
|
||||||
options: >-
|
|
||||||
--health-cmd="mysqladmin ping -proot"
|
|
||||||
--health-interval=10s
|
|
||||||
--health-timeout=5s
|
|
||||||
--health-retries=5
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup PHP
|
|
||||||
uses: shivammathur/setup-php@v2
|
|
||||||
with:
|
|
||||||
php-version: '8.2'
|
|
||||||
extensions: mbstring, dom, pdo_mysql, sqlite3, gd, redis
|
|
||||||
coverage: none
|
|
||||||
|
|
||||||
- name: Cache Composer
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: vendor
|
|
||||||
key: composer-${{ hashFiles('composer.lock') }}
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: composer install --no-interaction --prefer-dist --no-progress
|
|
||||||
|
|
||||||
- name: Env
|
|
||||||
run: |
|
|
||||||
cp .env.example .env
|
|
||||||
php artisan key:generate
|
|
||||||
touch database/database.sqlite
|
|
||||||
|
|
||||||
- name: Lint
|
|
||||||
run: |
|
|
||||||
find app plugins config database -name '*.php' -print0 | xargs -0 -n1 php -l
|
|
||||||
|
|
||||||
- name: Migrate & Seed (sqlite)
|
|
||||||
run: php artisan migrate --seed --force
|
|
||||||
|
|
||||||
- name: Run tests (sqlite)
|
|
||||||
run: php artisan test
|
|
||||||
|
|
||||||
# 生产走 MySQL:可选并行 MySQL 测试
|
|
||||||
- name: Run tests (mysql)
|
|
||||||
env:
|
|
||||||
DB_CONNECTION: mysql
|
|
||||||
DB_HOST: 127.0.0.1
|
|
||||||
DB_PORT: 3306
|
|
||||||
DB_DATABASE: laralog_test
|
|
||||||
DB_USERNAME: root
|
|
||||||
DB_PASSWORD: root
|
|
||||||
run: php artisan test
|
|
||||||
|
|
||||||
# 生产部署示例(SSH + rsync)。真实环境按需开启并配置 secrets:
|
|
||||||
# DEPLOY_HOST / DEPLOY_USER / DEPLOY_PATH / DEPLOY_SSH_KEY
|
|
||||||
deploy:
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
needs: test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment: production
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Deploy via SSH
|
|
||||||
uses: appleboy/ssh-action@v1
|
|
||||||
with:
|
|
||||||
host: ${{ secrets.DEPLOY_HOST }}
|
|
||||||
username: ${{ secrets.DEPLOY_USER }}
|
|
||||||
key: ${{ secrets.DEPLOY_SSH_KEY }}
|
|
||||||
script: |
|
|
||||||
cd ${{ secrets.DEPLOY_PATH }}
|
|
||||||
git pull origin main
|
|
||||||
composer install --no-dev --no-interaction --prefer-dist
|
|
||||||
php artisan migrate --force
|
|
||||||
php artisan config:cache
|
|
||||||
php artisan route:cache
|
|
||||||
php artisan view:cache
|
|
||||||
php artisan theme:publish
|
|
||||||
pm2 restart laralog-workerman laralog-schedule || pm2 start ecosystem.config.js
|
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
schema_version: 1
|
||||||
|
generated_at: "2026-08-13T10:34:55Z"
|
||||||
|
php:
|
||||||
|
version: 8.2.30
|
||||||
|
path: /Users/admin/Library/Application Support/Herd/bin//php
|
||||||
|
extensions:
|
||||||
|
- name: redis
|
||||||
|
constraint: '*'
|
||||||
|
installed: 6.3.0
|
||||||
|
loaded: true
|
||||||
|
- name: swoole
|
||||||
|
constraint: ^6.0
|
||||||
|
installed: 6.2.1
|
||||||
|
loaded: true
|
||||||
|
- name: xdebug
|
||||||
|
constraint: '*'
|
||||||
|
installed: ""
|
||||||
|
loaded: false
|
||||||
|
services: []
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
# xpier 项目钉定配置(可选:没有它 xpier 也能自动检测)
|
||||||
|
# 所有字段都可选,不需要的直接删掉或保持注释。字段说明见 docs/architecture.md。
|
||||||
|
|
||||||
|
runtime: fpm # 项目类型/运行时(决定 xpier up 怎么处理):
|
||||||
|
# ┌ fpm 标准 PHP / Laravel —— 无需 up:cd 项目 && xpier link,nginx+php-fpm 直接服务,访问 <目录名>.test
|
||||||
|
# ├ static 静态站点 —— 同 fpm,link 后 nginx 直接出文件
|
||||||
|
# ├ hyperf Hyperf 常驻服务 —— 在下方 apps: 写启动命令,xpier up 拉起
|
||||||
|
# ├ swoole Swoole 常驻服务 —— 同 hyperf
|
||||||
|
# └ frankenphp FrankenPHP —— 同 hyperf
|
||||||
|
# php: "8.4" # 钉定 PHP 版本(如 "8.2" / "8.4")
|
||||||
|
|
||||||
|
extensions: # 需要的 PHP 扩展(键=扩展名, 值=版本约束)
|
||||||
|
swoole: "^6.0" # 约束:"*" 任意 / "^6.0" / ">=6.0"
|
||||||
|
redis: "*"
|
||||||
|
xdebug: "*"
|
||||||
|
# 装法:xpier sync --apply 或 xpier ext:install swoole --php 8.4
|
||||||
|
|
||||||
|
# services: # 依赖的系统服务(sync --apply 会 brew 安装)
|
||||||
|
# - mysql
|
||||||
|
# - redis
|
||||||
|
|
||||||
|
apps: # 多应用编排(与 dev.yaml 同构,dev.yaml 优先;两种条目可混用)
|
||||||
|
# # 网站型:无 cmd —— up 自动注册站点(相当于 link),nginx+php-fpm 直接服务
|
||||||
|
blog:
|
||||||
|
dir: . # 可选,默认当前目录
|
||||||
|
domain: larablog.test # 必填:访问域名
|
||||||
|
secure: true # 可选:开启 https(默认 http)
|
||||||
|
php: "8.4" # 可选:固定 PHP 版本
|
||||||
|
|
||||||
|
# # 进程型:有 cmd —— up 托管常驻进程(Hyperf/vite...)
|
||||||
|
# php-server:
|
||||||
|
# dir: /path
|
||||||
|
# cmd: php bin/hyperf.php server:watch
|
||||||
|
# ports: ["9501"]
|
||||||
|
# domain: api.test # 可选:生成 nginx 反代
|
||||||
|
# node: "20" # 可选:经 nvm 固定 Node
|
||||||
|
# extensions: [swoole] # 可选:启动前检查扩展
|
||||||
@@ -20,8 +20,17 @@ class ArchiveController extends Controller
|
|||||||
return theme_view('archives', compact('archives'));
|
return theme_view('archives', compact('archives'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function month(string $year, string $month)
|
/**
|
||||||
|
* sablog 格式:/archives-{YYYYMM}.shtml
|
||||||
|
*/
|
||||||
|
public function month(string $date)
|
||||||
{
|
{
|
||||||
|
if (! preg_match('/^(\d{4})(\d{2})$/', $date, $m)) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
[$year, $month] = [$m[1], $m[2]];
|
||||||
|
|
||||||
$start = Carbon::create((int) $year, (int) $month, 1)->startOfMonth();
|
$start = Carbon::create((int) $year, (int) $month, 1)->startOfMonth();
|
||||||
$end = (clone $start)->endOfMonth();
|
$end = (clone $start)->endOfMonth();
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class LegacyController extends Controller
|
|||||||
$tag = Tag::findFromString($name, 'post');
|
$tag = Tag::findFromString($name, 'post');
|
||||||
|
|
||||||
return $tag
|
return $tag
|
||||||
? redirect()->route('tags.show', $tag->slug ?: $tag->name, 301)
|
? redirect()->route('tags.show', $tag->name, 301)
|
||||||
: abort(404);
|
: abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ class LegacyController extends Controller
|
|||||||
|
|
||||||
app(\App\Blog\Support\PluginManager::class)->doAction('comment.created', $comment);
|
app(\App\Blog\Support\PluginManager::class)->doAction('comment.created', $comment);
|
||||||
|
|
||||||
return redirect()->route('posts.show', $post->slug ?: $post->id)
|
return redirect()->route('posts.show', $post->id)
|
||||||
->with($status === 'published' ? 'success' : 'error', $status === 'published' ? '评论已发布' : '评论已提交,等待审核')
|
->with($status === 'published' ? 'success' : 'error', $status === 'published' ? '评论已发布' : '评论已提交,等待审核')
|
||||||
->withFragment('comments');
|
->withFragment('comments');
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ class LegacyController extends Controller
|
|||||||
$post = Post::find($id);
|
$post = Post::find($id);
|
||||||
|
|
||||||
return $post
|
return $post
|
||||||
? redirect()->route('posts.show', $post->slug ?: $post->id, 301)
|
? redirect()->route('posts.show', $post->id, 301)
|
||||||
: abort(404);
|
: abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ class LegacyController extends Controller
|
|||||||
$category = Category::find($cid);
|
$category = Category::find($cid);
|
||||||
|
|
||||||
return $category
|
return $category
|
||||||
? redirect()->route('category.show', $category->slug ?: $category->id, 301)
|
? redirect()->route('category.show', $category->id, 301)
|
||||||
: abort(404);
|
: abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,8 +185,8 @@ class LegacyController extends Controller
|
|||||||
$month = $m[2] ?? null;
|
$month = $m[2] ?? null;
|
||||||
|
|
||||||
return $month
|
return $month
|
||||||
? redirect()->route('archives.month', [$year, $month], 301)
|
? redirect()->route('archives.month', $year.$month, 301)
|
||||||
: redirect()->route('archives.month', [$year, '01'], 301);
|
: redirect()->route('archives.month', $year.'01', 301);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function tagList(Request $request)
|
private function tagList(Request $request)
|
||||||
@@ -198,7 +198,7 @@ class LegacyController extends Controller
|
|||||||
$tag = $tagId ? Tag::find((int) $tagId) : Tag::find((int) $request->query('id'));
|
$tag = $tagId ? Tag::find((int) $tagId) : Tag::find((int) $request->query('id'));
|
||||||
|
|
||||||
return $tag
|
return $tag
|
||||||
? redirect()->route('tags.show', $tag->slug ?: $tag->name, 301)
|
? redirect()->route('tags.show', $tag->name, 301)
|
||||||
: abort(404);
|
: abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,17 +14,22 @@ class PostController extends Controller
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(string $slug)
|
public function show(string $id, ?string $page = null)
|
||||||
{
|
{
|
||||||
$post = Post::query()
|
$post = Post::query()
|
||||||
->where('slug', $slug)
|
->where('id', (int) $id)
|
||||||
->orWhere('id', (int) $slug)
|
->orWhere('slug', $id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
abort_unless($post && $post->status === 'published', 404);
|
abort_unless($post && $post->status === 'published', 404);
|
||||||
|
|
||||||
$this->ensureReadable($post);
|
$this->ensureReadable($post);
|
||||||
|
|
||||||
|
// sablog 式 /show-{id}-{page}.shtml 的评论分页
|
||||||
|
if ($page !== null) {
|
||||||
|
\Illuminate\Pagination\Paginator::currentPageResolver(fn () => max(1, (int) $page));
|
||||||
|
}
|
||||||
|
|
||||||
// 浏览量由 /track-view 端点统计(页面整页缓存下控制器不执行,避免双计)
|
// 浏览量由 /track-view 端点统计(页面整页缓存下控制器不执行,避免双计)
|
||||||
|
|
||||||
$comments = $post->comments()
|
$comments = $post->comments()
|
||||||
|
|||||||
@@ -28,9 +28,12 @@ class TagController extends Controller
|
|||||||
return theme_view('tags', compact('tags'));
|
return theme_view('tags', compact('tags'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(string $slug)
|
/**
|
||||||
|
* sablog 格式:/tag/{name},按名称(而非 slug)解析
|
||||||
|
*/
|
||||||
|
public function show(string $name)
|
||||||
{
|
{
|
||||||
$tag = Tag::findFromString($slug, 'post');
|
$tag = Tag::findFromString(urldecode($name), 'post');
|
||||||
|
|
||||||
abort_unless($tag, 404);
|
abort_unless($tag, 404);
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,9 @@ class PostContentRenderer
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$replacement = $type === 'img'
|
// 老 sablog 的 [attach=xx] 对图片附件就是直接贴图,mime 是图片时用 <img>
|
||||||
|
$isImage = str_starts_with((string) $media->mime_type, 'image/');
|
||||||
|
$replacement = $type === 'img' || $isImage
|
||||||
? sprintf('<img src="%s" alt="%s" loading="lazy" />', $media->getUrl(), e($media->name))
|
? sprintf('<img src="%s" alt="%s" loading="lazy" />', $media->getUrl(), e($media->name))
|
||||||
: sprintf('<a href="%s">%s</a>', $media->getUrl(), e($media->file_name));
|
: sprintf('<a href="%s">%s</a>', $media->getUrl(), e($media->file_name));
|
||||||
|
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ class SablogImport extends Command
|
|||||||
'regip' => $row['regip'] ?: null,
|
'regip' => $row['regip'] ?: null,
|
||||||
'logintime' => $row['logintime'] ? date('Y-m-d H:i:s', (int) $row['logintime']) : null,
|
'logintime' => $row['logintime'] ? date('Y-m-d H:i:s', (int) $row['logintime']) : null,
|
||||||
'lastpost_at' => $row['lastpost'] ? date('Y-m-d H:i:s', (int) $row['lastpost']) : null,
|
'lastpost_at' => $row['lastpost'] ? date('Y-m-d H:i:s', (int) $row['lastpost']) : null,
|
||||||
'created_at' => date('Y-m-d H:i:s', (int) $row['regdateline']),
|
'created_at' => ($ts = (int) $row['regdateline']) > 0 ? date('Y-m-d H:i:s', $ts) : now(),
|
||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -252,10 +252,16 @@ class SablogImport extends Command
|
|||||||
foreach ($this->rows('articles') as $row) {
|
foreach ($this->rows('articles') as $row) {
|
||||||
$slug = SlugGenerator::make($row['title'], 'posts', 'slug', ignoreId: (int) $row['articleid'], fallback: 'post-'.$row['articleid']);
|
$slug = SlugGenerator::make($row['title'], 'posts', 'slug', ignoreId: (int) $row['articleid'], fallback: 'post-'.$row['articleid']);
|
||||||
$status = (int) $row['visible'] === 1 ? 'published' : 'draft';
|
$status = (int) $row['visible'] === 1 ? 'published' : 'draft';
|
||||||
$dateline = date('Y-m-d H:i:s', (int) $row['dateline']);
|
$dateline = ($ts = (int) $row['dateline']) > 0 ? date('Y-m-d H:i:s', $ts) : now()->toDateTimeString();
|
||||||
|
|
||||||
|
// 老库存在已删除分类的孤儿文章;目标列可空,置 null
|
||||||
|
$categoryId = (int) $row['cid'] ?: null;
|
||||||
|
if ($categoryId !== null && ! DB::table('categories')->where('id', $categoryId)->exists()) {
|
||||||
|
$categoryId = null;
|
||||||
|
}
|
||||||
|
|
||||||
DB::table('posts')->updateOrInsert(['id' => (int) $row['articleid']], [
|
DB::table('posts')->updateOrInsert(['id' => (int) $row['articleid']], [
|
||||||
'category_id' => (int) $row['cid'] ?: null,
|
'category_id' => $categoryId,
|
||||||
'user_id' => (int) $row['uid'] ?: null,
|
'user_id' => (int) $row['uid'] ?: null,
|
||||||
'title' => $row['title'],
|
'title' => $row['title'],
|
||||||
'slug' => $slug,
|
'slug' => $slug,
|
||||||
@@ -325,7 +331,7 @@ class SablogImport extends Command
|
|||||||
'content' => $row['content'],
|
'content' => $row['content'],
|
||||||
'ip' => $row['ipaddress'] ?: null,
|
'ip' => $row['ipaddress'] ?: null,
|
||||||
'status' => (int) $row['visible'] === 1 ? 'published' : 'pending',
|
'status' => (int) $row['visible'] === 1 ? 'published' : 'pending',
|
||||||
'created_at' => date('Y-m-d H:i:s', (int) $row['dateline']),
|
'created_at' => ($ts = (int) $row['dateline']) > 0 ? date('Y-m-d H:i:s', $ts) : null,
|
||||||
]);
|
]);
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class CommentsTable
|
|||||||
->label('文章')
|
->label('文章')
|
||||||
->limit(30)
|
->limit(30)
|
||||||
->description(fn ($record) => $record->post ? \Illuminate\Support\Str::limit($record->post->excerpt_or_fallback, 50) : null)
|
->description(fn ($record) => $record->post ? \Illuminate\Support\Str::limit($record->post->excerpt_or_fallback, 50) : null)
|
||||||
->url(fn ($record) => $record->post ? route('posts.show', $record->post->slug ?: $record->post->id) : null)
|
->url(fn ($record) => $record->post ? route('posts.show', $record->post->id) : null)
|
||||||
->openUrlInNewTab(),
|
->openUrlInNewTab(),
|
||||||
TextColumn::make('status')
|
TextColumn::make('status')
|
||||||
->label('状态')
|
->label('状态')
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class ApiController extends Controller
|
|||||||
'views' => $post->views,
|
'views' => $post->views,
|
||||||
'comment_count' => $post->comment_count,
|
'comment_count' => $post->comment_count,
|
||||||
'published_at' => $post->published_at?->toIso8601String(),
|
'published_at' => $post->published_at?->toIso8601String(),
|
||||||
'url' => route('posts.show', $post->slug ?: $post->id),
|
'url' => route('posts.show', $post->id),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ class ApiController extends Controller
|
|||||||
'views' => $post->views,
|
'views' => $post->views,
|
||||||
'comment_count' => $post->comment_count,
|
'comment_count' => $post->comment_count,
|
||||||
'published_at' => $post->published_at?->toIso8601String(),
|
'published_at' => $post->published_at?->toIso8601String(),
|
||||||
'url' => route('posts.show', $post->slug ?: $post->id),
|
'url' => route('posts.show', $post->id),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Category extends Model implements HasMedia
|
|||||||
|
|
||||||
public function getUrlAttribute(): string
|
public function getUrlAttribute(): string
|
||||||
{
|
{
|
||||||
return route('category.show', $this->slug ?? $this->id);
|
return route('category.show', $this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerMediaCollections(): void
|
public function registerMediaCollections(): void
|
||||||
|
|||||||
+1
-1
@@ -104,7 +104,7 @@ class Post extends Model implements HasMedia
|
|||||||
|
|
||||||
public function getUrlAttribute(): string
|
public function getUrlAttribute(): string
|
||||||
{
|
{
|
||||||
return route('posts.show', $this->slug ?? $this->id);
|
return route('posts.show', $this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -75,13 +75,13 @@ class SeoMiddleware
|
|||||||
'@context' => 'https://schema.org',
|
'@context' => 'https://schema.org',
|
||||||
'@type' => 'BlogPosting',
|
'@type' => 'BlogPosting',
|
||||||
'headline' => $post->title,
|
'headline' => $post->title,
|
||||||
'url' => route('posts.show', $post->slug ?: $post->id),
|
'url' => route('posts.show', $post->id),
|
||||||
'datePublished' => $post->published_at?->toIso8601String(),
|
'datePublished' => $post->published_at?->toIso8601String(),
|
||||||
'dateModified' => $post->updated_at?->toIso8601String(),
|
'dateModified' => $post->updated_at?->toIso8601String(),
|
||||||
'author' => ['@type' => 'Person', 'name' => $post->author?->name ?? $siteName] + ($sameAs ? ['sameAs' => $sameAs] : []),
|
'author' => ['@type' => 'Person', 'name' => $post->author?->name ?? $siteName] + ($sameAs ? ['sameAs' => $sameAs] : []),
|
||||||
'publisher' => ['@type' => 'Organization', 'name' => $siteName, 'url' => url('/')] + ($sameAs ? ['sameAs' => $sameAs] : []),
|
'publisher' => ['@type' => 'Organization', 'name' => $siteName, 'url' => url('/')] + ($sameAs ? ['sameAs' => $sameAs] : []),
|
||||||
'description' => Str::limit(strip_tags($post->excerpt_or_fallback), 200),
|
'description' => Str::limit(strip_tags($post->excerpt_or_fallback), 200),
|
||||||
'mainEntityOfPage' => route('posts.show', $post->slug ?: $post->id),
|
'mainEntityOfPage' => route('posts.show', $post->id),
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($cover = $post->getFirstMedia('cover')) {
|
if ($cover = $post->getFirstMedia('cover')) {
|
||||||
@@ -105,7 +105,7 @@ class SeoMiddleware
|
|||||||
'@type' => 'BreadcrumbList',
|
'@type' => 'BreadcrumbList',
|
||||||
'itemListElement' => [
|
'itemListElement' => [
|
||||||
['@type' => 'ListItem', 'position' => 1, 'name' => $siteName, 'item' => url('/')],
|
['@type' => 'ListItem', 'position' => 1, 'name' => $siteName, 'item' => url('/')],
|
||||||
['@type' => 'ListItem', 'position' => 2, 'name' => $category->name, 'item' => route('category.show', $category->slug ?: $category->id)],
|
['@type' => 'ListItem', 'position' => 2, 'name' => $category->name, 'item' => route('category.show', $category->id)],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class SeoController
|
|||||||
$lines[] = '';
|
$lines[] = '';
|
||||||
|
|
||||||
foreach ($posts as $post) {
|
foreach ($posts as $post) {
|
||||||
$lines[] = '- ['.$post->title.']('.route('posts.show', $post->slug ?: $post->id).') — '.Str::limit(strip_tags($post->excerpt_or_fallback), 120);
|
$lines[] = '- ['.$post->title.']('.route('posts.show', $post->id).') — '.Str::limit(strip_tags($post->excerpt_or_fallback), 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response(implode("\n", $lines)."\n")
|
return response(implode("\n", $lines)."\n")
|
||||||
|
|||||||
+3
-1
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
@@ -24,7 +25,8 @@ return new class extends Migration
|
|||||||
$table->timestamp('last_clicked_at')->nullable();
|
$table->timestamp('last_clicked_at')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
||||||
$table->index('target_url');
|
// MySQL 5.7 不支持对 TEXT 建全值索引,用前缀索引
|
||||||
|
$table->index([DB::raw('target_url(191)')], 'redirects_target_url_index');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class MembershipController
|
|||||||
// 已能读付费内容(会员 / 作者 / 已解锁):直接查看文章,避免重复支付。
|
// 已能读付费内容(会员 / 作者 / 已解锁):直接查看文章,避免重复支付。
|
||||||
// 注意:付费块文章的整篇是公开的,不能用 canReadPost 判断(否则永远"已有权限")
|
// 注意:付费块文章的整篇是公开的,不能用 canReadPost 判断(否则永远"已有权限")
|
||||||
if ($this->service->canReadPaidContent($user, $post)) {
|
if ($this->service->canReadPaidContent($user, $post)) {
|
||||||
return redirect()->route('posts.show', $post->slug ?? $post->id);
|
return redirect()->route('posts.show', $post->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 单篇付费解锁:创建一笔定向支付
|
// 单篇付费解锁:创建一笔定向支付
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
<ul class="archive-list">
|
<ul class="archive-list">
|
||||||
@foreach($months as $month => $monthPosts)
|
@foreach($months as $month => $monthPosts)
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ route('archives.month', [$year, $month]) }}">{{ (int) $month }} 月</a>
|
<a href="{{ route('archives.month', $year.$month) }}">{{ (int) $month }} 月</a>
|
||||||
<span class="count">({{ $monthPosts->count() }} 篇)</span>
|
<span class="count">({{ $monthPosts->count() }} 篇)</span>
|
||||||
<ul class="archive-posts">
|
<ul class="archive-posts">
|
||||||
@foreach($monthPosts as $post)
|
@foreach($monthPosts as $post)
|
||||||
<li><a href="{{ route('posts.show', $post->slug ?: $post->id) }}">{{ $post->title }}</a> <time>{{ $post->published_at->format(blog_setting('listtime', 'm-d')) }}</time></li>
|
<li><a href="{{ route('posts.show', $post->id) }}">{{ $post->title }}</a> <time>{{ $post->published_at->format(blog_setting('listtime', 'm-d')) }}</time></li>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<div class="comment" id="comment-{{ $comment->id }}">
|
<div class="comment" id="comment-{{ $comment->id }}">
|
||||||
<div class="comment-head">
|
<div class="comment-head">
|
||||||
<strong>{{ $comment->author_name }}</strong>
|
<strong>{{ $comment->author_name }}</strong>
|
||||||
<span>· 评论于 <a href="{{ route('posts.show', $comment->post->slug ?: $comment->post->id) }}#comment-{{ $comment->id }}">{{ $comment->post->title }}</a></span>
|
<span>· 评论于 <a href="{{ route('posts.show', $comment->post->id) }}#comment-{{ $comment->id }}">{{ $comment->post->title }}</a></span>
|
||||||
<span class="comment-time">· {{ $comment->created_at->format(blog_setting('comment_timeformat', 'Y-m-d H:i')) }}</span>
|
<span class="comment-time">· {{ $comment->created_at->format(blog_setting('comment_timeformat', 'Y-m-d H:i')) }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="comment-body">{!! nl2br(e($comment->content)) !!}</div>
|
<div class="comment-body">{!! nl2br(e($comment->content)) !!}</div>
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
@foreach($posts as $post)
|
@foreach($posts as $post)
|
||||||
<item>
|
<item>
|
||||||
<title>{{ $post->title }}</title>
|
<title>{{ $post->title }}</title>
|
||||||
<link>{{ route('posts.show', $post->slug ?: $post->id) }}</link>
|
<link>{{ route('posts.show', $post->id) }}</link>
|
||||||
<guid isPermaLink="true">{{ route('posts.show', $post->slug ?: $post->id) }}</guid>
|
<guid isPermaLink="true">{{ route('posts.show', $post->id) }}</guid>
|
||||||
<pubDate>{{ $post->published_at->toRssString() }}</pubDate>
|
<pubDate>{{ $post->published_at->toRssString() }}</pubDate>
|
||||||
<description>{{ Str::limit(strip_tags($post->excerpt_or_fallback), 300) }}</description>
|
<description>{{ Str::limit(strip_tags($post->excerpt_or_fallback), 300) }}</description>
|
||||||
@if($post->category)
|
@if($post->category)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
</url>
|
</url>
|
||||||
@foreach($posts as $post)
|
@foreach($posts as $post)
|
||||||
<url>
|
<url>
|
||||||
<loc>{{ route('posts.show', $post->slug ?: $post->id) }}</loc>
|
<loc>{{ route('posts.show', $post->id) }}</loc>
|
||||||
<lastmod>{{ $post->updated_at?->toAtomString() }}</lastmod>
|
<lastmod>{{ $post->updated_at?->toAtomString() }}</lastmod>
|
||||||
<changefreq>monthly</changefreq>
|
<changefreq>monthly</changefreq>
|
||||||
<priority>0.8</priority>
|
<priority>0.8</priority>
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
<article class="post-card {{ $post->is_sticky ? 'sticky' : '' }}">
|
<article class="post-card {{ $post->is_sticky ? 'sticky' : '' }}">
|
||||||
@if($cover = $post->getFirstMedia('cover'))
|
@if($cover = $post->getFirstMedia('cover'))
|
||||||
<a href="{{ route('posts.show', $post->slug ?: $post->id) }}" class="post-cover">
|
<a href="{{ route('posts.show', $post->id) }}" class="post-cover">
|
||||||
<img src="{{ $cover->getUrl('card') ?: $cover->getUrl() }}" alt="{{ $post->title }}" loading="lazy">
|
<img src="{{ $cover->getUrl('card') ?: $cover->getUrl() }}" alt="{{ $post->title }}" loading="lazy">
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
<h2 class="post-title">
|
<h2 class="post-title">
|
||||||
@if($post->is_sticky)<span class="badge">置顶</span>@endif
|
@if($post->is_sticky)<span class="badge">置顶</span>@endif
|
||||||
<a href="{{ route('posts.show', $post->slug ?: $post->id) }}">{{ $post->title }}</a>
|
<a href="{{ route('posts.show', $post->id) }}">{{ $post->title }}</a>
|
||||||
</h2>
|
</h2>
|
||||||
<div class="post-meta">
|
<div class="post-meta">
|
||||||
<time datetime="{{ $post->published_at->toIso8601String() }}">{{ $post->published_at->format(blog_setting('normaltime', 'Y-m-d H:i')) }}</time>
|
<time datetime="{{ $post->published_at->toIso8601String() }}">{{ $post->published_at->format(blog_setting('normaltime', 'Y-m-d H:i')) }}</time>
|
||||||
@if($post->category)
|
@if($post->category)
|
||||||
<span>·</span>
|
<span>·</span>
|
||||||
<a href="{{ route('category.show', $post->category->slug ?: $post->category->id) }}">{{ $post->category->name }}</a>
|
<a href="{{ route('category.show', $post->category->id) }}">{{ $post->category->name }}</a>
|
||||||
@endif
|
@endif
|
||||||
<span>· 阅读 {{ $post->views }}</span>
|
<span>· 阅读 {{ $post->views }}</span>
|
||||||
<span>· 评论 {{ $post->comment_count }}</span>
|
<span>· 评论 {{ $post->comment_count }}</span>
|
||||||
@@ -21,9 +21,9 @@
|
|||||||
{{ Str::limit(strip_tags($post->excerpt_or_fallback), 200) }}
|
{{ Str::limit(strip_tags($post->excerpt_or_fallback), 200) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="post-footer">
|
<div class="post-footer">
|
||||||
<a href="{{ route('posts.show', $post->slug ?: $post->id) }}" class="read-more">阅读全文 »</a>
|
<a href="{{ route('posts.show', $post->id) }}" class="read-more">阅读全文 »</a>
|
||||||
@foreach($post->tags as $tag)
|
@foreach($post->tags as $tag)
|
||||||
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
|
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<ul class="widget-list">
|
<ul class="widget-list">
|
||||||
@forelse($categories as $category)
|
@forelse($categories as $category)
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ route('category.show', $category->slug ?: $category->id) }}">{{ $category->name }}</a>
|
<a href="{{ route('category.show', $category->id) }}">{{ $category->name }}</a>
|
||||||
<span class="count">({{ $category->post_count }})</span>
|
<span class="count">({{ $category->post_count }})</span>
|
||||||
</li>
|
</li>
|
||||||
@empty
|
@empty
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
<h3 class="widget-title">最新文章</h3>
|
<h3 class="widget-title">最新文章</h3>
|
||||||
<ul class="widget-list">
|
<ul class="widget-list">
|
||||||
@forelse($recentPosts as $post)
|
@forelse($recentPosts as $post)
|
||||||
<li><a href="{{ route('posts.show', $post->slug ?: $post->id) }}">{{ $post->title }}</a></li>
|
<li><a href="{{ route('posts.show', $post->id) }}">{{ $post->title }}</a></li>
|
||||||
@empty
|
@empty
|
||||||
<li>暂无文章</li>
|
<li>暂无文章</li>
|
||||||
@endforelse
|
@endforelse
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
<ul class="widget-list">
|
<ul class="widget-list">
|
||||||
@forelse($recentComments as $comment)
|
@forelse($recentComments as $comment)
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ route('posts.show', $comment->post->slug ?: $comment->post->id) }}#comment-{{ $comment->id }}">
|
<a href="{{ route('posts.show', $comment->post->id) }}#comment-{{ $comment->id }}">
|
||||||
{{ $comment->author_name }}:{{ Str::limit(strip_tags($comment->content), 30) }}
|
{{ $comment->author_name }}:{{ Str::limit(strip_tags($comment->content), 30) }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
<h3 class="widget-title">标签云</h3>
|
<h3 class="widget-title">标签云</h3>
|
||||||
<div class="tag-cloud">
|
<div class="tag-cloud">
|
||||||
@forelse($hotTags as $tag)
|
@forelse($hotTags as $tag)
|
||||||
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">{{ $tag->name }}</a>
|
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link">{{ $tag->name }}</a>
|
||||||
@empty
|
@empty
|
||||||
<span>暂无标签</span>
|
<span>暂无标签</span>
|
||||||
@endforelse
|
@endforelse
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
<time datetime="{{ $post->published_at->toIso8601String() }}">{{ $post->published_at->format(blog_setting('normaltime', 'Y-m-d H:i')) }}</time>
|
<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->author)<span>· {{ $post->author->name }}</span>@endif
|
||||||
@if($post->category)
|
@if($post->category)
|
||||||
<span>· <a href="{{ route('category.show', $post->category->slug ?: $post->category->id) }}">{{ $post->category->name }}</a></span>
|
<span>· <a href="{{ route('category.show', $post->category->id) }}">{{ $post->category->name }}</a></span>
|
||||||
@endif
|
@endif
|
||||||
<span>· 阅读 {{ $post->views }}</span>
|
<span>· 阅读 {{ $post->views }}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
@if($post->tags->isNotEmpty())
|
@if($post->tags->isNotEmpty())
|
||||||
<div class="post-tags">
|
<div class="post-tags">
|
||||||
@foreach($post->tags as $tag)
|
@foreach($post->tags as $tag)
|
||||||
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
|
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<h1 class="list-title">全部标签</h1>
|
<h1 class="list-title">全部标签</h1>
|
||||||
<div class="tag-cloud big">
|
<div class="tag-cloud big">
|
||||||
@forelse($tags as $tag)
|
@forelse($tags as $tag)
|
||||||
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link" style="font-size: {{ max(0.9, min(1.8, 0.9 + $tag->posts_count * 0.1)) }}em">
|
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link" style="font-size: {{ max(0.9, min(1.8, 0.9 + $tag->posts_count * 0.1)) }}em">
|
||||||
{{ $tag->name }} ({{ $tag->posts_count }})
|
{{ $tag->name }} ({{ $tag->posts_count }})
|
||||||
</a>
|
</a>
|
||||||
@empty
|
@empty
|
||||||
|
|||||||
+50
-11
@@ -31,38 +31,77 @@ Route::get('/', function () {
|
|||||||
return app(HomeController::class)->index();
|
return app(HomeController::class)->index();
|
||||||
})->name('home');
|
})->name('home');
|
||||||
|
|
||||||
Route::get('/posts/{slug}.shtml', [PostController::class, 'show'])->where('slug', '[^/]+')->name('posts.show');
|
// sablog 首页分页格式:/index-{page}.shtml
|
||||||
Route::get('/posts/{slug}', fn (string $slug) => redirect()->route('posts.show', $slug, 301))->where('slug', '[^/]+');
|
Route::get('/index-{page}.shtml', function (string $page) {
|
||||||
|
\Illuminate\Pagination\Paginator::currentPageResolver(fn () => max(1, (int) $page));
|
||||||
|
|
||||||
|
return app(HomeController::class)->index();
|
||||||
|
})->whereNumber('page');
|
||||||
|
|
||||||
|
Route::get('/posts/{slug}.shtml', function (string $slug) {
|
||||||
|
$post = \App\Models\Post::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
|
||||||
|
|
||||||
|
return $post ? redirect()->route('posts.show', $post->id, 301) : abort(404);
|
||||||
|
})->where('slug', '[^/]+');
|
||||||
|
Route::get('/posts/{slug}', function (string $slug) {
|
||||||
|
$post = \App\Models\Post::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
|
||||||
|
|
||||||
|
return $post ? redirect()->route('posts.show', $post->id, 301) : abort(404);
|
||||||
|
})->where('slug', '[^/]+');
|
||||||
|
|
||||||
|
// 文章正典:与 sablog 完全一致 /show-{id}.shtml(评论分页 /show-{id}-{page}.shtml)
|
||||||
|
Route::get('/show-{id}.shtml', [PostController::class, 'show'])->whereNumber('id')->name('posts.show');
|
||||||
|
Route::get('/show-{id}-{page}.shtml', [PostController::class, 'show'])->whereNumber('id')->whereNumber('page');
|
||||||
Route::post('/posts/{post}/comments', [CommentController::class, 'store'])->name('comments.store');
|
Route::post('/posts/{post}/comments', [CommentController::class, 'store'])->name('comments.store');
|
||||||
|
|
||||||
// 浏览量统计(独立端点,避开整页缓存,保证实时)
|
// 浏览量统计(独立端点,避开整页缓存,保证实时)
|
||||||
Route::get('/track-view/{post}', fn (\App\Models\Post $post) => response($post->increment('views') ? '' : '', 204))->name('track-view');
|
Route::get('/track-view/{post}', fn (\App\Models\Post $post) => response($post->increment('views') ? '' : '', 204))->name('track-view');
|
||||||
|
|
||||||
|
|
||||||
Route::get('/category/{slug}.shtml', [CategoryController::class, 'show'])->where('slug', '[^/]+')->name('category.show');
|
Route::get('/category/{slug}.shtml', function (string $slug) {
|
||||||
Route::get('/category/{slug}', fn (string $slug) => redirect()->route('category.show', $slug, 301))->where('slug', '[^/]+');
|
$category = \App\Models\Category::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
|
||||||
|
|
||||||
|
return $category ? redirect()->route('category.show', $category->id, 301) : abort(404);
|
||||||
|
})->where('slug', '[^/]+');
|
||||||
|
Route::get('/category/{slug}', function (string $slug) {
|
||||||
|
$category = \App\Models\Category::query()->where('slug', $slug)->orWhere('id', (int) $slug)->first();
|
||||||
|
|
||||||
|
return $category ? redirect()->route('category.show', $category->id, 301) : abort(404);
|
||||||
|
})->where('slug', '[^/]+');
|
||||||
|
|
||||||
|
// 分类正典:/category-{cid}.shtml(分页 /category-{cid}-{page}.shtml)
|
||||||
|
Route::get('/category-{cid}.shtml', [CategoryController::class, 'show'])->whereNumber('cid')->name('category.show');
|
||||||
|
Route::get('/category-{cid}-{page}.shtml', [CategoryController::class, 'show'])->whereNumber('cid')->whereNumber('page');
|
||||||
|
|
||||||
Route::get('/archives.shtml', [ArchiveController::class, 'index'])->name('archives');
|
Route::get('/archives.shtml', [ArchiveController::class, 'index'])->name('archives');
|
||||||
Route::get('/archives', fn () => redirect()->route('archives', [], 301));
|
Route::get('/archives', fn () => redirect()->route('archives', [], 301));
|
||||||
Route::get('/archives/{year}/{month}.shtml', [ArchiveController::class, 'month'])
|
Route::get('/archives/{year}/{month}.shtml', fn (string $year, string $month) => redirect()->route('archives.month', $year.$month, 301))
|
||||||
->where(['year' => '\d{4}', 'month' => '\d{2}'])
|
|
||||||
->name('archives.month');
|
|
||||||
Route::get('/archives/{year}/{month}', fn (string $year, string $month) => redirect()->route('archives.month', [$year, $month], 301))
|
|
||||||
->where(['year' => '\d{4}', 'month' => '\d{2}']);
|
->where(['year' => '\d{4}', 'month' => '\d{2}']);
|
||||||
|
Route::get('/archives/{year}/{month}', fn (string $year, string $month) => redirect()->route('archives.month', $year.$month, 301))
|
||||||
|
->where(['year' => '\d{4}', 'month' => '\d{2}']);
|
||||||
|
// 按月归档正典:/archives-{YYYYMM}.shtml(分页 /archives-{YYYYMM}-{page}.shtml)
|
||||||
|
Route::get('/archives-{date}.shtml', [ArchiveController::class, 'month'])->where('date', '\d{6}')->name('archives.month');
|
||||||
|
Route::get('/archives-{date}-{page}.shtml', [ArchiveController::class, 'month'])->where(['date' => '\d{6}', 'page' => '\d+']);
|
||||||
|
|
||||||
Route::get('/tags.shtml', [TagController::class, 'index'])->name('tags');
|
// 标签正典:/tag/{name}(sablog 原版);列表 /tagslist.shtml
|
||||||
|
Route::get('/tagslist.shtml', [TagController::class, 'index'])->name('tags');
|
||||||
|
Route::get('/tagslist-{page}.shtml', [TagController::class, 'index'])->whereNumber('page');
|
||||||
|
Route::get('/tag/{name}', [TagController::class, 'show'])->name('tags.show');
|
||||||
|
Route::get('/tags.shtml', fn () => redirect()->route('tags', [], 301));
|
||||||
Route::get('/tags', fn () => redirect()->route('tags', [], 301));
|
Route::get('/tags', fn () => redirect()->route('tags', [], 301));
|
||||||
Route::get('/tags/{slug}.shtml', [TagController::class, 'show'])->where('slug', '[^/]+')->name('tags.show');
|
Route::get('/tags/{slug}.shtml', fn (string $slug) => redirect()->route('tags.show', $slug, 301))->where('slug', '[^/]+');
|
||||||
Route::get('/tags/{slug}', fn (string $slug) => redirect()->route('tags.show', $slug, 301))->where('slug', '[^/]+');
|
Route::get('/tags/{slug}', fn (string $slug) => redirect()->route('tags.show', $slug, 301))->where('slug', '[^/]+');
|
||||||
|
|
||||||
Route::get('/search.shtml', [SearchController::class, 'index'])->name('search');
|
Route::get('/search.shtml', [SearchController::class, 'index'])->name('search');
|
||||||
Route::get('/search', fn () => redirect()->route('search', [], 301));
|
Route::get('/search', fn () => redirect()->route('search', [], 301));
|
||||||
|
Route::get('/search-{page}.shtml', [SearchController::class, 'index'])->whereNumber('page');
|
||||||
|
|
||||||
Route::get('/links.shtml', [LinkController::class, 'index'])->name('links');
|
Route::get('/links.shtml', [LinkController::class, 'index'])->name('links');
|
||||||
Route::get('/links', fn () => redirect()->route('links', [], 301));
|
Route::get('/links', fn () => redirect()->route('links', [], 301));
|
||||||
|
|
||||||
Route::get('/comments.shtml', [CommentController::class, 'index'])->name('comments');
|
Route::get('/comments.shtml', [CommentController::class, 'index'])->name('comments');
|
||||||
Route::get('/comments', fn () => redirect()->route('comments', [], 301));
|
Route::get('/comments', fn () => redirect()->route('comments', [], 301));
|
||||||
|
Route::get('/comments-{page}.shtml', [CommentController::class, 'index'])->whereNumber('page');
|
||||||
|
|
||||||
Route::get('/login.shtml', [AuthController::class, 'showLogin'])->name('login');
|
Route::get('/login.shtml', [AuthController::class, 'showLogin'])->name('login');
|
||||||
Route::get('/login', fn () => redirect()->route('login', [], 301));
|
Route::get('/login', fn () => redirect()->route('login', [], 301));
|
||||||
@@ -120,7 +159,7 @@ Route::get('/tagslist.html', fn () => redirect()->route('tags', [], 301));
|
|||||||
Route::get('/comments-{page}.html', fn () => redirect()->route('comments', [], 301))->where('page', '\d+');
|
Route::get('/comments-{page}.html', fn () => redirect()->route('comments', [], 301))->where('page', '\d+');
|
||||||
Route::get('/search-{page}.html', fn () => redirect()->route('search', [], 301))->where('page', '\d+');
|
Route::get('/search-{page}.html', fn () => redirect()->route('search', [], 301))->where('page', '\d+');
|
||||||
Route::get('/reg.shtml', fn () => redirect()->route('register', [], 301));
|
Route::get('/reg.shtml', fn () => redirect()->route('register', [], 301));
|
||||||
Route::get('/tag/{name}', [LegacyController::class, 'tagByName']);
|
// /tag/{name} 已是正典路由(tags.show),不再需要 LegacyController 中转
|
||||||
|
|
||||||
Route::get('/index.php', fn () => app(LegacyController::class)->resolveAction(request()));
|
Route::get('/index.php', fn () => app(LegacyController::class)->resolveAction(request()));
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<h3>分类</h3>
|
<h3>分类</h3>
|
||||||
<ul>
|
<ul>
|
||||||
@forelse($categories as $category)
|
@forelse($categories as $category)
|
||||||
<li><a href="{{ route('category.show', $category->slug ?: $category->id) }}">{{ $category->name }}</a> ({{ $category->post_count }})</li>
|
<li><a href="{{ route('category.show', $category->id) }}">{{ $category->name }}</a> ({{ $category->post_count }})</li>
|
||||||
@empty
|
@empty
|
||||||
<li>暂无分类</li>
|
<li>暂无分类</li>
|
||||||
@endforelse
|
@endforelse
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
<h3>最新文章</h3>
|
<h3>最新文章</h3>
|
||||||
<ul>
|
<ul>
|
||||||
@forelse($recentPosts as $post)
|
@forelse($recentPosts as $post)
|
||||||
<li><a href="{{ route('posts.show', $post->slug ?: $post->id) }}">{{ $post->title }}</a></li>
|
<li><a href="{{ route('posts.show', $post->id) }}">{{ $post->title }}</a></li>
|
||||||
@empty
|
@empty
|
||||||
<li>暂无文章</li>
|
<li>暂无文章</li>
|
||||||
@endforelse
|
@endforelse
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<h3>最新评论</h3>
|
<h3>最新评论</h3>
|
||||||
<ul>
|
<ul>
|
||||||
@forelse($recentComments as $comment)
|
@forelse($recentComments as $comment)
|
||||||
<li><a href="{{ route('posts.show', $comment->post->slug ?: $comment->post->id) }}#comment-{{ $comment->id }}">{{ $comment->author_name }}:{{ Str::limit(strip_tags($comment->content), 20) }}</a></li>
|
<li><a href="{{ route('posts.show', $comment->post->id) }}#comment-{{ $comment->id }}">{{ $comment->author_name }}:{{ Str::limit(strip_tags($comment->content), 20) }}</a></li>
|
||||||
@empty
|
@empty
|
||||||
<li>暂无评论</li>
|
<li>暂无评论</li>
|
||||||
@endforelse
|
@endforelse
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
<h3>标签</h3>
|
<h3>标签</h3>
|
||||||
<p class="tagcloud">
|
<p class="tagcloud">
|
||||||
@forelse($hotTags as $tag)
|
@forelse($hotTags as $tag)
|
||||||
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}">{{ $tag->name }}</a>
|
<a href="{{ route('tags.show', $tag->name) }}">{{ $tag->name }}</a>
|
||||||
@empty
|
@empty
|
||||||
暂无标签
|
暂无标签
|
||||||
@endforelse
|
@endforelse
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<time datetime="{{ $post->published_at->toIso8601String() }}">{{ $post->published_at->format(blog_setting('normaltime', 'Y-m-d H:i')) }}</time>
|
<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->author)<span>· {{ $post->author->name }}</span>@endif
|
||||||
@if($post->category)
|
@if($post->category)
|
||||||
<span>· <a href="{{ route('category.show', $post->category->slug ?: $post->category->id) }}">{{ $post->category->name }}</a></span>
|
<span>· <a href="{{ route('category.show', $post->category->id) }}">{{ $post->category->name }}</a></span>
|
||||||
@endif
|
@endif
|
||||||
<span>· 阅读 {{ $post->views }}</span>
|
<span>· 阅读 {{ $post->views }}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
@if($post->tags->isNotEmpty())
|
@if($post->tags->isNotEmpty())
|
||||||
<div class="post-tags">
|
<div class="post-tags">
|
||||||
@foreach($post->tags as $tag)
|
@foreach($post->tags as $tag)
|
||||||
<a href="{{ route('tags.show', $tag->slug ?: $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
|
<a href="{{ route('tags.show', $tag->name) }}" class="tag-link">#{{ $tag->name }}</a>
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
Reference in New Issue
Block a user