88use Librarian \ContentType ;
99use Librarian \Exception \ContentNotFoundException ;
1010use Librarian \Provider \ContentServiceProvider ;
11+ use Librarian \Provider \FeedServiceProvider ;
1112use Librarian \Provider \TwigServiceProvider ;
1213use Minicli \App ;
1314use Minicli \Config ;
@@ -23,13 +24,15 @@ class StaticBuilder implements ServiceInterface
2324{
2425 public Config $ siteConfig ;
2526 public ContentServiceProvider $ contentProvider ;
27+ public FeedServiceProvider $ feedProvider ;
2628 public TwigServiceProvider $ twigServiceProvider ;
2729 public string $ outputPath ;
2830 public int $ postsPerPage ;
2931
3032 public function load (App $ app ): void
3133 {
3234 $ this ->contentProvider = $ app ->content ;
35+ $ this ->feedProvider = $ app ->feed ;
3336 $ this ->twigServiceProvider = $ app ->twig ;
3437 $ this ->siteConfig = $ app ->config ;
3538 $ this ->outputPath = $ this ->siteConfig ->output_path ;
@@ -204,37 +207,9 @@ public function getSinglePage(Content $content): string
204207
205208 public function buildRssFeed (): void
206209 {
207- $ feed = new Feed ();
208- $ channel = new Channel ();
209- $ channel
210- ->title ($ this ->siteConfig ->site_name )
211- ->description ($ this ->siteConfig ->site_description )
212- ->url ($ this ->siteConfig ->site_url )
213- ->feedUrl ($ this ->siteConfig ->site_url . '/feed.rss ' )
214- ->language ('en-US ' )
215- ->copyright ('Copyright ' . date ('Y ' ) . ', ' . $ this ->siteConfig ->site_name )
216- ->pubDate (strtotime (date ('Y-m-d H:i:s ' )))
217- ->lastBuildDate (strtotime (date ('Y-m-d H:i:s ' )))
218- ->ttl (60 )
219- ->appendTo ($ feed );
220-
221- $ content_list = $ this ->contentProvider ->fetchAll ();
222-
223- /** @var Content $content */
224- foreach ($ content_list as $ content ) {
225- $ item = new Item ();
226- $ item
227- ->title ($ content ->frontMatterGet ('title ' ) ?? $ content ->default_title )
228- ->description ('<div> ' .($ content ->frontMatterGet ('description ' ) ?? $ content ->description ).'</div> ' )
229- ->contentEncoded ('<div> ' .($ content ->frontMatterGet ('description ' ) ?? '' ).'</div> ' )
230- ->url ($ this ->siteConfig ->site_url . '/ ' . $ content ->getLink ())
231- ->author ($ this ->siteConfig ->site_author )
232- ->pubDate (strtotime ($ content ->getDate ()))
233- ->guid ($ this ->siteConfig ->site_url . '/ ' . $ content ->getLink (), true )
234- ->preferCdata (true ) // By this, title and description become CDATA wrapped HTML.
235- ->appendTo ($ channel );
236- }
210+ $ feed = $ this ->feedProvider ->buildFeed (is_static: true );
211+ $ customFeedPath = $ this ->feedProvider ->getCustomFeedPath (is_static: true );
237212
238- $ this ->saveFile ($ this ->outputPath . ' /feed.rss ' , $ feed );
213+ $ this ->saveFile ($ this ->outputPath . $ customFeedPath , $ feed );
239214 }
240215}
0 commit comments