commit ea84035fee9949c545961c77579387729e36e90a Author: Matt Mulhall Date: Sat Feb 29 15:45:04 2020 +1000 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..50d458a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# v0.1.0 +## 29-02-2020 + +1. [](#new) + * ChangeLog started... diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c936675 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Matt Mulhall + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..af95293 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Aura Authors Plugin + +The **Aura Authors** Plugin for [Grav CMS](https://github.com/getgrav/grav) enables you to store author bios in a centrally managed repository and have them displayed across various pages of your site. + +![Aura Authors Plugin for Grav - Demo](assets/demo-min.png) + +## Features + +* Easily manage author bios via the Grav admin interface +* Central repository ensures that a single change to an author's bio will automatically update it across multiple pages +* Optionally include author's image and links to social media accounts such as Twitter, LinkedIn etc. +* Use the included mobile and desktop responsive styling or provide your own + +## Installation + +It is recommended to install Aura Authors directly through the Admin Plugin by browsing to the `Plugins` tab and selecting `Add`. + +## Configuration + +* 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. + +``` + {% include 'partials/author-bio.html.twig' ignore missing %} +``` + +* The above will output the relevant author bio on all pages of that type, once an author is defined at the page level (see Usage below). Alternatively if you do not have access or do not wish to edit the theme you can include the code snippet directly within a page via the page editor. For this option to work you will need ensure Twig processing is enabled either at the page level (`Page Editor` > `Advanced` > `Overrides` > `Process`) or the site level (`Configuration` > `System` > `Content` > `Process`). + +* Optionally customise the layout of the author bio by copying the included templates/partials/author-bio.html.twig into the same location under your theme and editing it. Default styling can be disabled via the Plugin configuration panel if you wish to provide your own. + +## 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 Plugins panel. + +## Credits + +Includes a subset of the [IcoMoon - Free](https://icomoon.io/#icons-icomoon) icon pack. \ No newline at end of file diff --git a/assets/demo-min.png b/assets/demo-min.png new file mode 100644 index 0000000..67564e5 Binary files /dev/null and b/assets/demo-min.png differ diff --git a/assets/fonts/icomoon.eot b/assets/fonts/icomoon.eot new file mode 100644 index 0000000..8e5ba2b Binary files /dev/null and b/assets/fonts/icomoon.eot differ diff --git a/assets/fonts/icomoon.svg b/assets/fonts/icomoon.svg new file mode 100644 index 0000000..3e569cb --- /dev/null +++ b/assets/fonts/icomoon.svg @@ -0,0 +1,17 @@ + + + +Generated by IcoMoon + + + + + + + + + + + + + \ No newline at end of file diff --git a/assets/fonts/icomoon.ttf b/assets/fonts/icomoon.ttf new file mode 100644 index 0000000..ae57779 Binary files /dev/null and b/assets/fonts/icomoon.ttf differ diff --git a/assets/fonts/icomoon.woff b/assets/fonts/icomoon.woff new file mode 100644 index 0000000..6a6341f Binary files /dev/null and b/assets/fonts/icomoon.woff differ diff --git a/assets/style.min.css b/assets/style.min.css new file mode 100644 index 0000000..d28514b --- /dev/null +++ b/assets/style.min.css @@ -0,0 +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 */ diff --git a/assets/style.min.css.map b/assets/style.min.css.map new file mode 100644 index 0000000..8249569 --- /dev/null +++ b/assets/style.min.css.map @@ -0,0 +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 diff --git a/assets/style.scss b/assets/style.scss new file mode 100644 index 0000000..b6ea1fa --- /dev/null +++ b/assets/style.scss @@ -0,0 +1,128 @@ +.author-bio { + background-color: #F5F5F5; + margin: 40px 0; + padding: 25px; + border-radius: 15px; + overflow: hidden; + .author-heading { + font-weight: bold; + margin: 0; + padding: 0; + } + hr { + margin: 5px 0 15px; + padding: 0; + } + .author-image { + border-radius: 50%; + width: 128px; + height: auto; + float: left; + margin: 0 25px 15px 0 !important; + padding: 0 !important; + } + .author-name { + float: left; + margin-bottom: 10px; + p { + font-weight: bolder; + margin: 0; + padding: 0; + } + } + .author-social { + float: right; + margin-bottom: 10px; + ul { + margin: 0; + padding: 0; + list-style: none; + li { + display: inline; + &:not(:first-child) { + padding-left: 10px; + } + a, a:active, a:focus, a:hover { + text-decoration: none; + } + } + } + } + .clear-right { + clear: right; + } + .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-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-"] { + /* use !important to prevent issues with browser extensions that change fonts */ + font-family: 'icomoon' !important; + speak: none; + font-style: normal; + font-weight: normal; + font-variant: normal; + text-transform: none; + line-height: 1; + + /* Better Font Rendering =========== */ + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.aura-icon-website:before { + content: "\e9cb"; +} +.aura-icon-facebook:before { + content: "\ea90"; +} +.aura-icon-instagram:before { + content: "\ea92"; +} +.aura-icon-twitter:before { + content: "\ea96"; +} +.aura-icon-youtube:before { + content: "\ea9d"; +} +.aura-icon-linkedin:before { + content: "\eaca"; +} +.aura-icon-pinterest:before { + content: "\ead2"; +} \ No newline at end of file diff --git a/aura-authors.php b/aura-authors.php new file mode 100644 index 0000000..c122956 --- /dev/null +++ b/aura-authors.php @@ -0,0 +1,122 @@ + ['onPluginsInitialized', 0], + 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], + 'onPageInitialized' => ['onPageInitialized', 0], + 'onTwigSiteVariables' => ['onTwigSiteVariables', 0], + 'onBlueprintCreated' => ['onBlueprintCreated', 0], + ]; + } + + /** + * Initialize configuration + */ + public function onPluginsInitialized() + { + + // Add author to site taxonomies + $taxonomies = $this->config->get('site.taxonomies'); + $taxonomies[] = 'author'; + $this->config->set('site.taxonomies', $taxonomies); + + // Populate author list for use in blueprint + $authors = $this->grav['config']->get('plugins.aura-authors.authors'); + if ($authors) { + foreach ($authors as $author) { + if (!array_key_exists($author['label'], self::$authorList)) { + self::$authorList[$author['label']] = $author['name']; + } + } + } + asort(self::$authorList); + } + + + /** + * Extend page blueprints with additional configuration options. + * + * @param Event $event + */ + public function onBlueprintCreated(Event $event) + { + static $inEvent = false; + + /** @var Data\Blueprint $blueprint */ + $blueprint = $event['blueprint']; + if (!$inEvent && $blueprint->get('form/fields/tabs', null, '/')) { + $inEvent = true; + $blueprints = new Data\Blueprints(__DIR__ . '/blueprints/'); + $extends = $blueprints->get('aura-authors'); + $blueprint->extend($extends, true); + $inEvent = false; + } + } + + /** + * Add plugin directory to twig lookup paths + */ + public function onTwigTemplatePaths() + { + $this->grav['twig']->twig_paths[] = __DIR__ . '/templates'; + } + + /** + * Add author to page taxonomy + * + * @param Event $e + */ + public function onPageInitialized() + { + if ($this->isAdmin()) { + return; + } + $page = $this->grav['page']; + $header = $page->header(); + if ((isset($header->aura['author'])) && ($header->aura['author'] != '')) { + $taxonomy = $page->taxonomy(); + $taxonomy['author'][] = $header->aura['author']; + $page->taxonomy($taxonomy); + } + } + + /** + * 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; + } + + public static function listAuthors() { + return self::$authorList; + } + +} diff --git a/aura-authors.yaml b/aura-authors.yaml new file mode 100644 index 0000000..2a0ca0e --- /dev/null +++ b/aura-authors.yaml @@ -0,0 +1,2 @@ +enabled: true +include-css: true diff --git a/blueprints.yaml b/blueprints.yaml new file mode 100644 index 0000000..215f7ab --- /dev/null +++ b/blueprints.yaml @@ -0,0 +1,101 @@ +name: Aura Authors +version: 0.1.0 +description: Store author bios in a central repository for display on multiple pages. +icon: users +author: + name: Matt Mulhall + email: matt@theskylab.net + url: https://www.theskylab.net +homepage: https://github.com/matt-j-m/grav-plugin-aura-authors +keywords: author, bio, blog +bugs: https://github.com/matt-j-m/grav-plugin-aura-authors/issues +license: MIT + +form: + validation: strict + fields: + enabled: + type: toggle + label: PLUGIN_ADMIN.PLUGIN_STATUS + highlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + include-css: + type: toggle + label: Include default CSS + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 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/plugins/aura-authors/assets' + accept: + - image/* + .description: + type: textarea + size: long + label: Description + .facebook-url: + type: text + size: large + label: Facebook URL + placeholder: 'https://www.facebook.com/username' + .twitter-url: + type: text + size: large + label: Twitter URL + placeholder: 'https://twitter.com/username' + .instagram-url: + type: text + size: large + label: Instagram URL + placeholder: 'https://www.instagram.com/username' + .linkedin-url: + type: text + size: large + label: LinkedIn URL + placeholder: 'https://www.linkedin.com/in/name' + .pinterest-url: + type: text + size: large + label: Pinterest URL + placeholder: 'https://www.pinterest.com/user/username' + .youtube-url: + type: text + size: large + label: YouTube URL + placeholder: 'https://www.youtube.com/username' + .website-url: + type: text + label: Website URL + placeholder: 'https://www.example.com' diff --git a/blueprints/aura-authors.yaml b/blueprints/aura-authors.yaml new file mode 100644 index 0000000..1fb1e02 --- /dev/null +++ b/blueprints/aura-authors.yaml @@ -0,0 +1,17 @@ +form: + fields: + tabs: + fields: + aura: + type: tab + title: Aura + + fields: + + header.aura.author: + type: select + label: Author + size: medium + data-options@: '\Grav\Plugin\AuraAuthorsPlugin::listAuthors' + options: + '': '' diff --git a/templates/partials/author-bio.html.twig b/templates/partials/author-bio.html.twig new file mode 100644 index 0000000..7013341 --- /dev/null +++ b/templates/partials/author-bio.html.twig @@ -0,0 +1,44 @@ +{% set author = authors[page.header.aura.author] %} +{% if author %} + {% set social = [ + 'twitter', + 'linkedin', + 'youtube', + 'facebook', + 'instagram', + 'pinterest', + 'website', + ] %} +
+

About the author

+
+ {% if author.image %} + {% set path = 'user://plugins/aura-authors/assets/' ~ author.image|first.name %} + {{ media[path].html('', author.name, 'author-image') }} + {% endif %} +
+
+
+

{{ author.name }}

+
+
+
    + {% for item in social %} + {% set href = author[item ~ '-url'] %} + {% if href %} +
  • + {% endif %} + {% endfor %} +
+
+
+
+
+

{{ author.description }}

+
+
+
+ {% if config.plugins['aura-authors']['include-css'] %} + {% do assets.addCss('user://plugins/aura-authors/assets/style.min.css') %} + {% endif %} +{% endif %} \ No newline at end of file