@@ -50,8 +50,9 @@ public function stringFromSnippet(): Feed
5050 return $ this ;
5151 }
5252
53- // cache miss, load items now
53+ // cache miss, load items and dynamic options now
5454 $ this ->loadItems ();
55+ $ this ->dynamicOptions ();
5556
5657 // render snippet with items in options
5758 $ this ->string = trim (strval (snippet (A::get ($ this ->options , 'snippet ' ), $ this ->options , true )));
@@ -96,8 +97,14 @@ private function loadItems(): void
9697 $ items = $ items ->sortBy ($ this ->options ['datefield ' ], 'desc ' );
9798 }
9899 $ this ->options ['items ' ] = $ items ;
100+ }
101+
102+ private function dynamicOptions (): void
103+ {
99104 $ this ->options ['link ' ] = url ($ this ->options ['link ' ]);
100105
106+ /** @var Pages $items */
107+ $ items = $ this ->options ['items ' ];
101108 if ($ items ->count ()) {
102109 $ modified = $ items ->first ()->modified ($ this ->options ['dateformat ' ], 'date ' );
103110 $ this ->options ['modified ' ] = $ modified ;
@@ -116,19 +123,20 @@ public function response(): Response
116123 $ snippet = A::get ($ this ->options , 'snippet ' );
117124 $ mime = Mime::fromExtension (A::get ($ this ->options , 'mime ' , '' ));
118125
126+ $ response = null ;
119127 if ($ mime !== null ) {
120- return new Response ($ this ->string , $ mime );
128+ $ response = new Response ($ this ->string , $ mime );
121129 } elseif ($ snippet === 'feed/sitemap ' && Feed::isXml ($ this ->string )) {
122- return new Response ($ this ->string , 'xml ' );
130+ $ response = new Response ($ this ->string , 'xml ' );
123131 } elseif ($ snippet === 'feed/atom ' && Feed::isXml ($ this ->string )) {
124- return new Response ($ this ->string , 'xml ' );
132+ $ response = new Response ($ this ->string , 'xml ' );
125133 } elseif ($ snippet === 'feed/json ' && Feed::isJson ($ this ->string )) {
126- return new Response ($ this ->string , 'json ' );
134+ $ response = new Response ($ this ->string , 'json ' );
127135 } elseif ($ snippet === 'feed/rss ' && Feed::isXml ($ this ->string )) {
128- return new Response ($ this ->string , 'rss ' );
136+ $ response = new Response ($ this ->string , 'rss ' );
129137 }
130138
131- return new Response ('Error: Feed Response ' , null , 500 );
139+ return $ response ?? new Response ('Error: Feed Response ' , null , 500 );
132140 }
133141
134142 public static function feed (Pages |Closure $ pages , array $ options = []): Response
0 commit comments