From 9469863f44c93cafec05ef363623185c8443ad19 Mon Sep 17 00:00:00 2001 From: Fanny Mugnier Date: Fri, 5 Mar 2021 16:44:12 +0100 Subject: [PATCH] install auto-author plugin --- user/plugins/auto-author/.gitignore | 6 +++ user/plugins/auto-author/CHANGELOG.md | 5 ++ user/plugins/auto-author/LICENSE | 21 ++++++++ user/plugins/auto-author/README.md | 62 +++++++++++++++++++++++ user/plugins/auto-author/auto-author.php | 54 ++++++++++++++++++++ user/plugins/auto-author/auto-author.yaml | 2 + user/plugins/auto-author/blueprints.yaml | 39 ++++++++++++++ 7 files changed, 189 insertions(+) create mode 100644 user/plugins/auto-author/.gitignore create mode 100644 user/plugins/auto-author/CHANGELOG.md create mode 100644 user/plugins/auto-author/LICENSE create mode 100644 user/plugins/auto-author/README.md create mode 100644 user/plugins/auto-author/auto-author.php create mode 100644 user/plugins/auto-author/auto-author.yaml create mode 100644 user/plugins/auto-author/blueprints.yaml diff --git a/user/plugins/auto-author/.gitignore b/user/plugins/auto-author/.gitignore new file mode 100644 index 0000000..47ce0f1 --- /dev/null +++ b/user/plugins/auto-author/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +.idea +vendor +composer.phar +composer.lock +phpunit.xml \ No newline at end of file diff --git a/user/plugins/auto-author/CHANGELOG.md b/user/plugins/auto-author/CHANGELOG.md new file mode 100644 index 0000000..4b20062 --- /dev/null +++ b/user/plugins/auto-author/CHANGELOG.md @@ -0,0 +1,5 @@ +# v0.1.0 +## 09/03/2017 + +1. [](#new) + * ChangeLog started... diff --git a/user/plugins/auto-author/LICENSE b/user/plugins/auto-author/LICENSE new file mode 100644 index 0000000..4b7be87 --- /dev/null +++ b/user/plugins/auto-author/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Sven Sanzenbacher + +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/user/plugins/auto-author/README.md b/user/plugins/auto-author/README.md new file mode 100644 index 0000000..73bc17f --- /dev/null +++ b/user/plugins/auto-author/README.md @@ -0,0 +1,62 @@ +# Auto Author Plugin + +The **Auto Author** Plugin is for [Grav CMS](http://github.com/getgrav/grav). Automatically adds an author to frontmatter when creating a new page via Grav Admin plugin. + +## Usage + +Whenever you create a new page via the admin plugin, an author will be automatically inserted in the frontmatter of the page. The author name is dependent on the configuration. It can be the author name from `site.yaml` or the fullname of the current admin user. + +``` +user/pages/02.my-new-page/default.md +--- +title: 'My new page' +author: 'Joe Bloggs' +--- +``` + +## Installation + +Installing the Auto Author plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file. + +### GPM Installation (Preferred) + +The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's terminal (also called the command line). From the root of your Grav install type: + + bin/gpm install auto-author + +This will install the Auto Author plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/auto-author`. + +### Manual Installation + +To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `auto-author`. You can find these files on [GitHub](https://github.com/-sven-sanzenbacher/grav-plugin-auto-author) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras). + +You should now have all the plugin files under + + /your/site/grav/user/plugins/auto-author + +> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav) and the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) to operate. + +## Configuration + +Before configuring this plugin, you should copy the `user/plugins/auto-author/auto-author.yaml` to `user/config/plugins/auto-author.yaml` and only edit that copy. + +Here is the default configuration and an explanation of available options: + +```yaml +# enables or disables the plugin +enabled: true +# true = use current admin user (fullname) or false = use site author name (default) +user: false +``` + +## License + +The MIT License (MIT) + +Copyright (c) 2015 Sven Sanzenbacher + +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/user/plugins/auto-author/auto-author.php b/user/plugins/auto-author/auto-author.php new file mode 100644 index 0000000..e751fe6 --- /dev/null +++ b/user/plugins/auto-author/auto-author.php @@ -0,0 +1,54 @@ + ['onAdminCreatePageFrontmatter', 0] + ]; + } + + /** + * Initialize the plugin + * + * @param Event $event + */ + public function onAdminCreatePageFrontmatter(Event $event) + { + $header = $event['header']; + if (!isset($header['author'])) { + if ($this->config->get('plugins.auto-author.user')) { + /** + * @var Admin $admin + */ + $admin = $this->grav['admin']; + $author = $admin->user->get('fullname'); + + } else { + $author = $this->grav['config']->get('site.author.name'); + } + $header['author'] = $author; + $event['header'] = $header; + } + } +} diff --git a/user/plugins/auto-author/auto-author.yaml b/user/plugins/auto-author/auto-author.yaml new file mode 100644 index 0000000..1eaead7 --- /dev/null +++ b/user/plugins/auto-author/auto-author.yaml @@ -0,0 +1,2 @@ +enabled: true +user: false diff --git a/user/plugins/auto-author/blueprints.yaml b/user/plugins/auto-author/blueprints.yaml new file mode 100644 index 0000000..34aff83 --- /dev/null +++ b/user/plugins/auto-author/blueprints.yaml @@ -0,0 +1,39 @@ +name: Auto Author +version: 0.1.0 +description: Automatically adds an author to frontmatter when creating a new page via Grav Admin plugin +icon: user-circle +author: + name: Sven Sanzenbacher +homepage: https://github.com/naucon/grav-plugin-auto-author +keywords: grav, plugin, auto-author, author, autor, frontmatter +bugs: https://github.com/naucon/grav-plugin-auto-author/issues +docs: https://github.com/naucon/grav-plugin-auto-author/blob/develop/README.md +license: MIT + +dependencies: + - { name: admin, version: '>=1.2.3' } + +form: + validation: strict + fields: + enabled: + type: toggle + label: Plugin status + highlight: 1 + default: 0 + options: + 1: Enabled + 0: Disabled + validate: + type: bool + user: + type: toggle + label: Current user + highlight: 1 + default: 0 + options: + 1: Enabled + 0: Disabled + validate: + type: bool + help: use current admin user (fullname) or site author