Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only enable support files when there are related pages #448

Merged
7 changes: 6 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ This serves two purposes:

### Changed
- Renamed HydeSmartDocs.php to SemanticDocumentationArticle.php
- The RSS feed related generators are now only enabled when there are blog posts
- This means that no feed.xml will be generated, nor will there be any references (like meta tags) to it when there are no blog posts
- The documentation search related generators are now only enabled when there are documentation pages
- This means that no search.json nor search.html nor any references to them will be generated when there are no documentation pages

### Deprecated
- for soon-to-be removed features.
Expand All @@ -22,7 +26,8 @@ This serves two purposes:
- for now removed features.

### Fixed
- for any bug fixes.
- Fixed [#443](https://github.com/hydephp/develop/issues/443): RSS feed meta link should not be added if there is not a feed


### Security
- in case of vulnerabilities.
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,11 @@ protected function canGenerateSitemap(): bool

protected function canGenerateFeed(): bool
{
return Features::rss()
&& count(DiscoveryService::getMarkdownPostFiles()) > 0;
return Features::rss();
}

protected function canGenerateSearch(): bool
{
return Features::hasDocumentationSearch()
&& count(DiscoveryService::getDocumentationPageFiles()) > 0;
return Features::hasDocumentationSearch();
}
}
7 changes: 5 additions & 2 deletions packages/framework/src/Helpers/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Hyde\Framework\Concerns\JsonSerializesArrayable;
use Hyde\Framework\Hyde;
use Hyde\Framework\Services\DiscoveryService;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -76,7 +77,8 @@ public static function hasDataCollections(): bool
public static function hasDocumentationSearch(): bool
{
return static::enabled(static::documentationSearch())
&& static::hasDocumentationPages();
&& static::hasDocumentationPages()
&& count(DiscoveryService::getDocumentationPageFiles()) > 0;
}

public static function hasDarkmode(): bool
Expand Down Expand Up @@ -157,7 +159,8 @@ public static function rss(): bool
return Hyde::hasSiteUrl()
&& static::hasBlogPosts()
&& config('hyde.generate_rss_feed', true)
&& extension_loaded('simplexml');
&& extension_loaded('simplexml')
&& count(DiscoveryService::getMarkdownPostFiles()) > 0;
}

