diff --git a/CHANGELOG.md b/CHANGELOG.md index 50d458a..74d004c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ -# v0.1.0 -## 29-02-2020 +# v1.0.0 +## 23-06-2020 1. [](#new) * ChangeLog started... diff --git a/README.md b/README.md index 30e1391..da9106b 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/admin/assets/admin.min.js b/admin/assets/admin.min.js deleted file mode 100644 index 8089c52..0000000 --- a/admin/assets/admin.min.js +++ /dev/null @@ -1 +0,0 @@ -$(' ').prependTo('#authorSave'); \ No newline at end of file diff --git a/admin/assets/style.min.css b/admin/assets/style.min.css deleted file mode 100644 index 10f82b8..0000000 --- a/admin/assets/style.min.css +++ /dev/null @@ -1 +0,0 @@ -#authorSave{margin-left:1.5rem}#authorSave:active{margin:1px 0 -1px 1.5rem}#authorSave i{margin-right:5px} \ No newline at end of file diff --git a/admin/pages/authors.md b/admin/pages/authors.md deleted file mode 100644 index 0724c4c..0000000 --- a/admin/pages/authors.md +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: Authors - -access: - admin.authors: true - admin.super: true -form: - name: authors - action: '/authors' - template: authors - refresh_prevention: true - - fields: - authors: - type: list - display_label: false - collapsed: true - style: vertical - help: "Add or edit author details" - data-default@: ['\Grav\Plugin\AuraAuthorsPlugin::getAuthors'] - - 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' - - buttons: - submit: - type: submit - value: Save - classes: button - id: authorSave ---- diff --git a/admin/templates/authors.html.twig b/admin/templates/authors.html.twig deleted file mode 100644 index cc65fbc..0000000 --- a/admin/templates/authors.html.twig +++ /dev/null @@ -1,11 +0,0 @@ -{% extends 'partials/base.html.twig' %} - -{% block titlebar %} -

Authors

