feat: restore sablog browse modes and clean imported HTML
Keep the public site readable after import (nbsp, highlighter, wrapping code, compact pager) and finish the admin extras already in this tree: sticky levels, preview, page cache, and live llms.txt. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -45,7 +45,7 @@ class PageCacheMiddleware
|
||||
'body' => $response->getContent(),
|
||||
'type' => $response->headers->get('Content-Type') ?: 'text/html; charset=utf-8',
|
||||
], $ttl);
|
||||
self::rememberKey($key);
|
||||
self::rememberKey($key, $request->fullUrl());
|
||||
}
|
||||
|
||||
return $response;
|
||||
@@ -53,8 +53,8 @@ class PageCacheMiddleware
|
||||
|
||||
public static function flush(): void
|
||||
{
|
||||
foreach ((array) Cache::get(self::TAG.'_keys', []) as $key) {
|
||||
Cache::forget($key);
|
||||
foreach (array_keys((array) Cache::get(self::TAG.'_keys', [])) as $key) {
|
||||
Cache::forget((string) $key);
|
||||
}
|
||||
|
||||
Cache::forget(self::TAG.'_keys');
|
||||
@@ -88,16 +88,50 @@ class PageCacheMiddleware
|
||||
Cache::forget(self::TAG.'_misses');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{key: string, url: string, cached_at: string}>
|
||||
*/
|
||||
public static function entries(): array
|
||||
{
|
||||
$entries = [];
|
||||
|
||||
foreach ((array) Cache::get(self::TAG.'_keys', []) as $key => $meta) {
|
||||
$entries[] = [
|
||||
'key' => (string) $key,
|
||||
'url' => is_array($meta) ? (string) ($meta['url'] ?? $key) : (string) $key,
|
||||
'cached_at' => is_array($meta) ? (string) ($meta['cached_at'] ?? '') : '',
|
||||
];
|
||||
}
|
||||
|
||||
usort($entries, fn (array $left, array $right): int => strcmp($right['cached_at'], $left['cached_at']));
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
public static function forget(string $key): void
|
||||
{
|
||||
Cache::forget($key);
|
||||
$keys = (array) Cache::get(self::TAG.'_keys', []);
|
||||
unset($keys[$key]);
|
||||
Cache::put(self::TAG.'_keys', $keys, now()->addDay());
|
||||
}
|
||||
|
||||
private static function increment(string $metric): void
|
||||
{
|
||||
$key = self::TAG.'_'.$metric;
|
||||
Cache::put($key, (int) Cache::get($key, 0) + 1, now()->addDay());
|
||||
}
|
||||
|
||||
private static function rememberKey(string $key): void
|
||||
private static function rememberKey(string $key, ?string $url = null): void
|
||||
{
|
||||
$keys = (array) Cache::get(self::TAG.'_keys', []);
|
||||
$keys[$key] = true;
|
||||
$previous = $keys[$key] ?? [];
|
||||
|
||||
$keys[$key] = [
|
||||
'url' => $url ?: (is_array($previous) ? (string) ($previous['url'] ?? '') : ''),
|
||||
'cached_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
Cache::put(self::TAG.'_keys', $keys, now()->addDay());
|
||||
}
|
||||
|
||||
@@ -117,16 +151,24 @@ class PageCacheMiddleware
|
||||
return false;
|
||||
}
|
||||
|
||||
// 动态端点
|
||||
// 动态端点、订阅和 agent 索引不进整页缓存,新文章要马上能看到
|
||||
if (str_starts_with($path, 'track-view')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (in_array($path, ['rss.xml', 'rss.php', 'sitemap.xml', 'robots.txt', 'llms.txt'], true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (str_ends_with($path, '.md')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function key(Request $request): string
|
||||
{
|
||||
return self::TAG.':'.md5($request->fullUrl());
|
||||
return self::TAG.':'.md5($request->fullUrl().'|view:'.HomeViewMode::resolve($request));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user