/** @inheritDoc */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function test_rss_feed_is_generated_when_conditions_are_met()
{
config(['site.url' => 'https://example.com']);
config(['hyde.generate_rss_feed' => true]);
$this->file('_posts/foo.md');

unlinkIfExists(Hyde::path('_site/feed.xml'));
$this->artisan('build:rss')
Expand All @@ -43,6 +44,7 @@ public function test_rss_filename_can_be_changed()
config(['site.url' => 'https://example.com']);
config(['hyde.generate_rss_feed' => true]);
config(['hyde.rss_filename' => 'blog.xml']);
$this->file('_posts/foo.md');

unlinkIfExists(Hyde::path('_site/feed.xml'));
unlinkIfExists(Hyde::path('_site/blog.xml'));
Expand Down
5 changes: 5 additions & 0 deletions packages/framework/tests/Feature/MetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public function test_automatically_adds_rss_feed_when_enabled()
{
config(['site.url' => 'foo']);
config(['hyde.generate_rss_feed' => true]);
$this->file('_posts/foo.md');

$page = new MarkdownPage();

Expand All @@ -245,6 +246,7 @@ public function test_rss_feed_uses_configured_site_url()
{
config(['site.url' => 'bar']);
config(['hyde.generate_rss_feed' => true]);
$this->file('_posts/foo.md');

$page = new MarkdownPage();

Expand All @@ -256,6 +258,7 @@ public function test_rss_feed_uses_configured_site_name()
config(['site.url' => 'foo']);
config(['site.name' => 'Site']);
config(['hyde.generate_rss_feed' => true]);
$this->file('_posts/foo.md');

$page = new MarkdownPage();

Expand All @@ -267,6 +270,8 @@ public function test_rss_feed_uses_configured_rss_file_name()
config(['site.url' => 'foo']);
config(['hyde.rss_filename' => 'posts.rss']);
config(['hyde.generate_rss_feed' => true]);
$this->file('_posts/foo.md');

$page = new MarkdownPage();

$this->assertStringContainsString(
Expand Down
3 changes: 2 additions & 1 deletion packages/framework/tests/Feature/MetadataViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ protected function getDefaultTags(): array
'<meta name="viewport" content="width=device-width, initial-scale=1">',
'<meta id="meta-color-scheme" name="color-scheme" content="light">',
'<link rel="sitemap" href="http://localhost/sitemap.xml" type="application/xml" title="Sitemap">',
'<link rel="alternate" href="http://localhost/feed.xml" type="application/rss+xml" title="HydePHP RSS Feed">',
'<meta name="generator" content="HydePHP dev-master">',
'<meta property="og:site_name" content="HydePHP">',
];
Expand Down Expand Up @@ -135,6 +134,7 @@ public function test_metadata_tags_in_empty_markdown_post()

$assertions = $this->assertSee('posts/test', array_merge($this->getDefaultTags(), [
'<title>HydePHP - Test</title>',
'<link rel="alternate" href="http://localhost/feed.xml" type="application/rss+xml" title="HydePHP RSS Feed">',
'<link rel="stylesheet" href="../media/app.css">',
'<link rel="canonical" href="http://localhost/posts/test.html">',
'<meta name="twitter:title" content="HydePHP - Test">',
Expand Down Expand Up @@ -171,6 +171,7 @@ public function test_metadata_tags_in_markdown_post_with_flat_front_matter()

$assertions = $this->assertSee('posts/test', array_merge($this->getDefaultTags(), [
'<title>HydePHP - My title</title>',
'<link rel="alternate" href="http://localhost/feed.xml" type="application/rss+xml" title="HydePHP RSS Feed">',
'<link rel="stylesheet" href="../media/app.css">',
'<link rel="canonical" href="http://localhost/posts/test.html">',
'<meta name="twitter:title" content="HydePHP - My title">',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,21 @@ public function test_generate_feed_helper_returns_xml_string()
$this->assertStringStartsWith('<?xml version="1.0" encoding="UTF-8"?>', (RssFeedService::generateFeed()));
}

public function test_can_generate_sitemap_helper_returns_true_if_hyde_has_base_url()
public function test_can_generate_feed_helper_returns_true_if_hyde_has_base_url()
{
config(['site.url' => 'foo']);
$this->file('_posts/foo.md');
$this->assertTrue(Features::rss());
}

public function test_can_generate_sitemap_helper_returns_false_if_hyde_does_not_have_base_url()
public function test_can_generate_feed_helper_returns_false_if_hyde_does_not_have_base_url()
{
config(['site.url' => '']);
$this->file('_posts/foo.md');
$this->assertFalse(Features::rss());
}

public function test_can_generate_sitemap_helper_returns_false_if_sitemaps_are_disabled_in_config()
public function test_can_generate_feed_helper_returns_false_if_feeds_are_disabled_in_config()
{
config(['site.url' => 'foo']);
config(['hyde.generate_rss_feed' => false]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public function test_navigation_menu_label_can_be_changed_in_front_matter()
title: "My custom title"
---
');
Hyde::boot();

$this->artisan('rebuild _pages/foo.md');
$this->assertStringContainsString('My custom title', file_get_contents(Hyde::path('_site/foo.html')));
Hyde::unlink('_site/foo.html');
Expand All @@ -71,6 +73,7 @@ public function test_navigation_menu_label_can_be_changed_in_blade_matter()
@php($navigation = ['title' => 'My custom title'])
BLADE
);
Hyde::boot();

$this->artisan('rebuild _pages/foo.blade.php');
$this->assertStringContainsString('My custom title', file_get_contents(Hyde::path('_site/foo.html')));
Expand Down