Blog localization: lang-filtered API, strict EN/FA mirrored content, 12 new topics
Deploy Backend / deploy (push) Successful in 2m51s
Deploy Backend / deploy (push) Successful in 2m51s
- Add FilterableByLanguage scope (posts/categories/tags) keyed off the -fa slug convention; every public blog list endpoint honors ?lang=fa|en, feeds/sitemaps keep all languages when omitted - Homepage (latest/most-viewed/random posts + categories) filters per language; post detail shows same-language related posts only - Reseed content to a strict English/Persian mirror: 6 existing international topics + 6 new Iran-market topics (technical SEO for Persian sites, Iranian dev freelancing, AI & Iranian dev careers, web design for Iranian businesses, React job market in Iran, WordPress-to-Next migration), 12 posts per language, zero posts in only one language - Fix 2 legacy FA slugs to follow the EN-slug + -fa convention so twin redirects and mirror assertions hold - Update seeder test to assert balanced languages, full twin coverage and same-language related posts; add lang-filter coverage
This commit is contained in:
1 parent
21fa37af1f
commit
65415beae7
11 files changed
+904
-32
No files matched your search
@@ -37,7 +37,7 @@ class CategoryController extends Controller
|
||||
['name', 'slug', 'created_at', 'updated_at']
|
||||
);
|
||||
|
||||
$query = Category::with('posts');
|
||||
$query = Category::with('posts')->byLanguage($request->input('lang'));
|
||||
|
||||
if ($request->filled('filter')) {
|
||||
$query->where('name', 'like', '%'.$request->string('filter').'%');
|
||||
@@ -98,6 +98,8 @@ class CategoryController extends Controller
|
||||
|
||||
$postsQuery = $category->posts()->with(['category', 'tags', 'author']);
|
||||
|
||||
$postsQuery->byLanguage($request->input('lang'));
|
||||
|
||||
if (! empty($filter)) {
|
||||
$postsQuery->where('title', 'like', '%'.$filter.'%');
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Http\Resources\CategoryResource;
|
||||
use App\Http\Resources\PostResource;
|
||||
use App\Models\Blog\Category;
|
||||
use App\Models\Blog\Post;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* @OA\Tag(name="Blog Home", description="Blog homepage aggregated data")
|
||||
@@ -18,26 +19,35 @@ class HomeController extends Controller
|
||||
* path="/blog/homepage",
|
||||
* tags={"Blog Home"},
|
||||
* summary="Get homepage data: latest posts, categories, most viewed, random",
|
||||
*
|
||||
* @OA\Parameter(name="lang", in="query", @OA\Schema(type="string", enum={"en","fa"})),
|
||||
*
|
||||
* @OA\Response(response=200, description="OK")
|
||||
* )
|
||||
*/
|
||||
public function index()
|
||||
public function index(Request $request)
|
||||
{
|
||||
$lang = $request->input('lang');
|
||||
|
||||
$latestPosts = Post::with(['category', 'tags', 'author'])
|
||||
->byLanguage($lang)
|
||||
->orderBy('published_at', 'desc')
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
$latestCategories = Category::orderBy('created_at', 'desc')
|
||||
$latestCategories = Category::byLanguage($lang)
|
||||
->orderBy('created_at', 'desc')
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
$mostViewedPosts = Post::with(['category', 'tags', 'author'])
|
||||
->byLanguage($lang)
|
||||
->orderBy('views', 'desc')
|
||||
->take(5)
|
||||
->get();
|
||||
|
||||
$randomPosts = Post::with(['category', 'tags', 'author'])
|
||||
->byLanguage($lang)
|
||||
->inRandomOrder()
|
||||
->take(4)
|
||||
->get();
|
||||
|
||||
@@ -46,6 +46,7 @@ class PostController extends Controller
|
||||
);
|
||||
|
||||
$query = Post::with(['category', 'tags', 'author'])
|
||||
->byLanguage($request->input('lang'))
|
||||
->filter($filters)
|
||||
->sort($params['sort'], $params['direction']);
|
||||
|
||||
@@ -71,9 +72,19 @@ class PostController extends Controller
|
||||
->where('slug', $slug)
|
||||
->firstOrFail();
|
||||
|
||||
$postLang = str_ends_with($post->slug, '-fa') ? 'fa' : 'en';
|
||||
|
||||
$relatedPosts = $post->relatedPosts
|
||||
->filter(
|
||||
fn ($related) => str_ends_with($related->slug, '-fa')
|
||||
=== ($postLang === 'fa')
|
||||
)
|
||||
->sortByDesc('published_at')
|
||||
->take(5);
|
||||
|
||||
return response()->json([
|
||||
'post' => new PostResource($post),
|
||||
'related_posts' => PostResource::collection($post->relatedPosts->sortByDesc('published_at')->take(5)),
|
||||
'related_posts' => PostResource::collection($relatedPosts),
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class TagController extends Controller
|
||||
);
|
||||
|
||||
$tags = Tag::with('posts')
|
||||
->byLanguage($request->input('lang'))
|
||||
->orderBy($params['sort'], $params['direction'])
|
||||
->paginate($params['per_page']);
|
||||
|
||||
@@ -87,6 +88,8 @@ class TagController extends Controller
|
||||
|
||||
$postsQuery = $tag->posts()->with(['category', 'tags', 'author']);
|
||||
|
||||
$postsQuery->byLanguage($request->input('lang'));
|
||||
|
||||
if (! empty($filter)) {
|
||||
$postsQuery->where('title', 'like', '%'.$filter.'%');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user