Skip to content

Commit 38e3af5

Browse files
committed
Merge branch '2.x'
2 parents 19a403f + aef50d6 commit 38e3af5

File tree

14 files changed

+335
-161
lines changed

14 files changed

+335
-161
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Global
2+
.composer
3+
composer.lock
4+
package-lock.json
5+
vendor/
6+
7+
# OS Generated
8+
.DS_Store*
9+
ehthumbs.db
10+
Icon?
11+
Thumbs.db
12+
*.swp
13+
14+
# phpstorm
15+
.idea/*

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
# v2.0.0, 2022-07-11
2+
3+
### Features
4+
5+
* **core** Updated code base for new Flextype 1.0.0-alpha.1
6+
* **core** Adde ability to generate static feeds.
7+
18
# v1.0.0, 2021-01-15
29
* Initial release

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2021 Sergey Romanenko
3+
Copyright (c) Sergey Romanenko
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,29 @@
1-
<h1 align="center">Feed Plugin for <a href="https://flextype.org/">Flextype</a></h1>
1+
<h1 align="center">Feed Plugin for <a href="https://awilum.github.io/flextype">Flextype</a></h1>
22

33
<p align="center">
4-
<a href="https://github.com/flextype-plugins/feed/releases"><img alt="Version" src="https://img.shields.io/github/release/flextype-plugins/feed.svg?label=version&color=black"></a> <a href="https://github.com/flextype-plugins/feed"><img src="https://img.shields.io/badge/license-MIT-blue.svg?color=black" alt="License"></a> <a href="https://github.com/flextype-plugins/feed"><img src="https://img.shields.io/github/downloads/flextype-plugins/feed/total.svg?color=black" alt="Total downloads"></a> <a href="https://github.com/flextype/flextype"><img src="https://img.shields.io/badge/Flextype-0.9.16-green.svg?color=black" alt="Flextype"></a> <a href=""><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&color=black&label=Discord%20Chat" alt="Discord"></a>
4+
<img src="https://img.shields.io/badge/license-MIT-blue.svg?label=License" alt="License MIT"> <img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/flextype-plugins/feed?label=Stars"> <img alt="GitHub forks" src="https://img.shields.io/github/forks/flextype-plugins/feed?label=Forks"> <a href="https://hitsofcode.com"><img alt="Hits of Code" src="https://hitsofcode.com/github/flextype-plugins/feed?branch=2.x"></a> <a href="https://discord.gg/ewQkqgfBAc"><img src="https://img.shields.io/discord/423097982498635778.svg?logo=discord&label=Discord%20Chat" alt="Discord"></a>
55
</p>
66

7-
Feed plugin for Flextype supports Atom 1.0, RSS and JSON feed types and allows you to generate feeds for entries.
7+
Feed plugin for Flextype supports Atom 1.0, RSS and JSON feed types and allows you to generate feeds for entries.
88

99
## Dependencies
1010

1111
The following dependencies need to be downloaded and installed for Feed Plugin.
1212

1313
| Item | Version | Download |
1414
|---|---|---|
15-
| [flextype](https://github.com/flextype/flextype) | 0.9.16 | [download](https://github.com/flextype/flextype/releases) |
16-
| [twig](https://github.com/flextype-plugins/twig) | >=2.0.0 | [download](https://github.com/flextype-plugins/twig/releases) |
15+
| [flextype](https://github.com/flextype/flextype) | ^1.0.0-alpha.1 | [download](https://github.com/flextype/flextype/releases) |
16+
| [twig](https://github.com/flextype-plugins/twig) | ^3.0.0 | [download](https://github.com/flextype-plugins/twig/releases) |
1717

1818
## Installation
1919

2020
1. Download & Install all required dependencies.
21-
2. Create new folder `/project/plugins/feed`
22-
3. Download Feed Plugin and unzip plugin content to the folder `/project/plugins/feed`
21+
2. Create new folder `project/plugins/feed`.
22+
3. Download [Feed Plugin](https://github.com/flextype-plugins/feed/releases) and unzip plugin content to the folder `project/plugins/feed`.
2323

24-
## Documentation
24+
## Resources
25+
* [Documentation](https://awilum.github.io/flextype/downloads/extend/plugins/feed)
2526

26-
### Settings
27-
28-
| Key | Value | Description |
29-
|---|---|---|
30-
| enabled | true | true or false to disable the plugin |
31-
| priority | 100 | Feed plugin priority |
32-
| feed | [] | Feed specific data |
33-
34-
### Usage
35-
36-
In `project/config/plugins/feed/settings.yaml` you may create unlimited feed for you entries.
37-
38-
Lets create RSS, ATOM and JSON feed for blog collection:
39-
40-
```yaml
41-
feed:
42-
blog-rss:
43-
id: blog
44-
options:
45-
title: Blog
46-
description: Blog description
47-
collection: true
48-
format: rss
49-
route: '/blog.rss'
50-
blog-atom:
51-
id: blog
52-
options:
53-
title: Blog
54-
description: Blog description
55-
collection: true
56-
format: atom
57-
route: '/blog.atom'
58-
blog-json:
59-
id: blog
60-
options:
61-
title: Blog
62-
description: Blog description
63-
collection: true
64-
format: json
65-
route: '/blog.json'
66-
```
67-
68-
#### Display feed urls in the TWIG templates
69-
70-
You may easily display feed urls from example above in TWIG templates:
71-
72-
```twig
73-
<a href="{{ url() }}/blog.atom">Atom 1.0</a>
74-
<a href="{{ url() }}/blog.rss">RSS</a>
75-
<a href="{{ url() }}/blog.json">JSON</a>
76-
```
77-
78-
## LICENSE
27+
## License
7928
[The MIT License (MIT)](https://github.com/flextype-plugins/feed/blob/master/LICENSE.txt)
80-
Copyright (c) 2021 [Sergey Romanenko](https://github.com/Awilum)
29+
Copyright (c) [Sergey Romanenko](https://github.com/Awilum)

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "flextype-plugins/feed",
3+
"type": "project",
4+
"description": "Feed plugin for Flextype supports Atom 1.0, RSS and JSON feed types and allows you to generate feeds for entries.",
5+
"keywords": ["feed", "plugin", "flextype"],
6+
"homepage": "https://awilum.github.io/flextype/downloads/extend/plugins/feed",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Sergey Romanenko",
11+
"email": "awilum@msn.com",
12+
"homepage": "https://awilum.github.io"
13+
}
14+
],
15+
"support": {
16+
"issues": "https://github.com/flextype-plugins/feed/issues"
17+
},
18+
"require": {
19+
"php": "^8.1",
20+
"ext-json": "*"
21+
},
22+
"config": {
23+
"apcu-autoloader": true,
24+
"optimize-autoloader": true,
25+
"platform-check": false,
26+
"sort-packages": true
27+
},
28+
"autoload": {
29+
"classmap": [
30+
"src"
31+
]
32+
}
33+
}

plugin.php

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,81 @@
11
<?php
22

3-
use Psr\Http\Message\ResponseInterface as Response;
4-
use Psr\Http\Message\ServerRequestInterface as Request;
3+
declare(strict_types=1);
54

6-
$feed = flextype('registry')->get('plugins.feed.settings.feed');
5+
namespace Flextype\Plugin\Feed;
76

8-
if (isset($feed) and count($feed) > 0) {
9-
foreach ($feed as $item) {
7+
use Flextype\Plugin\Feed\Console\Commands\Feed\FeedGenerateCommand;
8+
use Psr\Http\Message\ResponseInterface;
9+
use Psr\Http\Message\ServerRequestInterface;
10+
use function Flextype\console;
11+
use function Flextype\registry;
12+
use function Flextype\emitter;
13+
use function Flextype\cache;
14+
use function Flextype\app;
15+
use function Glowy\Strings\strings;
1016

11-
$cacheID = strings('feed-collection-' . $item['id'])->hash()->toString();
17+
/**
18+
* Ensure vendor libraries exist
19+
*/
20+
! is_file($feedAutoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: <i>composer install</i> for feed plugin');
1221

13-
flextype('emitter')->addListener('onEntriesCreate', fn () => flextype('cache')->delete($cacheID));
14-
flextype('emitter')->addListener('onEntriesDelete', fn () => flextype('cache')->delete($cacheID));
15-
flextype('emitter')->addListener('onEntriesMove', fn () => flextype('cache')->delete($cacheID));
16-
flextype('emitter')->addListener('onEntriesCopy', fn () => flextype('cache')->delete($cacheID));
17-
flextype('emitter')->addListener('onEntriesUpdate', fn () => flextype('cache')->delete($cacheID));
22+
/**
23+
* Register The Auto Loader
24+
*
25+
* Composer provides a convenient, automatically generated class loader for
26+
* our application. We just need to utilize it! We'll simply require it
27+
* into the script here so that we don't have to worry about manual
28+
* loading any of our classes later on. It feels nice to relax.
29+
* Register The Auto Loader
30+
*/
31+
$feedLoader = require_once $feedAutoload;
1832

19-
flextype()->get($item['options']['route'], function (Request $request, Response $response, array $args) use ($item, $cacheID) {
33+
// Add feed generate console command
34+
console()->add(new FeedGenerateCommand());
2035

21-
if (flextype('cache')->has($cacheID)) {
22-
$entries = flextype('cache')->get($cacheID);
23-
} else {
24-
$entries = flextype('entries')
25-
->fetch($item['id'], $item['options'])
26-
->sortBy('published_at', 'DESC');
36+
$feeds = registry()->get('plugins.feed.settings.feeds');
37+
38+
if (is_array($feeds) && count($feeds) > 0) {
39+
foreach ($feeds as $feed) {
40+
41+
$cacheID = strings('feed-collection-' . $feed['id'] . '-' . json_encode($feed['options']))->hash()->toString();
2742

28-
flextype('cache')->set($cacheID, $entries);
43+
// Delete feed collection from cache on these events:
44+
emitter()->addListener('onEntriesCreate', fn () => cache()->delete($cacheID));
45+
emitter()->addListener('onEntriesDelete', fn () => cache()->delete($cacheID));
46+
emitter()->addListener('onEntriesMove', fn () => cache()->delete($cacheID));
47+
emitter()->addListener('onEntriesCopy', fn () => cache()->delete($cacheID));
48+
emitter()->addListener('onEntriesUpdate', fn () => cache()->delete($cacheID));
49+
50+
app()->get($feed['options']['feed']['route'], function (ServerRequestInterface $request, ResponseInterface $response) use ($feed, $cacheID) {
51+
52+
if (cache()->has($cacheID)) {
53+
$entries = cache()->get($cacheID);
54+
} else {
55+
$entries = entries()->fetch($feed['id'], $feed['options'])->sortBy('published_at', 'DESC');
56+
cache()->set($cacheID, $entries);
2957
}
3058

31-
switch ($item['options']['format']) {
59+
switch ($feed['options']['feed']['format']) {
3260
case 'rss':
3361
$response = $response->withHeader('Content-Type', 'application/rss+xml');
34-
$template = 'plugins/feed/templates/feed.rss.html';
62+
$template = isset($feed['options']['feed']['template']) ? $feed['options']['feed']['template'] : 'plugins/feed/views/templates/feed.rss.html';
3563
break;
3664
case 'atom':
3765
$response = $response->withHeader('Content-Type', 'application/atom+xml');
38-
$template = 'plugins/feed/templates/feed.atom.html';
66+
$template = isset($feed['options']['feed']['template']) ? $feed['options']['feed']['template'] : 'plugins/feed/views/templates/feed.atom.html';
3967
break;
4068
case 'json':
4169
default:
4270
$response = $response->withHeader('Content-Type', 'application/json');
43-
$template = 'plugins/feed/templates/feed.json.html';
71+
$template = isset($feed['options']['feed']['template']) ? $feed['options']['feed']['template'] : 'plugins/feed/views/templates/feed.json.html';
4472
break;
4573
}
4674

47-
return flextype('twig')->render($response, $template, ['entries' => $entries, 'item' => $item]);
75+
$response->withStatus(200);
76+
$response->getBody()->write(twig()->fetch($template, ['entries' => $entries, 'feed' => $feed]));
77+
78+
return $response;
4879
});
4980
}
50-
}
81+
}

plugin.yaml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
name: Feed
2-
version: 1.0.0
3-
description: Feed plugin for Flextype
2+
version: 2.0.0
3+
description: Feed plugin for Flextype supports Atom 1.0, RSS and JSON feed types and allows you to generate feeds for entries.
44
author:
55
name: Sergey Romanenko
6-
email: sergey.romanenko@flextype.org
7-
url: https://flextype.org
8-
homepage: https://github.com/flextype-plugins/feed
9-
documentation: https://github.com/flextype-plugins/feed
6+
email: awilum@msm.com
7+
url: https://awilum.github.io
8+
homepage: https://awilum.github.io/flextype/downloads/extend/plugins/feed
9+
documentation: https://awilum.github.io/flextype/downloads/extend/plugins/feed
1010
changelog: https://github.com/flextype-plugins/feed/blob/master/CHANGELOG.md
1111
bugs: https://github.com/flextype-plugins/feed/issues
1212
icon:
13-
name: map-marked-alt
14-
set: "fontawesome|solid"
13+
name: rss
14+
set: fontawesome|solid
15+
category: seo
1516
license: MIT
1617

1718
dependencies:
18-
flextype: 0.9.16
19-
twig: '>=2.0.0'
19+
flextype: "^1.0.0-alpha.1"
20+
twig: "^3.0.0"

settings.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# enabled: true or false to disable the plugin
12
enabled: true
3+
4+
# Feed plugin priority
25
priority: 100
3-
feed: []
6+
7+
# Feeds
8+
feeds: []
9+
10+
# Settings for static feeds generation
11+
static:
12+
13+
# Feeds path (without trailing and without starting slash)
14+
path: '_site'
15+
16+
# Site url (without trailing slash)
17+
site_url: ''

0 commit comments

Comments
 (0)