@@ -50,8 +50,9 @@ public function stringFromSnippet(): Feed
50
50
return $ this ;
51
51
}
52
52
53
- // cache miss, load items now
53
+ // cache miss, load items and dynamic options now
54
54
$ this ->loadItems ();
55
+ $ this ->dynamicOptions ();
55
56
56
57
// render snippet with items in options
57
58
$ this ->string = trim (strval (snippet (A::get ($ this ->options , 'snippet ' ), $ this ->options , true )));
@@ -96,8 +97,14 @@ private function loadItems(): void
96
97
$ items = $ items ->sortBy ($ this ->options ['datefield ' ], 'desc ' );
97
98
}
98
99
$ this ->options ['items ' ] = $ items ;
100
+ }
101
+
102
+ private function dynamicOptions (): void
103
+ {
99
104
$ this ->options ['link ' ] = url ($ this ->options ['link ' ]);
100
105
106
+ /** @var Pages $items */
107
+ $ items = $ this ->options ['items ' ];
101
108
if ($ items ->count ()) {
102
109
$ modified = $ items ->first ()->modified ($ this ->options ['dateformat ' ], 'date ' );
103
110
$ this ->options ['modified ' ] = $ modified ;
@@ -116,19 +123,20 @@ public function response(): Response
116
123
$ snippet = A::get ($ this ->options , 'snippet ' );
117
124
$ mime = Mime::fromExtension (A::get ($ this ->options , 'mime ' , '' ));
118
125
126
+ $ response = null ;
119
127
if ($ mime !== null ) {
120
- return new Response ($ this ->string , $ mime );
128
+ $ response = new Response ($ this ->string , $ mime );
121
129
} elseif ($ snippet === 'feed/sitemap ' && Feed::isXml ($ this ->string )) {
122
- return new Response ($ this ->string , 'xml ' );
130
+ $ response = new Response ($ this ->string , 'xml ' );
123
131
} elseif ($ snippet === 'feed/atom ' && Feed::isXml ($ this ->string )) {
124
- return new Response ($ this ->string , 'xml ' );
132
+ $ response = new Response ($ this ->string , 'xml ' );
125
133
} elseif ($ snippet === 'feed/json ' && Feed::isJson ($ this ->string )) {
126
- return new Response ($ this ->string , 'json ' );
134
+ $ response = new Response ($ this ->string , 'json ' );
127
135
} elseif ($ snippet === 'feed/rss ' && Feed::isXml ($ this ->string )) {
128
- return new Response ($ this ->string , 'rss ' );
136
+ $ response = new Response ($ this ->string , 'rss ' );
129
137
}
130
138
131
- return new Response ('Error: Feed Response ' , null , 500 );
139
+ return $ response ?? new Response ('Error: Feed Response ' , null , 500 );
132
140
}
133
141
134
142
public static function feed (Pages |Closure $ pages , array $ options = []): Response
0 commit comments