From 6108f26a9e51343c3bef0b145aee1c7966703d28 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 20:24:20 +0200 Subject: [PATCH 01/35] Create RssFeedService.php --- src/Services/RssFeedService.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/Services/RssFeedService.php diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php new file mode 100644 index 00000000..13d17def --- /dev/null +++ b/src/Services/RssFeedService.php @@ -0,0 +1,9 @@ + Date: Wed, 18 May 2022 20:25:43 +0200 Subject: [PATCH 02/35] Add RssFeedService test file --- src/Services/RssFeedService.php | 5 ++++- .../SitemapServiceTest/RssFeedServiceTest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/Services/SitemapServiceTest/RssFeedServiceTest.php diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 13d17def..c8aee17d 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -2,8 +2,11 @@ namespace Hyde\Framework\Services; +/** + * @see \Tests\Feature\Services\RssFeedServiceTest + */ class RssFeedService { - + } diff --git a/tests/Feature/Services/SitemapServiceTest/RssFeedServiceTest.php b/tests/Feature/Services/SitemapServiceTest/RssFeedServiceTest.php new file mode 100644 index 00000000..e0149f92 --- /dev/null +++ b/tests/Feature/Services/SitemapServiceTest/RssFeedServiceTest.php @@ -0,0 +1,15 @@ + Date: Wed, 18 May 2022 20:44:42 +0200 Subject: [PATCH 03/35] Add the initial channel items --- src/Services/RssFeedService.php | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index c8aee17d..943121a7 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -2,11 +2,63 @@ namespace Hyde\Framework\Services; +use SimpleXMLElement; +use Hyde\Framework\Hyde; + /** * @see \Tests\Feature\Services\RssFeedServiceTest */ class RssFeedService { + public SimpleXMLElement $feed; + protected float $time_start; + + public function __construct() + { + $this->time_start = microtime(true); + + $this->feed = new SimpleXMLElement(''); + $this->feed->addAttribute('generator', 'HydePHP '.Hyde::version()); + $this->feed->addChild('channel'); + + $this->addInitialChannelItems(); + } + + public function generate(): self + { + // TODO: Implement generate() method. + + return $this; + } + + public function getXML(): string + { + $this->feed->addAttribute('processing_time_ms', (string) round((microtime(true) - $this->time_start) * 1000, 2)); + + return $this->feed->asXML(); + } + + protected function addInitialChannelItems(): void + { + $this->feed->channel->addChild('title', $this->getTitle()); + $this->feed->channel->addChild('link', $this->getLink()); + $this->feed->channel->addChild('description', $this->getDescription()); + } + + protected function getTitle(): string + { + return config('hyde.name', 'HydePHP'); + } + + protected function getLink(): string + { + return config('hyde.site_url') ?? 'http://localhost'; + } + protected function getDescription(): string + { + return config('hyde.rssDescription', + $this->getTitle() . ' RSS Feed'); + } } From 51d77ef4b88bf5ef968db40de25ee659d095f6a8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 20:47:07 +0200 Subject: [PATCH 04/35] Escape XML values --- src/Services/RssFeedService.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 943121a7..5433f7e1 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -47,18 +47,29 @@ protected function addInitialChannelItems(): void protected function getTitle(): string { - return config('hyde.name', 'HydePHP'); + return $this->xmlEscape( + config('hyde.name', 'HydePHP') + ); } protected function getLink(): string { - return config('hyde.site_url') ?? 'http://localhost'; + return $this->xmlEscape( + config('hyde.site_url') ?? 'http://localhost' + ); } protected function getDescription(): string { - return config('hyde.rssDescription', - $this->getTitle() . ' RSS Feed'); + return $this->xmlEscape( + config('hyde.rssDescription', + $this->getTitle() . ' RSS Feed') + ); + } + + protected function xmlEscape(string $string): string + { + return htmlspecialchars($string, ENT_XML1 | ENT_COMPAT, 'UTF-8'); } } From fd8b5cac7320e13794ee01e1fd68418d12162f36 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:10:49 +0200 Subject: [PATCH 05/35] Add note that site_url is required to use sitemaps and RSS feeds --- config/hyde.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/hyde.php b/config/hyde.php index fa863a6b..8c6bb5cc 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -44,6 +44,8 @@ | | Here are some configuration options for URL generation. | + | A site_url is required to use sitemaps and RSS feeds. + | | `site_url` is used to create canonical URLs and permalinks. | `prettyUrls` will when enabled create links that do not end in .html. | `generateSitemap` determines if a sitemap.xml file should be generated. From 6f887f2bdc7ff9adbde798f0550cbed4b645bbf0 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:15:06 +0200 Subject: [PATCH 06/35] Add helper to get canonical post links --- src/Models/MarkdownPost.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Models/MarkdownPost.php b/src/Models/MarkdownPost.php index 4a93c672..803a0044 100644 --- a/src/Models/MarkdownPost.php +++ b/src/Models/MarkdownPost.php @@ -6,6 +6,7 @@ use Hyde\Framework\Concerns\HasAuthor; use Hyde\Framework\Concerns\HasDateString; use Hyde\Framework\Concerns\HasFeaturedImage; +use Hyde\Framework\Hyde; use Hyde\Framework\Models\Parsers\MarkdownPostParser; class MarkdownPost extends MarkdownDocument @@ -36,4 +37,9 @@ public function getCurrentPagePath(): string { return 'posts/'.$this->slug; } + + public function getCanonicalLink(): string + { + return Hyde::uriPath(Hyde::pageLink($this->getCurrentPagePath().'.html')); + } } From 37b41b70868598b32d1adac7f9ede3a76e57a993 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:16:02 +0200 Subject: [PATCH 07/35] Add helper to get post description --- src/Models/MarkdownPost.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Models/MarkdownPost.php b/src/Models/MarkdownPost.php index 803a0044..fa558a4d 100644 --- a/src/Models/MarkdownPost.php +++ b/src/Models/MarkdownPost.php @@ -42,4 +42,9 @@ public function getCanonicalLink(): string { return Hyde::uriPath(Hyde::pageLink($this->getCurrentPagePath().'.html')); } + + public function getPostDescription(): string + { + return $this->matter['description'] ?? substr($this->body, 0, 125).'...'; + } } From 189c26c73dc33abc06a1c4bccb15c691d64e0e9e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:18:39 +0200 Subject: [PATCH 08/35] Add basic blog post items to the feed Currently only the required properties are implemented --- src/Services/RssFeedService.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 5433f7e1..b0871842 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -2,6 +2,7 @@ namespace Hyde\Framework\Services; +use Hyde\Framework\Models\MarkdownPost; use SimpleXMLElement; use Hyde\Framework\Hyde; @@ -26,7 +27,9 @@ public function __construct() public function generate(): self { - // TODO: Implement generate() method. + foreach (Hyde::getLatestPosts() as $post) { + $this->addItem($post); + } return $this; } @@ -38,6 +41,14 @@ public function getXML(): string return $this->feed->asXML(); } + protected function addItem(MarkdownPost $post): void + { + $item = $this->feed->channel->addChild('item'); + $item->addChild('title', $post->findTitleForDocument()); + $item->addChild('link', $post->getCanonicalLink()); + $item->addChild('description', $post->getPostDescription()); + } + protected function addInitialChannelItems(): void { $this->feed->channel->addChild('title', $this->getTitle()); From 77228a1c0bd4da1718753af22ab0dbb8e3bdd63e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:24:00 +0200 Subject: [PATCH 09/35] Add pubDate support in additional item data helper --- src/Services/RssFeedService.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index b0871842..63ee25c6 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -47,6 +47,15 @@ protected function addItem(MarkdownPost $post): void $item->addChild('title', $post->findTitleForDocument()); $item->addChild('link', $post->getCanonicalLink()); $item->addChild('description', $post->getPostDescription()); + + $this->addAdditionalItemData($item, $post); + } + + protected function addAdditionalItemData(SimpleXMLElement $item, MarkdownPost $post): void + { + if ($post->date) { + $item->addChild('pubDate', $post->date->dateTimeObject->format(DATE_RSS)); + } } protected function addInitialChannelItems(): void From 18c36dcb3b6bd2a3cea4055bfd11a2c59cb95cc4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:30:42 +0200 Subject: [PATCH 10/35] Add link to the RSS 2.0 spec --- src/Services/RssFeedService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 63ee25c6..ae7b8ea9 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -8,6 +8,8 @@ /** * @see \Tests\Feature\Services\RssFeedServiceTest + * + * @see https://validator.w3.org/feed/docs/rss2.html */ class RssFeedService { From 707c522a4e32526b2dac78056eaa799e2568fee7 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:35:18 +0200 Subject: [PATCH 11/35] Add getName() helper --- src/Models/Author.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Models/Author.php b/src/Models/Author.php index 9b126507..b27cc39b 100644 --- a/src/Models/Author.php +++ b/src/Models/Author.php @@ -47,4 +47,14 @@ public function __construct(string $username, ?array $data = []) $this->website = $data['website']; } } + + /** + * Get the author's name. + * + * @return string + */ + public function getName(): string + { + return $this->name ?? $this->username; + } } From 9158b3863ac029d6818c30ca8da4cf6919d3fb27 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:37:47 +0200 Subject: [PATCH 12/35] Add author property While this does not conform to the official spec (that requires an email) I think it is acceptable --- src/Services/RssFeedService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index ae7b8ea9..227ee089 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -58,6 +58,8 @@ protected function addAdditionalItemData(SimpleXMLElement $item, MarkdownPost $p if ($post->date) { $item->addChild('pubDate', $post->date->dateTimeObject->format(DATE_RSS)); } + + $item->addChild('author', $post->author->getName()); } protected function addInitialChannelItems(): void From 130d9cb75fd23279d91e3084cd40adddcad4b398 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 21:43:20 +0200 Subject: [PATCH 13/35] Wrap additional data in conditionals --- src/Services/RssFeedService.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 227ee089..8abef53b 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -55,11 +55,13 @@ protected function addItem(MarkdownPost $post): void protected function addAdditionalItemData(SimpleXMLElement $item, MarkdownPost $post): void { - if ($post->date) { + if (isset($post->date)) { $item->addChild('pubDate', $post->date->dateTimeObject->format(DATE_RSS)); } - $item->addChild('author', $post->author->getName()); + if (isset($post->author)) { + $item->addChild('author', $post->author->getName()); + } } protected function addInitialChannelItems(): void From 425c55b8766b7a4250e310785398a6fe5d638d74 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 22:13:19 +0200 Subject: [PATCH 14/35] Replace author with dc:creator Use the Creator property from Dublin Core Metadata Initiative instead of the author property requiring an email. --- src/Services/RssFeedService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 8abef53b..919d5067 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -60,7 +60,7 @@ protected function addAdditionalItemData(SimpleXMLElement $item, MarkdownPost $p } if (isset($post->author)) { - $item->addChild('author', $post->author->getName()); + $item->addChild('dc:creator', $post->author->getName(), 'http://purl.org/dc/elements/1.1/'); } } From 3902608c57af43eace4954dc34153fc62fd52705 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 22:26:16 +0200 Subject: [PATCH 15/35] Add additional channel data --- src/Services/RssFeedService.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 919d5067..ddd0fedd 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -21,7 +21,6 @@ public function __construct() $this->time_start = microtime(true); $this->feed = new SimpleXMLElement(''); - $this->feed->addAttribute('generator', 'HydePHP '.Hyde::version()); $this->feed->addChild('channel'); $this->addInitialChannelItems(); @@ -38,7 +37,7 @@ public function generate(): self public function getXML(): string { - $this->feed->addAttribute('processing_time_ms', (string) round((microtime(true) - $this->time_start) * 1000, 2)); + $this->feed->channel->generator->addAttribute('hyde:processing_time_ms', (string) round((microtime(true) - $this->time_start) * 1000, 2), 'hyde'); return $this->feed->asXML(); } @@ -69,6 +68,15 @@ protected function addInitialChannelItems(): void $this->feed->channel->addChild('title', $this->getTitle()); $this->feed->channel->addChild('link', $this->getLink()); $this->feed->channel->addChild('description', $this->getDescription()); + + $this->addAdditionalChannelData(); + } + + protected function addAdditionalChannelData(): void + { + $this->feed->channel->addChild('language', config('hyde.language', 'en')); + $this->feed->channel->addChild('generator', 'HydePHP '.Hyde::version()); + $this->feed->channel->addChild('lastBuildDate', date(DATE_RSS)); } protected function getTitle(): string From 7e862d8a6fe46de6cdfa8c89c92ab7812669c53c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 22:42:47 +0200 Subject: [PATCH 16/35] Add guid element to items --- src/Services/RssFeedService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index ddd0fedd..df0c4610 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -47,6 +47,7 @@ protected function addItem(MarkdownPost $post): void $item = $this->feed->channel->addChild('item'); $item->addChild('title', $post->findTitleForDocument()); $item->addChild('link', $post->getCanonicalLink()); + $item->addChild('guid', $post->getCanonicalLink()); $item->addChild('description', $post->getPostDescription()); $this->addAdditionalItemData($item, $post); From eb5c23e65e20ec4577ecefc8d2b155bbe5cabe16 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 22:44:00 +0200 Subject: [PATCH 17/35] Remove debug processing time --- src/Services/RssFeedService.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index df0c4610..697b11e3 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -14,12 +14,9 @@ class RssFeedService { public SimpleXMLElement $feed; - protected float $time_start; public function __construct() { - $this->time_start = microtime(true); - $this->feed = new SimpleXMLElement(''); $this->feed->addChild('channel'); @@ -37,8 +34,6 @@ public function generate(): self public function getXML(): string { - $this->feed->channel->generator->addAttribute('hyde:processing_time_ms', (string) round((microtime(true) - $this->time_start) * 1000, 2), 'hyde'); - return $this->feed->asXML(); } From eb98a73a0ffeec8d19577cbf0553acb4e28193dd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 22:55:05 +0200 Subject: [PATCH 18/35] Add Atom link --- src/Services/RssFeedService.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 697b11e3..bbcef864 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -17,7 +17,7 @@ class RssFeedService public function __construct() { - $this->feed = new SimpleXMLElement(''); + $this->feed = new SimpleXMLElement(''); $this->feed->addChild('channel'); $this->addInitialChannelItems(); @@ -65,6 +65,13 @@ protected function addInitialChannelItems(): void $this->feed->channel->addChild('link', $this->getLink()); $this->feed->channel->addChild('description', $this->getDescription()); + $atomLink = $this->feed->channel->addChild('atom:link', namespace: 'http://www.w3.org/2005/Atom'); + $atomLink->addAttribute('href', $this->getLink() . '/rss.xml'); + $atomLink->addAttribute('rel', 'self'); + $atomLink->addAttribute('type', 'application/rss+xml'); + + + $this->addAdditionalChannelData(); } From 024ce28d1415356e05ad66bf69efa5c56b70966f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 22:56:12 +0200 Subject: [PATCH 19/35] Add XML namespace to root element --- src/Services/RssFeedService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index bbcef864..d9acfb61 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -17,7 +17,7 @@ class RssFeedService public function __construct() { - $this->feed = new SimpleXMLElement(''); + $this->feed = new SimpleXMLElement(''); $this->feed->addChild('channel'); $this->addInitialChannelItems(); From 15bbf886ceb7f0f0a3e38b62abe6a42dce6ad4d9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 22:57:44 +0200 Subject: [PATCH 20/35] Add post category support --- src/Services/RssFeedService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index d9acfb61..928e35a6 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -57,6 +57,10 @@ protected function addAdditionalItemData(SimpleXMLElement $item, MarkdownPost $p if (isset($post->author)) { $item->addChild('dc:creator', $post->author->getName(), 'http://purl.org/dc/elements/1.1/'); } + + if (isset($post->category)) { + $item->addChild('category', $post->category); + } } protected function addInitialChannelItems(): void From b719b0fc1f08620aec7b6e096f6036feb0026846 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 18 May 2022 22:59:42 +0200 Subject: [PATCH 21/35] Formatting --- src/Services/RssFeedService.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 928e35a6..1a4452bb 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -17,7 +17,8 @@ class RssFeedService public function __construct() { - $this->feed = new SimpleXMLElement(''); + $this->feed = new SimpleXMLElement(' + '); $this->feed->addChild('channel'); $this->addInitialChannelItems(); @@ -74,8 +75,6 @@ protected function addInitialChannelItems(): void $atomLink->addAttribute('rel', 'self'); $atomLink->addAttribute('type', 'application/rss+xml'); - - $this->addAdditionalChannelData(); } From 0604d0e4a708a8f7c43eeae0493cc58b88cfeee1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 09:41:39 +0200 Subject: [PATCH 22/35] Support local image attributes --- src/Services/RssFeedService.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 1a4452bb..704d29d1 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -62,6 +62,14 @@ protected function addAdditionalItemData(SimpleXMLElement $item, MarkdownPost $p if (isset($post->category)) { $item->addChild('category', $post->category); } + + // Only support local images, as remote images would take extra time to make HTTP requests to get length + if (isset($post->image) && isset($post->image->path)) { + $image = $item->addChild('enclosure'); + $image->addAttribute('url' , Hyde::uriPath(str_replace('_media', 'media', $post->image->path))); + $image->addAttribute('type' , str_ends_with($post->image->path, '.png') ? 'image/png' : 'image/jpeg'); + $image->addAttribute('length' , filesize(Hyde::path($post->image->path))); + } } protected function addInitialChannelItems(): void From 956f307b6a5405b08b2bf0ea706d3952b948804f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 09:51:41 +0200 Subject: [PATCH 23/35] Fix test namespaces --- .../Services/{SitemapServiceTest => }/RssFeedServiceTest.php | 2 +- .../Services/{SitemapServiceTest => }/SitemapServiceTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename tests/Feature/Services/{SitemapServiceTest => }/RssFeedServiceTest.php (79%) rename tests/Feature/Services/{SitemapServiceTest => }/SitemapServiceTest.php (98%) diff --git a/tests/Feature/Services/SitemapServiceTest/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php similarity index 79% rename from tests/Feature/Services/SitemapServiceTest/RssFeedServiceTest.php rename to tests/Feature/Services/RssFeedServiceTest.php index e0149f92..21be4eee 100644 --- a/tests/Feature/Services/SitemapServiceTest/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -1,6 +1,6 @@ Date: Thu, 19 May 2022 10:02:42 +0200 Subject: [PATCH 24/35] Add type annotation --- src/Services/RssFeedService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 704d29d1..b5071d30 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -26,6 +26,7 @@ public function __construct() public function generate(): self { + /** @var MarkdownPost $post */ foreach (Hyde::getLatestPosts() as $post) { $this->addItem($post); } From a21596f68792d313c551789f713950a6c2410975 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 10:59:09 +0200 Subject: [PATCH 25/35] Add the RSSFeedService test --- tests/Feature/Services/RssFeedServiceTest.php | 118 +++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php index 21be4eee..558466be 100644 --- a/tests/Feature/Services/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -11,5 +11,121 @@ */ class RssFeedServiceTest extends TestCase { - + // Test service instantiates the XML element + public function test_service_instantiates_xml_element() + { + $service = new RssFeedService(); + $this->assertInstanceOf('SimpleXMLElement', $service->feed); + } + + // Test XML root element is set to RSS 2.0 + public function test_xml_root_element_is_set_to_rss_2_0() + { + $service = new RssFeedService(); + $this->assertEquals('rss', $service->feed->getName()); + $this->assertEquals('2.0', $service->feed->attributes()->version); + } + + // Test XML element has channel element + public function test_xml_element_has_channel_element() + { + $service = new RssFeedService(); + $this->assertObjectHasAttribute('channel', $service->feed); + } + + // Test XML channel element has required elements + public function test_xml_channel_element_has_required_elements() + { + config(['hyde.name' => 'Test Blog']); + config(['hyde.site_url' => 'https://example.com']); + + $service = new RssFeedService(); + $this->assertObjectHasAttribute('title', $service->feed->channel); + $this->assertObjectHasAttribute('link', $service->feed->channel); + $this->assertObjectHasAttribute('description', $service->feed->channel); + + $this->assertEquals('Test Blog', $service->feed->channel->title); + $this->assertEquals('https://example.com', $service->feed->channel->link); + $this->assertEquals('Test Blog RSS Feed', $service->feed->channel->description); + } + + // Test XML channel element has additional elements + public function test_xml_channel_element_has_additional_elements() + { + config(['hyde.site_url' => 'https://example.com']); + + $service = new RssFeedService(); + $this->assertObjectHasAttribute('link', $service->feed->channel); + $this->assertEquals('https://example.com', $service->feed->channel->link); + $this->assertEquals('https://example.com/rss.xml', + $service->feed->channel->children('atom', true)->link->attributes()->href); + + $this->assertObjectHasAttribute('language', $service->feed->channel); + $this->assertObjectHasAttribute('generator', $service->feed->channel); + $this->assertObjectHasAttribute('lastBuildDate', $service->feed->channel); + } + + // Test XML channel data can be customized + public function test_xml_channel_data_can_be_customized() + { + config(['hyde.name' => 'Foo']); + config(['hyde.site_url' => 'https://blog.foo.com/bar']); + config(['hyde.rssDescription' => 'Foo is a web log about stuff']); + + $service = new RssFeedService(); + $this->assertEquals('Foo', $service->feed->channel->title); + $this->assertEquals('https://blog.foo.com/bar', $service->feed->channel->link); + $this->assertEquals('Foo is a web log about stuff', $service->feed->channel->description); + } + + // Test Markdown blog posts are added to RSS feed through autodiscovery + public function test_markdown_blog_posts_are_added_to_rss_feed_through_autodiscovery() + { + file_put_contents(Hyde::path('_posts/rss.md'), <<<'MD' + --- + title: RSS + author: Hyde + date: "2022-05-19 10:15:30" + description: RSS description + category: test + image: rss-test.jpg + --- + + # RSS Post + + Foo bar + MD + ); + + config(['hyde.site_url' => 'https://example.com']); + + file_put_contents(Hyde::path('rss-test.jpg'), 'statData'); // 8 bytes to test stat gets file length + + $service = new RssFeedService(); + $service->generate(); + $this->assertCount(1, $service->feed->channel->item); + + $item = $service->feed->channel->item[0]; + $this->assertEquals('RSS', $item->title); + $this->assertEquals('RSS description', $item->description); + $this->assertEquals('https://example.com/posts/rss.html', $item->link); + $this->assertEquals(date(DATE_RSS, strtotime('2022-05-19T10:15:30+00:00')), $item->pubDate); + $this->assertEquals('Hyde', $item->children('dc', true)->creator); + $this->assertEquals('test', $item->category); + + $this->assertObjectHasAttribute('enclosure', $item); + $this->assertEquals('https://example.com/rss-test.jpg', $item->enclosure->attributes()->url); + $this->assertEquals('image/jpeg', $item->enclosure->attributes()->type); + $this->assertEquals('8', $item->enclosure->attributes()->length); + + unlink(Hyde::path('_posts/rss.md')); + unlink(Hyde::path('rss-test.jpg')); + } + + // Test getXML method returns XML string + public function test_getXML_method_returns_XML_string() + { + $service = new RssFeedService(); + $this->assertStringStartsWith('', ($service->getXML())); + } } From 856f59d284d64ce6c691c801b01c379038634e08 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 19 May 2022 08:59:22 +0000 Subject: [PATCH 26/35] Apply fixes from StyleCI --- src/Services/RssFeedService.php | 14 +++--- tests/Feature/Services/RssFeedServiceTest.php | 50 +++++++++---------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index b5071d30..9c71909f 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -2,13 +2,12 @@ namespace Hyde\Framework\Services; +use Hyde\Framework\Hyde; use Hyde\Framework\Models\MarkdownPost; use SimpleXMLElement; -use Hyde\Framework\Hyde; /** * @see \Tests\Feature\Services\RssFeedServiceTest - * * @see https://validator.w3.org/feed/docs/rss2.html */ class RssFeedService @@ -67,9 +66,9 @@ protected function addAdditionalItemData(SimpleXMLElement $item, MarkdownPost $p // Only support local images, as remote images would take extra time to make HTTP requests to get length if (isset($post->image) && isset($post->image->path)) { $image = $item->addChild('enclosure'); - $image->addAttribute('url' , Hyde::uriPath(str_replace('_media', 'media', $post->image->path))); - $image->addAttribute('type' , str_ends_with($post->image->path, '.png') ? 'image/png' : 'image/jpeg'); - $image->addAttribute('length' , filesize(Hyde::path($post->image->path))); + $image->addAttribute('url', Hyde::uriPath(str_replace('_media', 'media', $post->image->path))); + $image->addAttribute('type', str_ends_with($post->image->path, '.png') ? 'image/png' : 'image/jpeg'); + $image->addAttribute('length', filesize(Hyde::path($post->image->path))); } } @@ -80,7 +79,7 @@ protected function addInitialChannelItems(): void $this->feed->channel->addChild('description', $this->getDescription()); $atomLink = $this->feed->channel->addChild('atom:link', namespace: 'http://www.w3.org/2005/Atom'); - $atomLink->addAttribute('href', $this->getLink() . '/rss.xml'); + $atomLink->addAttribute('href', $this->getLink().'/rss.xml'); $atomLink->addAttribute('rel', 'self'); $atomLink->addAttribute('type', 'application/rss+xml'); @@ -112,7 +111,7 @@ protected function getDescription(): string { return $this->xmlEscape( config('hyde.rssDescription', - $this->getTitle() . ' RSS Feed') + $this->getTitle().' RSS Feed') ); } @@ -121,4 +120,3 @@ protected function xmlEscape(string $string): string return htmlspecialchars($string, ENT_XML1 | ENT_COMPAT, 'UTF-8'); } } - diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php index 558466be..1229035c 100644 --- a/tests/Feature/Services/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -11,43 +11,43 @@ */ class RssFeedServiceTest extends TestCase { - // Test service instantiates the XML element - public function test_service_instantiates_xml_element() + // Test service instantiates the XML element + public function test_service_instantiates_xml_element() { $service = new RssFeedService(); $this->assertInstanceOf('SimpleXMLElement', $service->feed); } - // Test XML root element is set to RSS 2.0 - public function test_xml_root_element_is_set_to_rss_2_0() - { - $service = new RssFeedService(); - $this->assertEquals('rss', $service->feed->getName()); - $this->assertEquals('2.0', $service->feed->attributes()->version); - } - - // Test XML element has channel element - public function test_xml_element_has_channel_element() - { - $service = new RssFeedService(); - $this->assertObjectHasAttribute('channel', $service->feed); - } - - // Test XML channel element has required elements - public function test_xml_channel_element_has_required_elements() - { + // Test XML root element is set to RSS 2.0 + public function test_xml_root_element_is_set_to_rss_2_0() + { + $service = new RssFeedService(); + $this->assertEquals('rss', $service->feed->getName()); + $this->assertEquals('2.0', $service->feed->attributes()->version); + } + + // Test XML element has channel element + public function test_xml_element_has_channel_element() + { + $service = new RssFeedService(); + $this->assertObjectHasAttribute('channel', $service->feed); + } + + // Test XML channel element has required elements + public function test_xml_channel_element_has_required_elements() + { config(['hyde.name' => 'Test Blog']); config(['hyde.site_url' => 'https://example.com']); $service = new RssFeedService(); - $this->assertObjectHasAttribute('title', $service->feed->channel); - $this->assertObjectHasAttribute('link', $service->feed->channel); - $this->assertObjectHasAttribute('description', $service->feed->channel); + $this->assertObjectHasAttribute('title', $service->feed->channel); + $this->assertObjectHasAttribute('link', $service->feed->channel); + $this->assertObjectHasAttribute('description', $service->feed->channel); $this->assertEquals('Test Blog', $service->feed->channel->title); $this->assertEquals('https://example.com', $service->feed->channel->link); $this->assertEquals('Test Blog RSS Feed', $service->feed->channel->description); - } + } // Test XML channel element has additional elements public function test_xml_channel_element_has_additional_elements() @@ -103,7 +103,7 @@ public function test_markdown_blog_posts_are_added_to_rss_feed_through_autodisco $service = new RssFeedService(); $service->generate(); - $this->assertCount(1, $service->feed->channel->item); + $this->assertCount(1, $service->feed->channel->item); $item = $service->feed->channel->item[0]; $this->assertEquals('RSS', $item->title); From 53786cd06ce52b9bce57c6b71a360c347abb9aed Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 11:01:56 +0200 Subject: [PATCH 27/35] Make the feed filename configurable --- src/Services/RssFeedService.php | 7 ++++++- tests/Feature/Services/RssFeedServiceTest.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index b5071d30..319aadf5 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -80,7 +80,7 @@ protected function addInitialChannelItems(): void $this->feed->channel->addChild('description', $this->getDescription()); $atomLink = $this->feed->channel->addChild('atom:link', namespace: 'http://www.w3.org/2005/Atom'); - $atomLink->addAttribute('href', $this->getLink() . '/rss.xml'); + $atomLink->addAttribute('href', $this->getLink() . '/' . static::getDefaultOutputFilename()); $atomLink->addAttribute('rel', 'self'); $atomLink->addAttribute('type', 'application/rss+xml'); @@ -120,5 +120,10 @@ protected function xmlEscape(string $string): string { return htmlspecialchars($string, ENT_XML1 | ENT_COMPAT, 'UTF-8'); } + + public static function getDefaultOutputFilename(): string + { + return config('hyde.rssFilename', 'feed.rss'); + } } diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php index 558466be..640634f7 100644 --- a/tests/Feature/Services/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -57,7 +57,7 @@ public function test_xml_channel_element_has_additional_elements() $service = new RssFeedService(); $this->assertObjectHasAttribute('link', $service->feed->channel); $this->assertEquals('https://example.com', $service->feed->channel->link); - $this->assertEquals('https://example.com/rss.xml', + $this->assertEquals('https://example.com/feed.rss', $service->feed->channel->children('atom', true)->link->attributes()->href); $this->assertObjectHasAttribute('language', $service->feed->channel); From ff452114c3e5efd56c62ee4d11ad4018a412ed9f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 19 May 2022 09:02:41 +0000 Subject: [PATCH 28/35] Apply fixes from StyleCI --- src/Services/RssFeedService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 18fb59de..bfaab7cb 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -79,7 +79,7 @@ protected function addInitialChannelItems(): void $this->feed->channel->addChild('description', $this->getDescription()); $atomLink = $this->feed->channel->addChild('atom:link', namespace: 'http://www.w3.org/2005/Atom'); - $atomLink->addAttribute('href', $this->getLink() . '/' . static::getDefaultOutputFilename()); + $atomLink->addAttribute('href', $this->getLink().'/'.static::getDefaultOutputFilename()); $atomLink->addAttribute('rel', 'self'); $atomLink->addAttribute('type', 'application/rss+xml'); From 7f71154e54a0a76b3eee86093a97de4aa9e06459 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 11:11:56 +0200 Subject: [PATCH 29/35] Add static canGenerateFeed helper --- src/Services/RssFeedService.php | 5 +++++ tests/Feature/Services/RssFeedServiceTest.php | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index bfaab7cb..1be01c45 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -124,4 +124,9 @@ public static function getDefaultOutputFilename(): string { return config('hyde.rssFilename', 'feed.rss'); } + + public static function canGenerateFeed(): bool + { + return (Hyde::uriPath() !== false) && config('hyde.generateRssFeed', true); + } } diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php index a1e43a17..540fe7b9 100644 --- a/tests/Feature/Services/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -128,4 +128,24 @@ public function test_getXML_method_returns_XML_string() $service = new RssFeedService(); $this->assertStringStartsWith('', ($service->getXML())); } + + + public function test_can_generate_sitemap_helper_returns_true_if_hyde_has_base_url() + { + config(['hyde.site_url' => 'foo']); + $this->assertTrue(RssFeedService::canGenerateFeed()); + } + + public function test_can_generate_sitemap_helper_returns_false_if_hyde_does_not_have_base_url() + { + config(['hyde.site_url' => '']); + $this->assertFalse(RssFeedService::canGenerateFeed()); + } + + public function test_can_generate_sitemap_helper_returns_false_if_sitemaps_are_disabled_in_config() + { + config(['hyde.site_url' => 'foo']); + config(['hyde.generateRssFeed' => false]); + $this->assertFalse(RssFeedService::canGenerateFeed()); + } } From fa389b084e3041ad55a5e57092922d366e0e4189 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 11:15:07 +0200 Subject: [PATCH 30/35] Add static generateFeed helper --- src/Services/RssFeedService.php | 5 +++++ tests/Feature/Services/RssFeedServiceTest.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/Services/RssFeedService.php b/src/Services/RssFeedService.php index 1be01c45..dc93228f 100644 --- a/src/Services/RssFeedService.php +++ b/src/Services/RssFeedService.php @@ -125,6 +125,11 @@ public static function getDefaultOutputFilename(): string return config('hyde.rssFilename', 'feed.rss'); } + public static function generateFeed(): string + { + return (new static)->generate()->getXML(); + } + public static function canGenerateFeed(): bool { return (Hyde::uriPath() !== false) && config('hyde.generateRssFeed', true); diff --git a/tests/Feature/Services/RssFeedServiceTest.php b/tests/Feature/Services/RssFeedServiceTest.php index 540fe7b9..5e8dca27 100644 --- a/tests/Feature/Services/RssFeedServiceTest.php +++ b/tests/Feature/Services/RssFeedServiceTest.php @@ -129,6 +129,11 @@ public function test_getXML_method_returns_XML_string() $this->assertStringStartsWith('', ($service->getXML())); } + // Test generateFeed helper returns XML string + public function test_generateFeed_helper_returns_XML_string() + { + $this->assertStringStartsWith('', (RssFeedService::generateFeed())); + } public function test_can_generate_sitemap_helper_returns_true_if_hyde_has_base_url() { From 83ca387ef987d53ccd3ce3baaedded90f3e56118 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 11:19:15 +0200 Subject: [PATCH 31/35] Generate RSS feed after build process --- src/Commands/HydeBuildStaticSiteCommand.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index 8735a840..c96a6444 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -13,6 +13,7 @@ use Hyde\Framework\Models\MarkdownPage; use Hyde\Framework\Models\MarkdownPost; use Hyde\Framework\Services\DiscoveryService; +use Hyde\Framework\Services\RssFeedService; use Hyde\Framework\Services\SitemapService; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\File; @@ -176,6 +177,13 @@ public function postBuildActions(): void file_put_contents(Hyde::getSiteOutputPath('sitemap.xml'), SitemapService::generateSitemap()); $this->newLine(); } + + if (RssFeedService::canGenerateFeed()) { + $this->info('Generating RSS feed'); + + file_put_contents(Hyde::getSiteOutputPath(RssFeedService::getDefaultOutputFilename()), RssFeedService::generateFeed()); + $this->newLine(); + } } /** @internal */ From 5f1b137192a79f7cca97cef4cf56fd857333458f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 11:30:45 +0200 Subject: [PATCH 32/35] Add better action information output --- src/Commands/HydeBuildStaticSiteCommand.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index c96a6444..b0a44de0 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -173,16 +173,17 @@ public function postBuildActions(): void } if (SitemapService::canGenerateSitemap()) { - $this->info('Generating sitemap.xml'); + $actionTime = microtime(true); + $this->comment('Generating sitemap...'); file_put_contents(Hyde::getSiteOutputPath('sitemap.xml'), SitemapService::generateSitemap()); - $this->newLine(); + $this->line(' > Created sitemap.xml in ' .$this->getExecutionTimeInMs($actionTime)."ms\n"); } if (RssFeedService::canGenerateFeed()) { - $this->info('Generating RSS feed'); - + $actionTime = microtime(true); + $this->comment('Generating RSS feed...'); file_put_contents(Hyde::getSiteOutputPath(RssFeedService::getDefaultOutputFilename()), RssFeedService::generateFeed()); - $this->newLine(); + $this->line(' > Created '.RssFeedService::getDefaultOutputFilename().' in ' .$this->getExecutionTimeInMs($actionTime)."ms\n"); } } @@ -206,4 +207,9 @@ private function runNodeCommand(string $command, string $message, ?string $actio $output ?? 'Could not '.($actionMessage ?? 'run script').'! Is NPM installed?' ); } + + protected function getExecutionTimeInMs(float $timeStart): float + { + return number_format(((microtime(true) - $timeStart) * 1000), 2); + } } From fe93f5b7cd1dea1f3bbb5a851b8185e5288f50de Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 11:38:45 +0200 Subject: [PATCH 33/35] Update sitemap tests and add rss feed tests --- .../Commands/BuildStaticSiteCommandTest.php | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/Feature/Commands/BuildStaticSiteCommandTest.php b/tests/Feature/Commands/BuildStaticSiteCommandTest.php index 9cecfe37..49e812d6 100644 --- a/tests/Feature/Commands/BuildStaticSiteCommandTest.php +++ b/tests/Feature/Commands/BuildStaticSiteCommandTest.php @@ -112,10 +112,37 @@ public function test_sitemap_is_generated_when_conditions_are_met() unlinkIfExists(Hyde::path('_site/sitemap.xml')); $this->artisan('build') - ->expectsOutput('Generating sitemap.xml') + ->expectsOutput('Generating sitemap...') ->assertExitCode(0); $this->assertFileExists(Hyde::path('_site/sitemap.xml')); + unlink(Hyde::path('_site/sitemap.xml')); + } + + public function test_rss_feed_is_not_generated_when_conditions_are_not_met() + { + config(['hyde.site_url' => '']); + config(['hyde.generateRssFeed' => false]); + + unlinkIfExists(Hyde::path('_site/feed.rss')); + $this->artisan('build') + ->assertExitCode(0); + + $this->assertFileDoesNotExist(Hyde::path('_site/feed.rss')); + } + + public function test_rss_feed_is_generated_when_conditions_are_met() + { + config(['hyde.site_url' => 'https://example.com']); + config(['hyde.generateRssFeed' => true]); + + unlinkIfExists(Hyde::path('_site/feed.rss')); + $this->artisan('build') + ->expectsOutput('Generating RSS feed...') + ->assertExitCode(0); + + $this->assertFileExists(Hyde::path('_site/feed.rss')); + unlink(Hyde::path('_site/feed.rss')); } /** From dde4a60de98fcfdf17c82d8abe280c5d96be27ec Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 19 May 2022 09:38:59 +0000 Subject: [PATCH 34/35] Apply fixes from StyleCI --- src/Commands/HydeBuildStaticSiteCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/HydeBuildStaticSiteCommand.php b/src/Commands/HydeBuildStaticSiteCommand.php index b0a44de0..65c68519 100644 --- a/src/Commands/HydeBuildStaticSiteCommand.php +++ b/src/Commands/HydeBuildStaticSiteCommand.php @@ -176,14 +176,14 @@ public function postBuildActions(): void $actionTime = microtime(true); $this->comment('Generating sitemap...'); file_put_contents(Hyde::getSiteOutputPath('sitemap.xml'), SitemapService::generateSitemap()); - $this->line(' > Created sitemap.xml in ' .$this->getExecutionTimeInMs($actionTime)."ms\n"); + $this->line(' > Created sitemap.xml in '.$this->getExecutionTimeInMs($actionTime)."ms\n"); } if (RssFeedService::canGenerateFeed()) { $actionTime = microtime(true); $this->comment('Generating RSS feed...'); file_put_contents(Hyde::getSiteOutputPath(RssFeedService::getDefaultOutputFilename()), RssFeedService::generateFeed()); - $this->line(' > Created '.RssFeedService::getDefaultOutputFilename().' in ' .$this->getExecutionTimeInMs($actionTime)."ms\n"); + $this->line(' > Created '.RssFeedService::getDefaultOutputFilename().' in '.$this->getExecutionTimeInMs($actionTime)."ms\n"); } } From 2ceb60dcd0292331e5bfe5e8c277c4e70a027336 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 19 May 2022 11:47:39 +0200 Subject: [PATCH 35/35] Test that RSS filename can be changed --- .../Commands/BuildStaticSiteCommandTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Feature/Commands/BuildStaticSiteCommandTest.php b/tests/Feature/Commands/BuildStaticSiteCommandTest.php index 49e812d6..28c662bf 100644 --- a/tests/Feature/Commands/BuildStaticSiteCommandTest.php +++ b/tests/Feature/Commands/BuildStaticSiteCommandTest.php @@ -145,6 +145,24 @@ public function test_rss_feed_is_generated_when_conditions_are_met() unlink(Hyde::path('_site/feed.rss')); } + public function test_rss_filename_can_be_changed() + { + config(['hyde.site_url' => 'https://example.com']); + config(['hyde.generateRssFeed' => true]); + config(['hyde.rssFilename' => 'blog.xml']); + + unlinkIfExists(Hyde::path('_site/feed.rss')); + unlinkIfExists(Hyde::path('_site/blog.xml')); + + $this->artisan('build') + ->expectsOutput('Generating RSS feed...') + ->assertExitCode(0); + + $this->assertFileDoesNotExist(Hyde::path('_site/feed.rss')); + $this->assertFileExists(Hyde::path('_site/blog.xml')); + unlink(Hyde::path('_site/blog.xml')); + } + /** * Added for code coverage, deprecated as the pretty flag is deprecated. *