Skip to content

Commit 66110bf

Browse files
authored
Allow customizing RSS feed title & description (#4501)
1 parent 22d2ba4 commit 66110bf

29 files changed

Lines changed: 270 additions & 1 deletion

app/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@ class Kernel extends HttpKernel
110110
'album_cache_refresher' => \App\Http\Middleware\Caching\AlbumRouteCacheRefresher::class,
111111
'legacy_id_redirect' => \App\Http\Middleware\LegacyLocalIdRedirect::class,
112112
'feature' => \App\Http\Middleware\FeatureEnabled::class,
113+
'rss_feed_meta' => \App\Http\Middleware\SetRssFeedMeta::class,
113114
];
114115
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2026 LycheeOrg.
7+
*/
8+
9+
namespace App\Http\Middleware;
10+
11+
use Illuminate\Http\Request;
12+
13+
/**
14+
* Injects the admin-configured RSS feed title/description into the
15+
* spatie/laravel-feed config at request time.
16+
*
17+
* The spatie FeedController reads the feed config before it invokes our
18+
* RSSController, so the override cannot happen inside the controller and must
19+
* run here, before the feed is built. A blank setting is ignored so that the
20+
* static defaults in config/feed.php remain in effect.
21+
*/
22+
class SetRssFeedMeta
23+
{
24+
/**
25+
* Handle an incoming request.
26+
*
27+
* @param \Illuminate\Http\Request $request
28+
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
29+
*
30+
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
31+
*/
32+
public function handle(Request $request, \Closure $next)
33+
{
34+
$configs = $request->configs();
35+
36+
if ($configs->hasKey('rss_title')) {
37+
$title = $configs->getValueAsString('rss_title');
38+
if ($title !== '') {
39+
config(['feed.feeds.main.title' => $title]);
40+
}
41+
}
42+
43+
if ($configs->hasKey('rss_description')) {
44+
$description = $configs->getValueAsString('rss_description');
45+
if ($description !== '') {
46+
config(['feed.feeds.main.description' => $description]);
47+
}
48+
}
49+
50+
return $next($request);
51+
}
52+
}

config/feed.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
// ? Correct value should be '/feed'
2222
'url' => '/feed',
2323

24+
// These are the defaults. They are overridden per-request by the
25+
// SetRssFeedMeta middleware when the admin sets the `rss_title` /
26+
// `rss_description` config, so editing them here only affects installs
27+
// that leave those settings blank.
2428
'title' => 'Latest pictures',
2529
'description' => 'Latest added pictures.',
2630
'language' => 'en-US',
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* SPDX-License-Identifier: MIT
5+
* Copyright (c) 2017-2018 Tobias Reich
6+
* Copyright (c) 2018-2026 LycheeOrg.
7+
*/
8+
9+
use App\Models\Extensions\BaseConfigMigration;
10+
11+
return new class() extends BaseConfigMigration {
12+
public const MOD_RSS = 'Mod RSS';
13+
14+
public function getConfigs(): array
15+
{
16+
return [
17+
[
18+
'key' => 'rss_title',
19+
// Empty means "use the default": the middleware only overrides the
20+
// feed channel title when this is non-empty, so config/feed.php stays
21+
// the single source of truth for the default. See SetRssFeedMeta.
22+
'value' => '',
23+
'cat' => self::MOD_RSS,
24+
'type_range' => self::STRING,
25+
'description' => 'Feed Title',
26+
'details' => 'Shown as the channel title in the RSS feed. Leave blank to use the default.',
27+
'is_secret' => false,
28+
'is_expert' => false,
29+
'level' => 0,
30+
'order' => 3,
31+
],
32+
[
33+
'key' => 'rss_description',
34+
// Empty means "use the default"; see the note on rss_title above.
35+
'value' => '',
36+
'cat' => self::MOD_RSS,
37+
'type_range' => self::STRING,
38+
'description' => 'Feed Description',
39+
'details' => 'Shown as the channel description in the RSS feed. Leave blank to use the default.',
40+
'is_secret' => false,
41+
'is_expert' => false,
42+
'level' => 0,
43+
'order' => 4,
44+
],
45+
];
46+
}
47+
};

lang/ar/all_settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
'rss_enable' => 'Enable RSS feed',
7777
'rss_recent_days' => 'Display the last X days in the RSS feed',
7878
'rss_max_items' => 'Max number of items in the RSS feed',
79+
'rss_title' => 'Feed Title',
80+
'rss_description' => 'Feed Description',
7981
'prefer_available_xmp_metadata' => 'Use sidecar if provided instead of exif metadata',
8082
'editor_enabled' => 'Enable manual rotation of images',
8183
'lossless_optimization' => 'Apply additional compression on images',
@@ -442,6 +444,8 @@
442444
'rss_enable' => '',
443445
'rss_recent_days' => '',
444446
'rss_max_items' => '',
447+
'rss_title' => 'Shown as the channel title in the RSS feed. Leave blank to use the default.',
448+
'rss_description' => 'Shown as the channel description in the RSS feed. Leave blank to use the default.',
445449
'prefer_available_xmp_metadata' => '',
446450
'editor_enabled' => '',
447451
'lossless_optimization' => '',

