Skip to content

Commit 246ac25

Browse files
Added presets
1 parent 79c94ae commit 246ac25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1212
-562
lines changed

docs/laravel-feeds.tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
<toc-element topic="receipt-sitemap.topic" />
3131
<toc-element topic="receipt-instagram.topic" />
3232
<toc-element topic="receipt-yandex.topic" />
33+
<toc-element topic="receipt-rss-atom.topic" />
3334
</toc-element>
3435
</instance-profile>

docs/snippets/receipt-instagram-feed-item.php

Lines changed: 0 additions & 68 deletions
This file was deleted.

docs/snippets/receipt-instagram-feed.php

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,46 @@
44

55
namespace App\Feeds;
66

7-
use App\Feeds\Items\InstagramFeedItem;
8-
use App\Models\Product;
9-
use DragonCode\LaravelFeed\Data\ElementData;
10-
use DragonCode\LaravelFeed\Feeds\Feed;
117
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
8+
use DragonCode\LaravelFeed\Presets\InstagramFeedPreset;
129
use Illuminate\Database\Eloquent\Builder;
1310
use Illuminate\Database\Eloquent\Model;
11+
use App\Models\Product;
1412

15-
class InstagramFeed extends Feed
13+
class InstagramFeed extends InstagramFeedPreset
1614
{
1715
public function builder(): Builder
1816
{
1917
return Product::query();
2018
}
2119

22-
public function root(): ElementData
23-
{
24-
return new ElementData('offers');
25-
}
26-
27-
public function header(): string
28-
{
29-
$name = config('app.name');
30-
$url = config('app.url');
31-
32-
return <<<XML
33-
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
34-
<channel>
35-
<title>$name</title>
36-
<link>$url</link>
37-
38-
XML;
39-
}
40-
41-
public function footer(): string
42-
{
43-
return "\n</channel>\n</rss>";
44-
}
45-
4620
public function item(Model $model): FeedItem
4721
{
48-
return new InstagramFeedItem($model);
22+
return parent::item($model)
23+
->title($model->title)
24+
->description($model->description)
25+
->brand($model->brand)
26+
->url(route('products.show', $model->slug))
27+
->price($model->price)
28+
->image(array_first($model->images))
29+
->images($model->images)
30+
->availability($model->quantity > 0 ? 'in stock' : 'out of stock')
31+
->status($model->quantity > 0 ? 'active' : 'inactive')
32+
->additional([
33+
'g:foo' => 'Some foo',
34+
'g:bar' => 'Some bar',
35+
36+
'g:baz' => [
37+
'@attributes' => ['qwe' => 'rty'],
38+
'@value' => 'Some baz',
39+
],
40+
41+
'@g:arrayable' => [
42+
'a',
43+
'b',
44+
'c',
45+
],
46+
]);
4947
}
5048

5149
public function filename(): string

docs/snippets/receipt-instagram-feed.xml

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,45 @@
66

77
<item>
88
<g:id>1</g:id>
9-
<g:title><![CDATA[eaque nulla recusandae aliquid]]></g:title>
10-
<g:description><![CDATA[Atque sunt illum qui omnis eos. Sunt iste nisi quidem ut vitae. In quas est totam eius accusantium deserunt eaque. Ea repellat perspiciatis vel aut cumque illo. In et voluptas at eos.]]></g:description>
11-
<g:link>https://example.com/products/qui-enim-minima-aut-similique-id-nihil-voluptatem</g:link>
12-
<g:image_link>https://via.placeholder.com/640x480.png/00ffaa?text=natus</g:image_link>
13-
<g:additional_image_link>https://via.placeholder.com/640x480.png/0099cc?text=nobis</g:additional_image_link>
14-
<g:additional_image_link>https://via.placeholder.com/640x480.png/006611?text=qui</g:additional_image_link>
15-
<g:brand>suscipit</g:brand>
9+
<g:title><![CDATA[Some 1]]></g:title>
10+
<g:description><![CDATA[Some description 1]]></g:description>
11+
<g:link>https://example.com/products/ullam-animi-ipsum-expedita-exercitationem-id-neque</g:link>
12+
<g:image_link>https://via.placeholder.com/640x480.png/008877?text=repudiandae</g:image_link>
13+
<g:additional_image_link>https://via.placeholder.com/640x480.png/008877?text=repudiandae</g:additional_image_link>
14+
<g:brand>The Best</g:brand>
1615
<g:condition>new</g:condition>
1716
<g:availability>in stock</g:availability>
18-
<g:price>980</g:price>
19-
<g:sale_price>980</g:sale_price>
20-
<g:item_group_id>12345</g:item_group_id>
17+
<g:price>100</g:price>
18+
<g:sale_price>100</g:sale_price>
2119
<g:status>active</g:status>
22-
<g:color><![CDATA[PaleGoldenRod]]></g:color>
23-
<g:size>13</g:size>
24-
<g:age_group>adult</g:age_group>
25-
<g:material><![CDATA[modi]]></g:material>
26-
<g:pattern><![CDATA[regular]]></g:pattern>
27-
<g:google_product_category>1000</g:google_product_category>
28-
<g:fb_product_category>2000</g:fb_product_category>
20+
<g:foo>Some foo</g:foo>
21+
<g:bar>Some bar</g:bar>
22+
<g:baz qwe="rty">Some baz</g:baz>
23+
<g:arrayable>a</g:arrayable>
24+
<g:arrayable>b</g:arrayable>
25+
<g:arrayable>c</g:arrayable>
2926
</item>
3027
<item>
3128
<g:id>2</g:id>
32-
<g:title><![CDATA[commodi impedit aut dignissimos]]></g:title>
33-
<g:description><![CDATA[Voluptatem quia fugiat enim et molestiae. Illo at eos est iste. Nulla et non est. Qui qui facere harum nesciunt. Itaque sit quibusdam praesentium qui beatae est cum. Quia sint autem vel aut.]]></g:description>
34-
<g:link>https://example.com/products/pariatur-aliquid-sapiente-quia-est-quis-cumque-quis</g:link>
35-
<g:image_link>https://via.placeholder.com/640x480.png/0033bb?text=harum</g:image_link>
36-
<g:additional_image_link>https://via.placeholder.com/640x480.png/00ffdd?text=sit</g:additional_image_link>
37-
<g:additional_image_link>https://via.placeholder.com/640x480.png/00ff66?text=sequi</g:additional_image_link>
38-
<g:brand>explicabo</g:brand>
29+
<g:title><![CDATA[Some 2]]></g:title>
30+
<g:description><![CDATA[Some description 2]]></g:description>
31+
<g:link>https://example.com/products/est-ducimus-omnis-consequatur-et-corrupti-minus-incidunt-in</g:link>
32+
<g:image_link>https://via.placeholder.com/640x480.png/009966?text=beatae</g:image_link>
33+
<g:additional_image_link>https://via.placeholder.com/640x480.png/009966?text=beatae</g:additional_image_link>
34+
<g:additional_image_link>https://via.placeholder.com/640x480.png/000011?text=deleniti</g:additional_image_link>
35+
<g:additional_image_link>https://via.placeholder.com/640x480.png/009999?text=voluptates</g:additional_image_link>
36+
<g:brand>The Best</g:brand>
3937
<g:condition>new</g:condition>
4038
<g:availability>in stock</g:availability>
41-
<g:price>659</g:price>
42-
<g:sale_price>659</g:sale_price>
43-
<g:item_group_id>12345</g:item_group_id>
39+
<g:price>250</g:price>
40+
<g:sale_price>250</g:sale_price>
4441
<g:status>active</g:status>
45-
<g:color><![CDATA[Chocolate]]></g:color>
46-
<g:size>16</g:size>
47-
<g:age_group>adult</g:age_group>
48-
<g:material><![CDATA[facere]]></g:material>
49-
<g:pattern><![CDATA[regular]]></g:pattern>
50-
<g:google_product_category>1000</g:google_product_category>
51-
<g:fb_product_category>2000</g:fb_product_category>
42+
<g:foo>Some foo</g:foo>
43+
<g:bar>Some bar</g:bar>
44+
<g:baz qwe="rty">Some baz</g:baz>
45+
<g:arrayable>a</g:arrayable>
46+
<g:arrayable>b</g:arrayable>
47+
<g:arrayable>c</g:arrayable>
5248
</item>
5349

5450
</offers>

docs/snippets/receipt-rss-feed.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Feeds;
6+
7+
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
8+
use DragonCode\LaravelFeed\Presets\RssFeedPreset;
9+
use Illuminate\Database\Eloquent\Builder;
10+
use Illuminate\Database\Eloquent\Model;
11+
use App\Models\News;
12+
13+
class RssFeed extends RssFeedPreset
14+
{
15+
public function builder(): Builder
16+
{
17+
return News::query()->take(2);
18+
}
19+
20+
public function item(Model $model): FeedItem
21+
{
22+
return parent::item($model)
23+
->title($model->title)
24+
->description($model->content)
25+
->category($model->category)
26+
->url($model->url);
27+
}
28+
29+
public function filename(): string
30+
{
31+
return 'rss.xml';
32+
}
33+
}

docs/snippets/receipt-rss-feed.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
3+
<channel>
4+
5+
<item>
6+
<title>Some 1</title>
7+
<link>https://example.com/news/some-1</link>
8+
<guid>1</guid>
9+
<description><![CDATA[Some content 1]]></description>
10+
<category>Some category 1</category>
11+
<pubDate>Thu, 04 Sep 2025 04:08:12 +0000</pubDate>
12+
</item>
13+
<item>
14+
<title>Some 2</title>
15+
<link>https://example.com/news/some-2</link>
16+
<guid>2</guid>
17+
<description><![CDATA[Some content 2]]></description>
18+
<category>Some category 2</category>
19+
<pubDate>Thu, 04 Sep 2025 04:08:12 +0000</pubDate>
20+
</item>
21+
22+
</channel>
23+
</rss>

docs/snippets/receipt-sitemap-feed-item.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

docs/snippets/receipt-sitemap-feed.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,28 @@
44

55
namespace App\Feeds\Sitemaps;
66

7-
use App\Feeds\Sitemaps\Items\ProductFeedItem;
8-
use App\Models\Product;
9-
use DragonCode\LaravelFeed\Data\ElementData;
10-
use DragonCode\LaravelFeed\Feeds\Feed;
117
use DragonCode\LaravelFeed\Feeds\Items\FeedItem;
8+
use DragonCode\LaravelFeed\Presets\SitemapFeedPreset;
129
use Illuminate\Database\Eloquent\Builder;
1310
use Illuminate\Database\Eloquent\Model;
11+
use App\Models\Product;
1412

15-
class ProductFeed extends Feed
13+
class ProductFeed extends SitemapFeedPreset
1614
{
17-
protected string $name = 'urlset';
18-
19-
protected array $attributes = [
20-
'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
21-
'xmlns:xhtml' => 'http://www.w3.org/1999/xhtml',
22-
'xmlns:image' => 'http://www.google.com/schemas/sitemap-image/1.1',
23-
'xmlns:video' => 'http://www.google.com/schemas/sitemap-video/1.1',
24-
'xmlns:news' => 'http://www.google.com/schemas/sitemap-news/0.9',
25-
];
26-
2715
public function builder(): Builder
2816
{
2917
return Product::query();
3018
}
3119

32-
public function root(): ElementData
33-
{
34-
return new ElementData(
35-
name : $this->name,
36-
attributes: $this->attributes,
37-
);
38-
}
39-
4020
public function item(Model $model): FeedItem
4121
{
42-
return new ProductFeedItem($model);
22+
return parent::item($model)->url(
23+
$model->url
24+
);
4325
}
4426

4527
public function filename(): string
4628
{
47-
return 'sitemaps/products.xml';
29+
return 'sitemaps/' . parent::filename();
4830
}
4931
}

docs/snippets/receipt-sitemap-feed.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
33

44
<url>
5-
<loc>https://example.com/products/in-nulla-sequi-qui-nulla</loc>
6-
<lastmod>2025-09-04T04:08:12+00:00</lastmod>
5+
<loc>https://example.com/products/et-eum-corporis-et-nam-vitae-assumenda-fugiat-sint</loc>
6+
<lastmod>2025-08-31T20:00:00+00:00</lastmod>
77
<priority>0.9</priority>
88
</url>
99
<url>
10-
<loc>https://example.com/products/et-at-dolor-occaecati-ut</loc>
11-
<lastmod>2025-09-04T04:08:12+00:00</lastmod>
10+
<loc>https://example.com/products/consequuntur-blanditiis-culpa-autem-ratione</loc>
11+
<lastmod>2025-08-30T19:00:00+00:00</lastmod>
1212
<priority>0.9</priority>
1313
</url>
1414

0 commit comments

Comments
 (0)