Skip to content

Commit

Permalink
Prepared for initial gpm release
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-j-m committed Jun 23, 2020
1 parent 225ff1b commit 7716ae9
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 155 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# v0.1.0
## 29-02-2020
# v1.0.0
## 23-06-2020

1. [](#new)
* ChangeLog started...
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It is recommended to install Aura Authors directly through the Admin Plugin by b

## Configuration

* Enter author details via the `Authors` section of the Admin Plugin.
* Enter author details via the Admin Plugin by browsing to `Plugins` > `Aura Authors` and selecting `Add Item`.

* Copy the following code snippet to the relevant Twig template within your theme, at the place where you would like the author bio to be displayed.

Expand All @@ -32,7 +32,7 @@ It is recommended to install Aura Authors directly through the Admin Plugin by b

## Usage

Authors can be selected per page via the page editor, on the `Aura` tab. The list of authors will be automatically populated with author records you create via the `Authors` menu item.
Authors can be selected per page via the page editor, on the `Aura` tab. The list of authors will be automatically populated with author records you create via the Plugins panel.

## Credits

Expand Down
1 change: 0 additions & 1 deletion admin/assets/admin.min.js

This file was deleted.

1 change: 0 additions & 1 deletion admin/assets/style.min.css

This file was deleted.

90 changes: 0 additions & 90 deletions admin/pages/authors.md

This file was deleted.

11 changes: 0 additions & 11 deletions admin/templates/authors.html.twig

This file was deleted.

2 changes: 1 addition & 1 deletion assets/style.min.css

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

2 changes: 1 addition & 1 deletion assets/style.min.css.map

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

87 changes: 47 additions & 40 deletions aura-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,47 @@
use Grav\Common\Plugin;
use Grav\Common\Page\Page;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\File\File;
use Symfony\Component\Yaml\Yaml;

/**
* Class AuraAuthorsPlugin
* @package Grav\Plugin
*/
class AuraAuthorsPlugin extends Plugin
{
protected static $authorsFile = DATA_DIR . 'authors/authors.yaml';
protected $route = 'authors';

/** @var array */
static protected $authors = [];

public static function getAuthors()
{
$fileInstance = File::instance(self::$authorsFile);
if (!$fileInstance->content()) {
return;
}
return Yaml::parse($fileInstance->content());
return self::$authors;
}

public function onPluginsInitialized()
{
// Admin only events
if ($this->isAdmin()) {
$this->enable([
'onAdminMenu' => ['onAdminMenu', 0],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
'onPageInitialized' => ['onPageInitialized', 0],
'onGetPageBlueprints' => ['onGetPageBlueprints', 0],
'onAdminSave' => ['onAdminSave', 0],
]);
return;
}

// Frontend events
$this->enable([
'onTwigSiteVariables' => ['onTwigSiteVariables', 0],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
]);

}

/**
* Add plugin directory to twig lookup paths
*/
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}

/**
Expand All @@ -48,8 +54,11 @@ public function onPluginsInitialized()
*/
public function onGetPageBlueprints($event)
{
$types = $event->types;
$types->scanBlueprints('plugins://' . $this->name . '/blueprints');

self::$authors = $this->grav['config']->get('plugins.aura-authors.authors');

$types = $event->types;
$types->scanBlueprints('plugins://' . $this->name . '/blueprints');
}

public function onAdminSave(Event $event)
Expand All @@ -61,37 +70,20 @@ public function onAdminSave(Event $event)

$page = $event['object'];
if (isset($page->header()->aura['author'])) {
$author = array('author' => array($page->header()->aura['author']));
$page->header()->taxonomy = array_merge($page->header()->taxonomy, $author);
}

}

