atom feed added

This commit is contained in:
HolgerHatGarKeineNode
2023-02-15 20:32:37 +01:00
parent be04341d02
commit ae2dc8571c
7 changed files with 194 additions and 10 deletions

View File

@@ -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);
}
}

View File

@@ -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",

95
composer.lock generated
View File

@@ -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",

55
config/feed.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
return [
'feeds' => [
'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 <link> 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' => '',
],
],
];

View File

@@ -9,6 +9,7 @@
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
@stack('feeds')
{!! seo($SEOData ?? null) !!}
<!-- Fonts -->
@googlefonts

View File

@@ -1,4 +1,7 @@
<div class="bg-21gray flex flex-col h-screen justify-between">
@push('feeds')
<x-feed-links />
@endpush
<livewire:frontend.header :country="null"/>
<div class="relative bg-21gray px-6 pt-2 pb-20 lg:px-8 lg:pt-2 lg:pb-2">
<div class="absolute inset-0">

View File

@@ -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();