Expand blog to 36 mirrored posts with deepened sections and page-turn links
Deploy Backend / deploy (push) Successful in 2m35s

- Six new topic pairs (EN+FA): TypeScript advanced patterns, SQL indexes,
  Git branching/reviews, TDD, clean architecture in Laravel, browser page load
- Every existing post gains Key takeaways + FAQ sections in both languages
- New engineering-practices category pair and database/git/testing tag pairs
- Single-post API now returns same-language previous_post/next_post links
This commit is contained in:
Parsa Aghayi committed 2026-10-02 09:34:53 -04:00
1 parent d659c5d325
commit fbacb0c9a1
4 files changed
+1377 -9

No files matched your search

@@ -82,9 +82,43 @@ class PostController extends Controller
->sortByDesc('published_at')
->take(5);
// Plainly named page-turn links, always inside the reader's language so
// the previous/next navigation never crosses the EN/FA mirror.
$siblings = Post::with(['category', 'tags', 'author'])
->byLanguage($postLang)
->where('id', '!=', $post->id);
$previousPost = (clone $siblings)
->where(
fn ($q) => $q->where('published_at', '>', $post->published_at)
->orWhere(
fn ($q2) => $q2
->where('published_at', '=', $post->published_at)
->where('id', '>', $post->id)
)
)
->orderByDesc('published_at')
->orderByDesc('id')
->first();
$nextPost = (clone $siblings)
->where(
fn ($q) => $q->where('published_at', '<', $post->published_at)
->orWhere(
fn ($q2) => $q2
->where('published_at', '=', $post->published_at)
->where('id', '<', $post->id)
)
)
->orderBy('published_at')
->orderBy('id')
->first();
return response()->json([
'post' => new PostResource($post),
'related_posts' => PostResource::collection($relatedPosts),
'previous_post' => $previousPost ? new PostResource($previousPost) : null,
'next_post' => $nextPost ? new PostResource($nextPost) : null,
], 200);
}
File diff suppressed because it is too large. Load diff
+24 -1
View File
@@ -28,7 +28,30 @@ class PostTest extends TestCase
$response = $this->getJson("/api/blog/posts/{$post->slug}");
$response->assertStatus(200)
->assertJsonStructure(['post', 'related_posts']);
->assertJsonStructure(['post', 'related_posts', 'previous_post', 'next_post']);
}
public function test_page_turn_links_stay_inside_the_reader_language()
{
Post::factory()->create(['slug' => 'older-topic', 'published_at' => now()->subDays(2)]);
Post::factory()->create(['slug' => 'older-topic-fa', 'published_at' => now()->subDays(2)]);
Post::factory()->create(['slug' => 'newer-topic', 'published_at' => now()->addDay()]);
Post::factory()->create(['slug' => 'newer-topic-fa', 'published_at' => now()->addDay()]);
$current = Post::factory()->create(['slug' => 'current-topic', 'published_at' => now()]);
$currentFa = Post::factory()->create(['slug' => 'current-topic-fa', 'published_at' => now()]);
$response = $this->getJson("/api/blog/posts/{$current->slug}");
$response->assertStatus(200)
->assertJsonPath('previous_post.slug', 'newer-topic')
->assertJsonPath('next_post.slug', 'older-topic')
->assertJsonMissing(['previous_post' => ['slug' => 'newer-topic-fa']]);
$response = $this->getJson("/api/blog/posts/{$currentFa->slug}");
$response->assertStatus(200)
->assertJsonPath('previous_post.slug', 'newer-topic-fa')
->assertJsonPath('next_post.slug', 'older-topic-fa');
}
public function test_can_create_post()
@@ -25,9 +25,9 @@ class RealBlogContentSeederTest extends TestCase
$this->seed(RealBlogContentSeeder::class);
$this->assertSame(12, Category::count());
$this->assertSame(26, Tag::count());
$this->assertSame(24, Post::count());
$this->assertSame(14, Category::count());
$this->assertSame(32, Tag::count());
$this->assertSame(36, Post::count());
$post = Post::where('slug', 'core-web-vitals-practical-guide')->firstOrFail();
$this->assertSame($user->id, $post->author_id);
@@ -40,16 +40,27 @@ class RealBlogContentSeederTest extends TestCase
$faTwin = Post::where('slug', 'core-web-vitals-practical-guide-fa')->firstOrFail();
$this->assertNotNull($faTwin->published_at);
// Strict English/Persian mirror: the two versions always cover exactly
// the same topics, so no post exists in only one language.
// Every English post and every new topic pair resolve their Persian twin:
// the strict English/Persian mirror now spans 18 posts per language.
$englishCount = Post::where('slug', 'not like', '%-fa')->count();
$persianCount = Post::where('slug', 'like', '%-fa')->count();
$this->assertSame($englishCount, $persianCount);
$this->assertSame(18, $englishCount);
foreach (Post::where('slug', 'not like', '%-fa')->pluck('slug') as $slug) {
$this->assertDatabaseHas('posts', ['slug' => $slug.'-fa']);
}
// Deepened editing: every article ends with Key takeaways + FAQ sections
// in both languages, plus the new engineering-practices category pair.
foreach (Post::pluck('body') as $body) {
$this->assertStringContainsString('## FAQ', $body);
}
$this->assertDatabaseHas('categories', ['slug' => 'engineering-practices']);
$this->assertDatabaseHas('categories', ['slug' => 'engineering-practices-fa']);
$this->assertDatabaseHas('posts', ['slug' => 'typescript-advanced-patterns']);
$this->assertDatabaseHas('posts', ['slug' => 'typescript-advanced-patterns-fa']);
// featured_image is a VARCHAR(255) column; the generated og-image URLs
// must never overrun it, or the seeder fails in production.
foreach (Post::pluck('featured_image') as $image) {
@@ -71,8 +82,8 @@ class RealBlogContentSeederTest extends TestCase
$this->seed(RealBlogContentSeeder::class);
$this->seed(RealBlogContentSeeder::class);
$this->assertSame(12, Category::count());
$this->assertSame(26, Tag::count());
$this->assertSame(24, Post::count());
$this->assertSame(14, Category::count());
$this->assertSame(32, Tag::count());
$this->assertSame(36, Post::count());
}
}