public function onPageInitialized()
{
$page = $this->grav['page'];
if ($page->template() === 'authors') {
$post = $this->grav['uri']->post();
if ($post) {
$authors = isset($post['data']['authors']) ? $post['data']['authors'] : [];
$file = File::instance(self::$authorsFile);
$file->save(Yaml::dump($authors));
$admin = $this->grav['admin'];
$admin->setMessage($admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info');
// TODO: tidy this section
// Also consider how to remove an author (currently need to go to expert mode)
// Also what if someone wants to set multiple author tags? should proably allow but only consider the aura one for meta output
if (isset($page->header()->taxonomy)) {
$taxonomy = $page->header()->taxonomy;
} else {
$taxonomy = [];
}
$taxonomy['author'] = array($page->header()->aura['author']);
$page->header()->taxonomy = $taxonomy;
}
}

public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/admin/templates';
}

public function onAdminMenu()
{
$this->grav['twig']->plugins_hooked_nav['Authors'] = ['route' => $this->route, 'icon' => 'fa-users'];
}

public static function listAuthors() {
$authorList = [];
$authors = self::getAuthors();
Expand All @@ -102,4 +94,19 @@ public static function listAuthors() {
return $authorList;
}

/**
* Create structured authors array and expose to Twig
*/
public function onTwigSiteVariables()
{
$authors = array();
$raw = $this->grav['config']->get('plugins.aura-authors.authors');
if ($raw) {
foreach ($raw as $author) {
$authors[$author['label']] = $author;
}
}
$this->grav['twig']->twig_vars['authors'] = $authors;
}

}
67 changes: 66 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Aura Authors
version: 0.1.0
version: 1.0.0
description: Store author bios in a central repository for display on multiple pages.
icon: users
author:
Expand Down Expand Up @@ -34,3 +34,68 @@ form:
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool
authors:
type: list
label: Author details
help: "Add or edit author details"
fields:
.name:
type: text
size: large
label: Name
validate:
required: true
.label:
type: text
size: large
label: Taxonomy Label
validate:
pattern: "[a-z][a-z0-9_\-]+"
message: "Use all lowercase letters and replace spaces with hyphens."
required: true
.image:
type: file
size: large
label: Image
multiple: false
destination: 'user/images'
accept:
- image/*
.description:
type: textarea
size: long
label: Description
.person-facebook-url:
type: text
size: large
label: Facebook URL
placeholder: 'https://www.facebook.com/username'
.person-twitter-user:
type: text
size: large
label: Twitter Username
placeholder: 'username'
.person-instagram-url:
type: text
size: large
label: Instagram URL
placeholder: 'https://www.instagram.com/username'
.person-linkedin-url:
type: text
size: large
label: LinkedIn URL
placeholder: 'https://www.linkedin.com/in/name'
.person-pinterest-url:
type: text
size: large
label: Pinterest URL
placeholder: 'https://www.pinterest.com/user/username'
.person-youtube-url:
type: text
size: large
label: YouTube URL
placeholder: 'https://www.youtube.com/username'
.person-website-url:
type: text
label: Website URL
placeholder: 'https://www.example.com'
11 changes: 6 additions & 5 deletions templates/partials/author-bio.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% set author = authors[page.header.aura.author] %}
{% if author %}
{% set social = [
'twitter',
'linkedin',
'youtube',
'facebook',
Expand All @@ -13,8 +12,7 @@
<p class="author-heading">About the author</p>
<hr />
{% if author.image %}
{% set path = 'user://plugins/aura-authors/assets/' ~ author.image|first.name %}
{{ media[path].html('', author.name, 'author-image') }}
{{ media['user://images/' ~ author.image|first.name].html('', author.name, 'author-image') }}
{% endif %}
<div class="author-text">
<div>
Expand All @@ -24,12 +22,15 @@
<div class="author-social">
<ul>
{% for item in social %}
{% set href = author[item ~ '-url'] %}
{% set href = author['person-' ~ item ~ '-url'] %}
{% if href %}
<li><a href="{{ href }}" target="_blank"><span class="aura-icon-{{ item }}"></span></a></li>
{% endif %}
{% endfor %}
</ul>
{% if author['person-twitter-user'] %}
<li><a href="https://twitter.com/{{ author['person-twitter-user'] }}" target="_blank"><span class="aura-icon-twitter"></span></a></li>
{% endif %}
</ul>&nbsp;
</div>
<div class="clear-right"></div>
</div>
Expand Down

0 comments on commit 7716ae9

Please sign in to comment.