lang/bg/all_settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
'rss_enable' => 'Активиране на RSS емисия',
7575
'rss_recent_days' => 'Показване на последните X дни в RSS емисията',
7676
'rss_max_items' => 'Максимален брой елементи в RSS емисията',
77+
'rss_title' => 'Feed Title',
78+
'rss_description' => 'Feed Description',
7779
'prefer_available_xmp_metadata' => 'Използване на sidecar файл, ако е наличен, вместо exif метаданни',
7880
'editor_enabled' => 'Активиране на ръчно завъртане на изображения',
7981
'lossless_optimization' => 'Прилагане на допълнителна компресия върху изображенията',
@@ -440,6 +442,8 @@
440442
'rss_enable' => '',
441443
'rss_recent_days' => '',
442444
'rss_max_items' => '',
445+
'rss_title' => 'Shown as the channel title in the RSS feed. Leave blank to use the default.',
446+
'rss_description' => 'Shown as the channel description in the RSS feed. Leave blank to use the default.',
443447
'prefer_available_xmp_metadata' => '',
444448
'editor_enabled' => '',
445449
'lossless_optimization' => '',

lang/cz/all_settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
'rss_enable' => 'Enable RSS feed',
7777
'rss_recent_days' => 'Display the last X days in the RSS feed',
7878
'rss_max_items' => 'Max number of items in the RSS feed',
79+
'rss_title' => 'Feed Title',
80+
'rss_description' => 'Feed Description',
7981
'prefer_available_xmp_metadata' => 'Use sidecar if provided instead of exif metadata',
8082
'editor_enabled' => 'Enable manual rotation of images',
8183
'lossless_optimization' => 'Apply additional compression on images',
@@ -442,6 +444,8 @@
442444
'rss_enable' => '',
443445
'rss_recent_days' => '',
444446
'rss_max_items' => '',
447+
'rss_title' => 'Shown as the channel title in the RSS feed. Leave blank to use the default.',
448+
'rss_description' => 'Shown as the channel description in the RSS feed. Leave blank to use the default.',
445449
'prefer_available_xmp_metadata' => '',
446450
'editor_enabled' => '',
447451
'lossless_optimization' => '',

lang/de/all_settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
'rss_enable' => 'RSS-Feed aktivieren',
7575
'rss_recent_days' => 'Die letzten X Tage im RSS-Feed anzeigen',
7676
'rss_max_items' => 'Maximale Anzahl an Einträgen im RSS-Feed',
77+
'rss_title' => 'Feed Title',
78+
'rss_description' => 'Feed Description',
7779
'prefer_available_xmp_metadata' => 'XMP-Sidecar-Dateien gegenüber EXIF-Metadaten bevorzugen',
7880
'editor_enabled' => 'Manuelles Drehen von Bildern aktivieren',
7981
'lossless_optimization' => 'Zusätzliche verlustfreie Kompression auf Bilder anwenden',
@@ -440,6 +442,8 @@
440442
'rss_enable' => '',
441443
'rss_recent_days' => '',
442444
'rss_max_items' => '',
445+
'rss_title' => 'Shown as the channel title in the RSS feed. Leave blank to use the default.',
446+
'rss_description' => 'Shown as the channel description in the RSS feed. Leave blank to use the default.',
443447
'prefer_available_xmp_metadata' => '',
444448
'editor_enabled' => '',
445449
'lossless_optimization' => '',

lang/el/all_settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
'rss_enable' => 'Enable RSS feed',
7777
'rss_recent_days' => 'Display the last X days in the RSS feed',
7878
'rss_max_items' => 'Max number of items in the RSS feed',
79+
'rss_title' => 'Feed Title',
80+
'rss_description' => 'Feed Description',
7981
'prefer_available_xmp_metadata' => 'Use sidecar if provided instead of exif metadata',
8082
'editor_enabled' => 'Enable manual rotation of images',
8183
'lossless_optimization' => 'Apply additional compression on images',
@@ -442,6 +444,8 @@
442444
'rss_enable' => '',
443445
'rss_recent_days' => '',
444446
'rss_max_items' => '',
447+
'rss_title' => 'Shown as the channel title in the RSS feed. Leave blank to use the default.',
448+
'rss_description' => 'Shown as the channel description in the RSS feed. Leave blank to use the default.',
445449
'prefer_available_xmp_metadata' => '',
446450
'editor_enabled' => '',
447451
'lossless_optimization' => '',

lang/en/all_settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
'rss_enable' => 'Enable RSS feed',
7777
'rss_recent_days' => 'Display the last X days in the RSS feed',
7878
'rss_max_items' => 'Max number of items in the RSS feed',
79+
'rss_title' => 'Feed Title',
80+
'rss_description' => 'Feed Description',
7981
'prefer_available_xmp_metadata' => 'Use sidecar if provided instead of exif metadata',
8082
'editor_enabled' => 'Enable manual rotation of images',
8183
'lossless_optimization' => 'Apply additional compression on images',
@@ -442,6 +444,8 @@
442444
'rss_enable' => '',
443445
'rss_recent_days' => '',
444446
'rss_max_items' => '',
447+
'rss_title' => 'Shown as the channel title in the RSS feed. Leave blank to use the default.',
448+
'rss_description' => 'Shown as the channel description in the RSS feed. Leave blank to use the default.',
445449
'prefer_available_xmp_metadata' => '',
446450
'editor_enabled' => '',
447451
'lossless_optimization' => '',

0 commit comments

Comments
 (0)