-{% endblock %} - -{% block content %} - {% include "forms/form.html.twig" %} - {% do assets.addCss('user://plugins/aura-authors/admin/assets/style.min.css') %} - {% do assets.addJs('user://plugins/aura-authors/admin/assets/admin.min.js', { 'loading':'defer' }) %} -{% endblock %} \ No newline at end of file diff --git a/assets/style.min.css b/assets/style.min.css index d28514b..7d42832 100644 --- a/assets/style.min.css +++ b/assets/style.min.css @@ -1 +1 @@ -.author-bio{background-color:#f5f5f5;margin:40px 0;padding:25px;border-radius:15px;overflow:hidden}.author-bio .author-heading{font-weight:bold;margin:0;padding:0}.author-bio hr{margin:5px 0 15px;padding:0}.author-bio .author-image{border-radius:50%;width:128px;height:auto;float:left;margin:0 25px 15px 0 !important;padding:0 !important}.author-bio .author-name{float:left;margin-bottom:10px}.author-bio .author-name p{font-weight:bolder;margin:0;padding:0}.author-bio .author-social{float:right;margin-bottom:10px}.author-bio .author-social ul{margin:0;padding:0;list-style:none}.author-bio .author-social ul li{display:inline}.author-bio .author-social ul li:not(:first-child){padding-left:10px}.author-bio .author-social ul li a,.author-bio .author-social ul li a:active,.author-bio .author-social ul li a:focus,.author-bio .author-social ul li a:hover{text-decoration:none}.author-bio .clear-right{clear:right}.author-bio .author-description p{overflow:hidden;margin:0;padding:0}@media only screen and (max-width: 767px){.author-bio .author-description p{overflow:unset}}@media only screen and (max-width: 575px){.author-bio .author-name,.author-bio .author-social{float:unset}}@font-face{font-family:"icomoon";src:url("fonts/icomoon.eot?aizbyq");src:url("fonts/icomoon.eot?aizbyq#iefix") format("embedded-opentype"),url("fonts/icomoon.ttf?aizbyq") format("truetype"),url("fonts/icomoon.woff?aizbyq") format("woff"),url("fonts/icomoon.svg?aizbyq#icomoon") format("svg");font-weight:normal;font-style:normal;font-display:block}[class^=aura-icon-],[class*=" aura-icon-"]{font-family:"icomoon" !important;speak:none;font-style:normal;font-weight:normal;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.aura-icon-website:before{content:""}.aura-icon-facebook:before{content:""}.aura-icon-instagram:before{content:""}.aura-icon-twitter:before{content:""}.aura-icon-youtube:before{content:""}.aura-icon-linkedin:before{content:""}.aura-icon-pinterest:before{content:""}/*# sourceMappingURL=style.min.css.map */ +.author-bio{background-color:#f5f5f5;margin:40px 0;padding:25px;border-radius:15px;overflow:hidden}.author-bio .author-heading{font-weight:bold;margin:0;padding:0}.author-bio hr{margin:5px 0 15px;padding:0}.author-bio .author-image{border-radius:50%;width:128px;height:auto;float:left;margin:0 25px 15px 0 !important;padding:0 !important}.author-bio .author-name{float:left;margin-bottom:10px}.author-bio .author-name p{font-weight:bolder;margin:0;padding:0}.author-bio .author-social{float:right;margin-bottom:10px}.author-bio .author-social ul{margin:0;padding:0;list-style:none}.author-bio .author-social ul li{display:inline}.author-bio .author-social ul li:not(:first-child){padding-left:10px}.author-bio .author-social ul li a,.author-bio .author-social ul li a:active,.author-bio .author-social ul li a:focus,.author-bio .author-social ul li a:hover{text-decoration:none}.author-bio .clear-right{clear:right}.author-bio .author-description p{overflow:hidden;margin:0;padding:0}@media only screen and (max-width: 767px){.author-bio .author-description p{overflow:unset}}@media only screen and (max-width: 575px){.author-bio .author-name,.author-bio .author-social{float:unset}}@font-face{font-family:"icomoon";src:url("fonts/icomoon.eot?aizbyq");src:url("fonts/icomoon.eot?aizbyq#iefix") format("embedded-opentype"),url("fonts/icomoon.ttf?aizbyq") format("truetype"),url("fonts/icomoon.woff?aizbyq") format("woff"),url("fonts/icomoon.svg?aizbyq#icomoon") format("svg");font-weight:normal;font-style:normal;font-display:block}[class^=aura-icon-],[class*=" aura-icon-"]{font-family:"icomoon" !important;speak:none;font-style:normal;font-weight:normal;font-variant:normal;text-transform:none;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.aura-icon-website:before{content:""}.aura-icon-facebook:before{content:""}.aura-icon-instagram:before{content:""}.aura-icon-twitter:before{content:""}.aura-icon-youtube:before{content:""}.aura-icon-linkedin:before{content:""}.aura-icon-pinterest:before{content:""}/*# sourceMappingURL=style.min.css.map */ diff --git a/assets/style.min.css.map b/assets/style.min.css.map index 8249569..ff9fb45 100644 --- a/assets/style.min.css.map +++ b/assets/style.min.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["style.scss"],"names":[],"mappings":"CAAA,YACE,yBACA,cACA,aACA,mBACA,gBACA,4BACE,iBACA,SACA,UAEF,eACE,kBACA,UAEF,0BACE,kBACA,YACA,YACA,WACA,gCACA,qBAEF,yBACE,WACA,mBACA,2BACE,mBACA,SACA,UAGJ,2BACE,YACA,mBACA,8BACE,SACA,UACA,gBACA,iCACE,eACA,mDACE,kBAEF,+JACE,qBAKR,yBACE,YAGA,kCACE,gBACA,SACA,UAKN,0CAGM,kCACE,gBAMR,0CAEI,oDACE,aAKN,WACE,sBACA,oCACA,+NAIA,mBACA,kBACA,mBAGF,2CAEE,iCACA,WACA,kBACA,mBACA,oBACA,oBACA,cAGA,mCACA,kCAGF,0BACE,YAEF,2BACE,YAEF,4BACE,YAEF,0BACE,YAEF,0BACE,YAEF,2BACE,YAEF,4BACE","file":"style.min.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["style.scss"],"names":[],"mappings":"AAAA,YACE,yBACA,cACA,aACA,mBACA,gBACA,4BACE,iBACA,SACA,UAEF,eACE,kBACA,UAEF,0BACE,kBACA,YACA,YACA,WACA,gCACA,qBAEF,yBACE,WACA,mBACA,2BACE,mBACA,SACA,UAGJ,2BACE,YACA,mBACA,8BACE,SACA,UACA,gBACA,iCACE,eACA,mDACE,kBAEF,+JACE,qBAKR,yBACE,YAGA,kCACE,gBACA,SACA,UAKN,0CAGM,kCACE,gBAMR,0CAEI,oDACE,aAKN,WACE,sBACA,oCACA,+NAIA,mBACA,kBACA,mBAGF,2CAEE,iCACA,WACA,kBACA,mBACA,oBACA,oBACA,cAGA,mCACA,kCAGF,0BACE,YAEF,2BACE,YAEF,4BACE,YAEF,0BACE,YAEF,0BACE,YAEF,2BACE,YAEF,4BACE","file":"style.min.css"} \ No newline at end of file diff --git a/aura-authors.php b/aura-authors.php index 0cf8738..8d9c372 100644 --- a/aura-authors.php +++ b/aura-authors.php @@ -4,8 +4,6 @@ namespace Grav\Plugin; 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 @@ -13,16 +11,13 @@ use Symfony\Component\Yaml\Yaml; */ 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() @@ -30,15 +25,26 @@ class AuraAuthorsPlugin extends Plugin // 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'; } /** @@ -48,8 +54,11 @@ class AuraAuthorsPlugin extends Plugin */ 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) @@ -61,37 +70,20 @@ class AuraAuthorsPlugin extends Plugin $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(); @@ -102,4 +94,19 @@ class AuraAuthorsPlugin extends Plugin 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; + } + } \ No newline at end of file diff --git a/blueprints.yaml b/blueprints.yaml index 8f3ee9f..61e0d93 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -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: @@ -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' diff --git a/templates/partials/author-bio.html.twig b/templates/partials/author-bio.html.twig index 7013341..75af7aa 100644 --- a/templates/partials/author-bio.html.twig +++ b/templates/partials/author-bio.html.twig @@ -1,7 +1,6 @@ {% set author = authors[page.header.aura.author] %} {% if author %} {% set social = [ - 'twitter', 'linkedin', 'youtube', 'facebook', @@ -13,8 +12,7 @@

About the author


{% 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 %}
@@ -24,12 +22,15 @@
    {% for item in social %} - {% set href = author[item ~ '-url'] %} + {% set href = author['person-' ~ item ~ '-url'] %} {% if href %}
  • {% endif %} {% endfor %} -
+ {% if author['person-twitter-user'] %} +
  • + {% endif %} +