Files
laralog/app/Blog/Controllers/FeedController.php
T
goukiandCursor ae47447062
Build and Deploy / verify (push) Successful in 40s
Build and Deploy / deploy (push) Successful in 36s
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>
2026-09-18 21:33:02 +00:00

62 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Blog\Controllers;
use App\Models\Post;
use Illuminate\Http\Response;
class FeedController extends Controller
{
public function rss()
{
$posts = Post::query()
->published()
->latest('published_at')
->limit((int) blog_setting('rss_num', config('blog.rss_num')))
->with('category', 'author', 'tags')
->get();
$content = view('feed.rss', [
'posts' => $posts,
'siteName' => blog_setting('site_name', config('blog.name')),
'siteDescription' => blog_setting('site_description', config('blog.description')),
'xmlDeclaration' => '<?xml version="1.0" encoding="UTF-8"?>',
])->render();
return response($content)->header('Content-Type', 'application/rss+xml; charset=utf-8');
}
public function sitemap()
{
$posts = Post::query()
->published()
->latest('published_at')
->get(['id', 'slug', 'updated_at']);
$content = view('feed.sitemap', [
'posts' => $posts,
'xmlDeclaration' => '<?xml version="1.0" encoding="UTF-8"?>',
])->render();
return response($content)->header('Content-Type', 'application/xml; charset=utf-8');
}
public function robots(): Response
{
$disallow = array_merge(config('robots.disallow'), (array) blog_setting('seo_robots_disallow', []));
$sitemap = config('robots.sitemap');
$lines = ['User-agent: *'];
foreach ($disallow as $path) {
$lines[] = "Disallow: {$path}";
}
$lines[] = 'Sitemap: '.url($sitemap);
$lines[] = 'Allow: /llms.txt';
$lines[] = 'Allow: /posts/*.md';
return response(implode("\n", $lines)."\n")->header('Content-Type', 'text/plain; charset=utf-8');
}
}