Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 6, 2021
2 parents f8e2c37 + 1954e0e commit 7c2e54c
Show file tree
Hide file tree
Showing 19 changed files with 1,360 additions and 97 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v2.1.0
## 12/06/2021

1. [](#new)
* Added `[page-inject]` and `[content-inject]` shortcodes as an alternative syntax
* Added support for remote `page-inject` and `content-inject` variations
2. [](#improved)
* Refactored code to work with both markdown and shortcode syntax
* Use composer-based autoloader

# v2.0.0
## 12/03/2021

Expand Down
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Grav Page Inject Plugin

`Page Inject` is a powerful [Grav][grav] Plugin that lets you inject entire pages or page content into other pages using simple markdown syntax
`Page Inject` is a powerful [Grav][grav] Plugin that lets you inject entire pages or page content into other pages using simple markdown-style syntax or alternatively a shortcode syntax (Shortcode Core plugin required).

# Installation

Expand Down Expand Up @@ -47,7 +47,7 @@ page-inject:
processed_content: true
```

# Usage
## Markdown-Style Usage (Legacy)

There are two ways to use this plugin in your markdown content:

Expand All @@ -71,6 +71,36 @@ There are two ways to use this plugin in your markdown content:
Sometimes you just want the content of another page injected directly into your current page. Use `content-inject` for this purpose. The content is not rendered with the associated twig template, merely injected into the current page.
## Shortcode Usage (New)
The shortcode syntax follows the markdown-style syntax, and supports both `page-inject` and `content-inject` approaches.
> NOTE: Shortcode functionality requires the `shortcode-core` plugin to be installed and enabled.
For example the Page Injection example from above would look like:
```markdown
[page-inject=/route/to/page /]
```

and the content inject version:

```markdown
[content-inject=/route/to/page /]
```

Alternatively, you can supply the path explicitly:

```markdown
[content-inject path="/route/to/page" /]
```

And for page-injection, you can specify a custom Twig template to render with:

```markdown
[page-inject path="/route/to/page" template="foo" /]
```

## Remote Injects

It is now possible to retrieve remote content from another Grav instance as long as both of the sites are running the latest version of the `page-inject` plugin. First in the **client** Grav instance you need to define a remote connection to another Grav **server** in the plugin configuration. For example:
Expand All @@ -87,6 +117,12 @@ This will then allow you to inject page content from one Grav instance to anothe
[plugin:page-inject](remote://dev/home/modular/_callout)
```

and for the shortcode version:

```markdown
[page-inject path="remote://dev/home/modular/_callout" /]
```

Where the `remote://dev` protocol tells the plugin to retrieve the requested page from the `dev` injection configuration via the path `/home/modular/_callout`.

This is particularly useful for modular content that is already a snippet of content that is being reused on the **server**. This will retrieve the content, and because a modular page's content is pre-rendered with the appropriate Twig template, it will include all the HTML of the modular page. If you request a regular page (non-modular), there will be no Twig and just plain HTML content will be sent.
Expand Down
4 changes: 2 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Page Inject
type: plugin
slug: page-inject
version: 2.0.0
description: "**Page Inject** is a powerful plugin that lets you inject entire pages or page content into other pages using simple markdown syntax"
version: 2.1.0
description: "**Page Inject** is a powerful plugin that lets you inject entire pages or page content into other pages using simple markdown-style or shortcode syntax"
icon: trello
author:
name: Team Grav
Expand Down
22 changes: 22 additions & 0 deletions classes/shortcodes/PageInjectShortcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Grav\Plugin\Shortcodes;

use Grav\Plugin\PageInjectPlugin;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;

class PageInjectShortcode extends Shortcode
{
public function init()
{
$this->shortcode->getHandlers()->add('page-inject', function(ShortcodeInterface $sc) {
$path = $sc->getParameter('path') ?? $sc->getBbCode();
return PageInjectPlugin::getInjectedPageContent('page-inject', $path);
});

$this->shortcode->getHandlers()->add('content-inject', function(ShortcodeInterface $sc) {
$path = $sc->getParameter('path') ?? $sc->getBbCode();
return PageInjectPlugin::getInjectedPageContent('content-inject', $path);
});
}
}
30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "getgrav/page-inject",
"type": "grav-plugin",
"description": "Page & Content Injection for Grav",
"keywords": ["shortcode"],
"homepage": "https://github.com/getgrav/grav-plugin-content-inject/",
"license": "MIT",
"authors": [
{
"name": "Team Grav",
"email": "devs@getgrav.org",
"homepage": "http://getgrav.org",
"role": "Developer"
}
],
"require": {
"php": ">=7.1.3"
},
"autoload": {
"psr-4": {
"Grav\\Plugin\\PageInject\\": "classes"
},
"classmap": ["page-inject.php"]
},
"config": {
"platform": {
"php": "7.1.3"
}
}
}
23 changes: 23 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7c2e54c

Please sign in to comment.