Hide draft articles from the front page and mark drafts when viewed directly
Add an Article::published() scope and use it on the front page (which previously showed drafts), the /blog listing and the feeds. Draft articles are still reachable at their URL, but now show a draft notice, a "[Draft]" title prefix and a noindex robots meta tag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
eb35a0aa2d
commit
a31c218784
2 changed files with 84 additions and 7 deletions
|
|
@ -29,6 +29,39 @@ class ArticlesTest extends TestCase
|
|||
$response->assertViewIs('articles.show');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function articles_page_does_not_list_drafts(): void
|
||||
{
|
||||
Article::factory()->create(['title' => 'Published Article']);
|
||||
Article::factory()->create(['title' => 'Draft Article', 'published' => 0]);
|
||||
|
||||
$this->get('/blog')
|
||||
->assertSee('Published Article')
|
||||
->assertDontSee('Draft Article');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function draft_article_is_viewable_and_marked_as_draft(): void
|
||||
{
|
||||
$article = Article::factory()->create(['published' => 0]);
|
||||
|
||||
$this->get($article->link)
|
||||
->assertOk()
|
||||
->assertSee('draft-notice', false)
|
||||
->assertSee('<meta name="robots" content="noindex, nofollow">', false)
|
||||
->assertSee('<title>[Draft] ', false);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function published_article_is_not_marked_as_draft(): void
|
||||
{
|
||||
$article = Article::factory()->create();
|
||||
|
||||
$this->get($article->link)
|
||||
->assertDontSee('draft-notice', false)
|
||||
->assertDontSee('noindex', false);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function wrong_date_in_url_redirects_to_correct_date()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,4 +31,15 @@ class FrontPageTest extends TestCase
|
|||
->assertSee('https://example.com')
|
||||
->assertSee('Like 1');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function front_page_does_not_show_draft_articles(): void
|
||||
{
|
||||
Article::factory()->create(['title' => 'Published Article']);
|
||||
Article::factory()->create(['title' => 'Draft Article', 'published' => 0]);
|
||||
|
||||
$this->get('/')
|
||||
->assertSee('Published Article')
|
||||
->assertDontSee('Draft Article');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue