Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jul 12, 2022
2 parents 19a403f + aef50d6 commit 38e3af5
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 161 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Global
.composer
composer.lock
package-lock.json
vendor/

# OS Generated
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
*.swp

# phpstorm
.idea/*
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# v2.0.0, 2022-07-11

### Features

* **core** Updated code base for new Flextype 1.0.0-alpha.1
* **core** Adde ability to generate static feeds.

# v1.0.0, 2021-01-15
* Initial release
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2021 Sergey Romanenko
Copyright (c) Sergey Romanenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
73 changes: 11 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,29 @@
<h1 align="center">Feed Plugin for <a href="https://flextype.org/">Flextype</a></h1>
<h1 align="center">Feed Plugin for <a href="https://awilum.github.io/flextype">Flextype</a></h1>

<p align="center">
<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>
<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>
</p>

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

## Dependencies

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

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

## Installation

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

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

### Settings

| Key | Value | Description |
|---|---|---|
| enabled | true | true or false to disable the plugin |
| priority | 100 | Feed plugin priority |
| feed | [] | Feed specific data |

### Usage

In `project/config/plugins/feed/settings.yaml` you may create unlimited feed for you entries.

Lets create RSS, ATOM and JSON feed for blog collection:

```yaml
feed:
blog-rss:
id: blog
options:
title: Blog
description: Blog description
collection: true
format: rss
route: '/blog.rss'
blog-atom:
id: blog
options:
title: Blog
description: Blog description
collection: true
format: atom
route: '/blog.atom'
blog-json:
id: blog
options:
title: Blog
description: Blog description
collection: true
format: json
route: '/blog.json'
```
#### Display feed urls in the TWIG templates
You may easily display feed urls from example above in TWIG templates:
```twig
<a href="{{ url() }}/blog.atom">Atom 1.0</a>
<a href="{{ url() }}/blog.rss">RSS</a>
<a href="{{ url() }}/blog.json">JSON</a>
```

## LICENSE
## License
[The MIT License (MIT)](https://github.com/flextype-plugins/feed/blob/master/LICENSE.txt)
Copyright (c) 2021 [Sergey Romanenko](https://github.com/Awilum)
Copyright (c) [Sergey Romanenko](https://github.com/Awilum)
33 changes: 33 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "flextype-plugins/feed",
"type": "project",
"description": "Feed plugin for Flextype supports Atom 1.0, RSS and JSON feed types and allows you to generate feeds for entries.",
"keywords": ["feed", "plugin", "flextype"],
"homepage": "https://awilum.github.io/flextype/downloads/extend/plugins/feed",
"license": "MIT",
"authors": [
{
"name": "Sergey Romanenko",
"email": "[email protected]",
"homepage": "https://awilum.github.io"
}
],
"support": {
"issues": "https://github.com/flextype-plugins/feed/issues"
},
"require": {
"php": "^8.1",
"ext-json": "*"
},
"config": {
"apcu-autoloader": true,
"optimize-autoloader": true,
"platform-check": false,
"sort-packages": true
},
"autoload": {
"classmap": [
"src"
]
}
}
81 changes: 56 additions & 25 deletions plugin.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,81 @@
<?php

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
declare(strict_types=1);

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

if (isset($feed) and count($feed) > 0) {
foreach ($feed as $item) {
use Flextype\Plugin\Feed\Console\Commands\Feed\FeedGenerateCommand;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use function Flextype\console;
use function Flextype\registry;
use function Flextype\emitter;
use function Flextype\cache;
use function Flextype\app;
use function Glowy\Strings\strings;

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

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

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

if (flextype('cache')->has($cacheID)) {
$entries = flextype('cache')->get($cacheID);
} else {
$entries = flextype('entries')
->fetch($item['id'], $item['options'])
->sortBy('published_at', 'DESC');
$feeds = registry()->get('plugins.feed.settings.feeds');

if (is_array($feeds) && count($feeds) > 0) {
foreach ($feeds as $feed) {

$cacheID = strings('feed-collection-' . $feed['id'] . '-' . json_encode($feed['options']))->hash()->toString();

flextype('cache')->set($cacheID, $entries);
// Delete feed collection from cache on these events:
emitter()->addListener('onEntriesCreate', fn () => cache()->delete($cacheID));
emitter()->addListener('onEntriesDelete', fn () => cache()->delete($cacheID));
emitter()->addListener('onEntriesMove', fn () => cache()->delete($cacheID));
emitter()->addListener('onEntriesCopy', fn () => cache()->delete($cacheID));
emitter()->addListener('onEntriesUpdate', fn () => cache()->delete($cacheID));

app()->get($feed['options']['feed']['route'], function (ServerRequestInterface $request, ResponseInterface $response) use ($feed, $cacheID) {

if (cache()->has($cacheID)) {
$entries = cache()->get($cacheID);
} else {
$entries = entries()->fetch($feed['id'], $feed['options'])->sortBy('published_at', 'DESC');
cache()->set($cacheID, $entries);
}

switch ($item['options']['format']) {
switch ($feed['options']['feed']['format']) {
case 'rss':
$response = $response->withHeader('Content-Type', 'application/rss+xml');
$template = 'plugins/feed/templates/feed.rss.html';
$template = isset($feed['options']['feed']['template']) ? $feed['options']['feed']['template'] : 'plugins/feed/views/templates/feed.rss.html';
break;
case 'atom':
$response = $response->withHeader('Content-Type', 'application/atom+xml');
$template = 'plugins/feed/templates/feed.atom.html';
$template = isset($feed['options']['feed']['template']) ? $feed['options']['feed']['template'] : 'plugins/feed/views/templates/feed.atom.html';
break;
case 'json':
default:
$response = $response->withHeader('Content-Type', 'application/json');
$template = 'plugins/feed/templates/feed.json.html';
$template = isset($feed['options']['feed']['template']) ? $feed['options']['feed']['template'] : 'plugins/feed/views/templates/feed.json.html';
break;
}

return flextype('twig')->render($response, $template, ['entries' => $entries, 'item' => $item]);
$response->withStatus(200);
$response->getBody()->write(twig()->fetch($template, ['entries' => $entries, 'feed' => $feed]));

return $response;
});
}
}
}
21 changes: 11 additions & 10 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
name: Feed
version: 1.0.0
description: Feed plugin for Flextype
version: 2.0.0
description: Feed plugin for Flextype supports Atom 1.0, RSS and JSON feed types and allows you to generate feeds for entries.
author:
name: Sergey Romanenko
email: [email protected]
url: https://flextype.org
homepage: https://github.com/flextype-plugins/feed
documentation: https://github.com/flextype-plugins/feed
email: [email protected]
url: https://awilum.github.io
homepage: https://awilum.github.io/flextype/downloads/extend/plugins/feed
documentation: https://awilum.github.io/flextype/downloads/extend/plugins/feed
changelog: https://github.com/flextype-plugins/feed/blob/master/CHANGELOG.md
bugs: https://github.com/flextype-plugins/feed/issues
icon:
name: map-marked-alt
set: "fontawesome|solid"
name: rss
set: fontawesome|solid
category: seo
license: MIT

dependencies:
flextype: 0.9.16
twig: '>=2.0.0'
flextype: "^1.0.0-alpha.1"
twig: "^3.0.0"
16 changes: 15 additions & 1 deletion settings.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# enabled: true or false to disable the plugin
enabled: true

# Feed plugin priority
priority: 100
feed: []

# Feeds
feeds: []

# Settings for static feeds generation
static:

# Feeds path (without trailing and without starting slash)
path: '_site'

# Site url (without trailing slash)
site_url: ''
Loading

0 comments on commit 38e3af5

Please sign in to comment.