Blog localization: lang-filtered API, strict EN/FA mirrored content, 12 new topics
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:
Parsa Aghayi committed 2026-10-02 08:27:20 -04:00
1 parent 21fa37af1f
commit 65415beae7
11 files changed
+904 -32

No files matched your search

@@ -25,9 +25,9 @@ class RealBlogContentSeederTest extends TestCase
$this->seed(RealBlogContentSeeder::class);
$this->assertSame(10, Category::count());
$this->assertSame(20, Tag::count());
$this->assertSame(12, Post::count());
$this->assertSame(12, Category::count());
$this->assertSame(26, Tag::count());
$this->assertSame(24, Post::count());
$post = Post::where('slug', 'core-web-vitals-practical-guide')->firstOrFail();
$this->assertSame($user->id, $post->author_id);
@@ -40,10 +40,21 @@ class RealBlogContentSeederTest extends TestCase
$faTwin = Post::where('slug', 'core-web-vitals-practical-guide-fa')->firstOrFail();
$this->assertNotNull($faTwin->published_at);
// English posts and their Persian twins are linked as related posts.
$this->assertTrue(
$post->relatedPosts()->where('related_posts.related_post_id', $faTwin->id)->exists()
);
// Strict English/Persian mirror: the two versions always cover exactly
// the same topics, so no post exists in only one language.
$englishCount = Post::where('slug', 'not like', '%-fa')->count();
$persianCount = Post::where('slug', 'like', '%-fa')->count();
$this->assertSame($englishCount, $persianCount);
foreach (Post::where('slug', 'not like', '%-fa')->pluck('slug') as $slug) {
$this->assertDatabaseHas('posts', ['slug' => $slug.'-fa']);
}
// Related posts stay inside the reader's language: the English version
// of a post never offers a Persian card and vice versa.
$this->assertGreaterThan(0, $post->relatedPosts()->count());
$this->assertSame(0, $post->relatedPosts()->where('slug', 'like', '%-fa')->count());
$this->assertSame(0, $faTwin->relatedPosts()->where('slug', 'not like', '%-fa')->count());
}
public function test_it_is_safe_to_run_twice(): void
@@ -53,8 +64,8 @@ class RealBlogContentSeederTest extends TestCase
$this->seed(RealBlogContentSeeder::class);
$this->seed(RealBlogContentSeeder::class);
$this->assertSame(10, Category::count());
$this->assertSame(20, Tag::count());
$this->assertSame(12, Post::count());
$this->assertSame(12, Category::count());
$this->assertSame(26, Tag::count());
$this->assertSame(24, Post::count());
}
}