diff --git a/app/Models/LibraryItem.php b/app/Models/LibraryItem.php index c487883f..30adc9d6 100644 --- a/app/Models/LibraryItem.php +++ b/app/Models/LibraryItem.php @@ -9,6 +9,8 @@ use Illuminate\Support\Facades\Cookie; use Spatie\Comments\Models\Concerns\HasComments; use Spatie\EloquentSortable\Sortable; use Spatie\EloquentSortable\SortableTrait; +use Spatie\Feed\Feedable; +use Spatie\Feed\FeedItem; use Spatie\Image\Manipulations; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; @@ -18,7 +20,7 @@ use Spatie\Sluggable\HasSlug; use Spatie\Sluggable\SlugOptions; use Spatie\Tags\HasTags; -class LibraryItem extends Model implements HasMedia, Sortable +class LibraryItem extends Model implements HasMedia, Sortable, Feedable { use InteractsWithMedia; use HasTags; @@ -43,6 +45,17 @@ class LibraryItem extends Model implements HasMedia, Sortable 'library_id' => 'integer', ]; + public static function getFeedItems() + { + return self::query() + ->with([ + 'lecturer', + ]) + ->where('news', true) + ->where('approved', true) + ->get(); + } + protected static function booted() { static::creating(function ($model) { @@ -78,7 +91,10 @@ class LibraryItem extends Model implements HasMedia, Sortable ->singleFile() ->useFallbackUrl(asset('img/einundzwanzig.png')); $this->addMediaCollection('single_file') - ->acceptsMimeTypes(['application/pdf', 'application/zip', 'application/octet-stream', 'application/x-zip-compressed', 'multipart/x-zip']) + ->acceptsMimeTypes([ + 'application/pdf', 'application/zip', 'application/octet-stream', 'application/x-zip-compressed', + 'multipart/x-zip' + ]) ->singleFile(); $this->addMediaCollection('images') ->useFallbackUrl(asset('img/einundzwanzig.png')); @@ -99,24 +115,26 @@ class LibraryItem extends Model implements HasMedia, Sortable return $this->belongsTo(Episode::class); } + /* + * This string will be used in notifications on what a new comment + * was made. + */ + public function libraries(): BelongsToMany { return $this->belongsToMany(Library::class); } /* - * This string will be used in notifications on what a new comment - * was made. + * This URL will be used in notifications to let the user know + * where the comment itself can be read. */ + public function commentableName(): string { return __('Library Item'); } - /* - * This URL will be used in notifications to let the user know - * where the comment itself can be read. - */ public function commentUrl(): string { if ($this->type === 'markdown_article') { @@ -125,4 +143,16 @@ class LibraryItem extends Model implements HasMedia, Sortable return url()->route('libraryItem.view', ['libraryItem' => $this]); } } + + public function toFeedItem(): FeedItem + { + return FeedItem::create() + ->id($this->id) + ->title($this->name) + ->summary($this->excerpt) + ->updated($this->updated_at) + ->link($this->link) + ->image($this->getFirstMediaUrl('main')) + ->authorName($this->lecturer->name); + } } diff --git a/composer.json b/composer.json index 14b06f9d..66d4ffa3 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "spatie/laravel-ciphersweet": "^1.0", "spatie/laravel-comments": "^1.4", "spatie/laravel-comments-livewire": "^1.2", + "spatie/laravel-feed": "^4.2", "spatie/laravel-google-fonts": "^1.2", "spatie/laravel-markdown": "^2.2", "spatie/laravel-medialibrary": "^10.0.0", diff --git a/composer.lock b/composer.lock index 2f8f62e0..7b1ad6ea 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7bfd9957a6ea50d4bad46bd722c049fa", + "content-hash": "c2ef61f66ba7add8a14c0a78564b82c7", "packages": [ { "name": "akuechler/laravel-geoly", @@ -8771,6 +8771,99 @@ ], "time": "2023-01-26T12:47:09+00:00" }, + { + "name": "spatie/laravel-feed", + "version": "4.2.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-feed.git", + "reference": "0b9b7df3f716c6067b082cd6a985126c2189a6c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-feed/zipball/0b9b7df3f716c6067b082cd6a985126c2189a6c4", + "reference": "0b9b7df3f716c6067b082cd6a985126c2189a6c4", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^8.0|^9.0|^10.0", + "illuminate/http": "^8.0|^9.0|^10.0", + "illuminate/support": "^8.0|^9.0|^10.0", + "php": "^8.0", + "spatie/laravel-package-tools": "^1.9" + }, + "require-dev": { + "orchestra/testbench": "^6.23|^7.0|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5", + "spatie/pest-plugin-snapshots": "^1.1", + "spatie/test-time": "^1.2" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\Feed\\FeedServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\Feed\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jolita Grazyte", + "email": "jolita@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Sebastian De Deyne", + "email": "sebastian@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Patrick Organ", + "homepage": "https://github.com/patinthehat", + "role": "Developer" + } + ], + "description": "Generate rss feeds", + "homepage": "https://github.com/spatie/laravel-feed", + "keywords": [ + "laravel", + "laravel-feed", + "rss", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/laravel-feed/tree/4.2.1" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-01-25T09:39:38+00:00" + }, { "name": "spatie/laravel-google-fonts", "version": "1.2.3", diff --git a/config/feed.php b/config/feed.php new file mode 100644 index 00000000..9dda878b --- /dev/null +++ b/config/feed.php @@ -0,0 +1,55 @@ + [ + 'main' => [ + /* + * Here you can specify which class and method will return + * the items that should appear in the feed. For example: + * [App\Model::class, 'getAllFeedItems'] + * + * You can also pass an argument to that method. Note that their key must be the name of the parameter: + * [App\Model::class, 'getAllFeedItems', 'parameterName' => 'argument'] + */ + 'items' => [\App\Models\LibraryItem::class, 'getFeedItems'], + + /* + * The feed will be available on this url. + */ + 'url' => 'feed', + + 'title' => 'Einundzwanzig - Feed', + 'description' => 'Toximalist infotainment for bullish bitcoiners.', + 'language' => 'de', + + /* + * The image to display for the feed. For Atom feeds, this is displayed as + * a banner/logo; for RSS and JSON feeds, it's displayed as an icon. + * An empty value omits the image attribute from the feed. + */ + 'image' => '', + + /* + * The format of the feed. Acceptable values are 'rss', 'atom', or 'json'. + */ + 'format' => 'atom', + + /* + * The view that will render the feed. + */ + 'view' => 'feed::atom', + + /* + * The mime type to be used in the tag. Set to an empty string to automatically + * determine the correct value. + */ + 'type' => '', + + /* + * The content type for the feed response. Set to an empty string to automatically + * determine the correct value. + */ + 'contentType' => '', + ], + ], +]; diff --git a/resources/views/layouts/guest.blade.php b/resources/views/layouts/guest.blade.php index d3d7af74..9d1a8d68 100644 --- a/resources/views/layouts/guest.blade.php +++ b/resources/views/layouts/guest.blade.php @@ -9,6 +9,7 @@ + @stack('feeds') {!! seo($SEOData ?? null) !!} @googlefonts diff --git a/resources/views/livewire/news/article-overview.blade.php b/resources/views/livewire/news/article-overview.blade.php index 5ec11ee6..080bac6e 100644 --- a/resources/views/livewire/news/article-overview.blade.php +++ b/resources/views/livewire/news/article-overview.blade.php @@ -1,4 +1,7 @@
+ @push('feeds') + + @endpush
diff --git a/routes/web.php b/routes/web.php index 392be933..3e10cad8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -39,7 +39,6 @@ Route::middleware([ ->name('form'); }); - /* * Content Creator * */ @@ -258,3 +257,5 @@ Route::middleware([ Route::get('/meetup-osm/item/{meetup}', \App\Http\Livewire\Meetup\PrepareForBtcMapItem::class) ->name('osm.meetups.item'); }); + +Route::feeds();