Skip to content

Commit

Permalink
Merge branch 'release/1.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Sep 26, 2023
2 parents a269d53 + 1909d32 commit 6dac901
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.10.0
## 09/26/2023

1. [](#new)
* Allow template overrides based on header feed config [#67](https://github.com/getgrav/grav-plugin-feed/pull/67)
1. [](#bugfix)
* Fixed the `<lastBuildDate..>` that was broken

# v1.9.0
## 10/05/2022

Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ Manually updating Feed is pretty simple. Here is what you will need to do to get

> Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in `user/config/plugins`) will remain intact.
## Overriding the default feed template:

Sometimes, you may wish to use a different template for an RSS/ ATOM/ JSON feed. To override a feed's template, place the following in the page header:
``` yaml
feed:
template:
rss: my-override
```
Create the `my-override.rss.twig` in your theme/ plugin's `templates` folder and add it to your [twig template paths](https://learn.getgrav.org/17/cookbook/plugin-recipes#custom-twig-templates-plu). Change `*.rss.*` to `*.atom.*` or `*.json.*` to override those page types.

## Nginx Note:

If you are having trouble with 404s with Nginx, it might be related to your configuration. You may need to remove the feed extensions from the list of types to cache as static files: `.xml`, `.rss`, and `.atom`. For example:
Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Feed
type: plugin
slug: feed
version: 1.9.0
version: 1.10.0
description: The **Feed** plugin is a simple yet powerful add-on that lets you view a Grav Collection as **JSON**, **RSS** or **Atom** news feed.
icon: rss
author:
Expand Down
15 changes: 11 additions & 4 deletions feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public function onPluginsInitialized()
$this->type = $uri->extension();

if ($this->type && in_array($this->type, $this->valid_types)) {

$this->enable([
'onPageInitialized' => ['onPageInitialized', 0],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
Expand All @@ -95,19 +94,27 @@ public function onPageInitialized()

// Overwrite regular content with feed config, so you can influence the collection processing with feed config
if (property_exists($page->header(), 'content')) {
// Set default template.
$template = "feed";

if (isset($page->header()->feed)) {
$this->feed_config = array_merge($this->feed_config, $page->header()->feed);

// Look for feed type override,
if (isset($this->feed_config['template']) && isset($this->feed_config['template'][$this->type])) {
$template = $this->feed_config['template'][$this->type];
}
}

$page->header()->content = array_merge($page->header()->content, $this->feed_config);

$this->grav['twig']->template = 'feed.' . $this->type . '.twig';
// Set page template.
$this->grav['twig']->template = $template . "." . $this->type . '.twig';

$this->enable([
'onCollectionProcessed' => ['onCollectionProcessed', 0],
]);
}

}

/**
Expand Down Expand Up @@ -175,4 +182,4 @@ public function onPageHeaders(Event $e)
$headers->{'Content-Type'} = "$content_type; charset=utf-8";
}
}
}
}
2 changes: 1 addition & 1 deletion templates/feed.rss.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% for page in collection %}
{%- set lastBuildDate = max(lastBuildDate, page.date) %}
{%- if collection.params.show_last_modified %}
{%- set lastBuildDate = max(feed_updated, page.modified) %}
{%- set lastBuildDate = max(lastBuildDate, page.modified) %}
{%- endif %}
{% endfor %}
<?xml version="1.0" encoding="utf-8"?>
Expand Down

0 comments on commit 6dac901

Please sign in to comment.