diff --git a/plugins/breadcrumbs/CHANGELOG.md b/plugins/breadcrumbs/CHANGELOG.md new file mode 100644 index 0000000..6080f6c --- /dev/null +++ b/plugins/breadcrumbs/CHANGELOG.md @@ -0,0 +1,67 @@ +# v1.6.1 +## 12/02/2020 + +1. [](#improved) + * Minor default template improvements + +# v1.6.0 +## 04/22/2020 + +1. [](#new) + * Added `schema.org/BreadcrumbList` [#29] + * Added per-page option to control breadcrumbs [#20] + * Added various translations [#17][#18][#19] + * Pass phpstan level 1 tests + * Require Grav v1.6 + +# v1.5.1 +## 10/24/2017 + +1. [](#improved) + * Add option to ignore current page [#11] + * Removed Grav trait in favor of `Grav::instance()` + +# v1.5.0 +## 07/14/2016 + +1. [](#improved) + * non-routable pages are not linked + +# v1.4.0 +## 08/25/2015 + +1. [](#improved) + * Added blueprints for Grav Admin plugin + +# v1.3.0 +## 03/06/2015 + +1. [](#new) + * Added toggle for showing home item + * Added configurable home icon + * Added configurable divider icon + * Added toggle to link trailing item + +# v1.2.3 +## 02/05/2015 + +2. [](#improved) + * Added support for HHVM + +# v1.2.2 +## 01/23/2015 + +2. [](#improved) + * Added microdata information + +# v1.2.1 +## 01/09/2015 + +2. [](#improved) + * NOTE: BREAKING CHANGE: Moved templates into `partials/` subfolder for consistency. + +# v1.2.0 +## 11/30/2014 + +1. [](#new) + * ChangeLog started... diff --git a/plugins/breadcrumbs/LICENSE b/plugins/breadcrumbs/LICENSE new file mode 100644 index 0000000..484793a --- /dev/null +++ b/plugins/breadcrumbs/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Grav + +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/plugins/breadcrumbs/README.md b/plugins/breadcrumbs/README.md new file mode 100644 index 0000000..5f8d424 --- /dev/null +++ b/plugins/breadcrumbs/README.md @@ -0,0 +1,101 @@ +# Grav Breadcrumbs Plugin + +![Breadcrumbs](assets/readme_1.png) + +`Breadcrumbs` is a [Grav](http://github.com/getgrav/grav) plugin that adds links to the previous pages (following the hierarchical structure). +It is particularly useful if you are using Grav to run a blog. + +# Installation + +Installing the Breadcrumbs plugin can be done in one of two ways. Our 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 breadcrumbs + +This will install the Breadcrumbs plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/breadcrumbs`. + +## 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 `breadcrumbs`. You can find these files either on [GitHub](https://github.com/getgrav/grav-plugin-breadcrumbs) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras). + +You should now have all the plugin files under + + /your/site/grav/user/plugins/breadcrumbs + +>> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav), the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) plugins, and a theme to be installed in order to operate. + +# Usage + +The `breadcrumbs` plugin doesn't require any configuration. The moment you install it, it is ready to use. + +Something you might want to do is to override the look and feel of the breadcrumbs, and with Grav it is super easy. + +Copy the template file [breadcrumbs.html.twig](templates/partials/breadcrumbs.html.twig) into the `templates` folder of your custom theme, and that is it. + +``` +/your/site/grav/user/themes/custom-theme/templates/partials/breadcrumbs.html.twig +``` + +You can now edit the override and tweak it however you prefer. + +## Per-page Settings + +The following options are available for use in a page's YAML frontmatter, placed within the `breadcrumbs` mapping: + +| Option | Default | Values | Description | +|-------------|---------|-------------------|--------------------------------------------------------------------------------------| +| `max_depth` | `true` | `true` or `false` | Determines whether breadcrumbs for pages beneath the current page will be generated. | + +### Example Per-page Settings + +```yaml +--- +title: Some page you wrote +breadcrumbs: + may_descend: false # Breadcrumbs will not be generated for pages underneath this one. +--- +``` + +# Updating + +As development for the Breadcrumbs plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating Breadcrumbs is easy, and can be done through Grav's GPM system, as well as manually. + +## GPM Update (Preferred) + +The simplest way to update this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm). You can do this with this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following: + + bin/gpm update breadcrumbs + +This command will check your Grav install to see if your Breadcrumbs plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type `y` and hit enter. The plugin will automatically update and clear Grav's cache. + +## Manual Update + +Manually updating Breadcrumbs is pretty simple. Here is what you will need to do to get this done: + +* Delete the `your/site/user/plugins/breadcrumbs` directory. +* Download the new version of the Breadcrumbs plugin from either [GitHub](https://github.com/getgrav/grav-plugin-breadcrumbs) or [GetGrav.org](http://getgrav.org/downloads/plugins#extras). +* Unzip the zip file in `your/site/user/plugins` and rename the resulting folder to `breadcrumbs`. +* Clear the Grav cache. The simplest way to do this is by going to the root Grav directory in terminal and typing `bin/grav clear-cache`. + +> Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in `user/config/plugins`) will remain intact. + +## Configuration + +Simply copy the `user/plugins/breadcrumbs/breadcrumbs.yaml` into `user/config/plugins/breadcrumbs.yaml` and make your modifications. + +``` +enabled: true +show_all: true +built_in_css: true +include_home: true +include_current: true +icon_home: '' +icon_divider_classes: 'fa fa-angle-right' +link_trailing: false +``` + +Options are pretty self explanatory. + diff --git a/plugins/breadcrumbs/assets/readme_1.png b/plugins/breadcrumbs/assets/readme_1.png new file mode 100644 index 0000000..7837412 Binary files /dev/null and b/plugins/breadcrumbs/assets/readme_1.png differ diff --git a/plugins/breadcrumbs/blueprints.yaml b/plugins/breadcrumbs/blueprints.yaml new file mode 100644 index 0000000..f9f8f39 --- /dev/null +++ b/plugins/breadcrumbs/blueprints.yaml @@ -0,0 +1,99 @@ +name: Breadcrumbs +type: plugin +slug: breadcrumbs +version: 1.6.1 +description: The **Breadcrumbs** plugin provides a simple method to display the depth of your content/navigation structure. +icon: caret-square-o-right +author: + name: Team Grav + email: devs@getgrav.org + url: http://getgrav.org +homepage: https://github.com/getgrav/grav-plugin-breadcrumbs +demo: http://demo.getgrav.org/blog-skeleton +keywords: breadcrumbs, plugin, navigation, depth +bugs: https://github.com/getgrav/grav-plugin-breadcrumbs/issues +license: MIT +dependencies: + - { name: grav, version: '>=1.6.0' } + +form: + validation: strict + fields: + enabled: + type: toggle + label: PLUGIN_ADMIN.PLUGIN_STATUS + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + show_all: + type: toggle + label: PLUGIN_BREADCRUMBS.SHOW_WITH_ONE_ITEM + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + built_in_css: + type: toggle + label: PLUGIN_BREADCRUMBS.BUILTIN_CSS + highlight: 1 + default: 1 + help: PLUGIN_BREADCRUMBS.BUILTIN_CSS_HELP + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + include_home: + type: toggle + label: PLUGIN_BREADCRUMBS.INCLUDE_HOME + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + include_current: + type: toggle + label: PLUGIN_BREADCRUMBS.INCLUDE_CURRENT_PAGE + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool + + icon_home: + type: text + size: medium + label: PLUGIN_BREADCRUMBS.ICON_HOME + default: '' + + icon_divider_classes: + type: text + size: medium + label: PLUGIN_BREADCRUMBS.ICON_DIVIDER_CLASSES + default: 'fa fa-angle-right' + + link_trailing: + type: toggle + label: PLUGIN_BREADCRUMBS.LINK_TRAILING + highlight: 1 + default: 0 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool diff --git a/plugins/breadcrumbs/breadcrumbs.php b/plugins/breadcrumbs/breadcrumbs.php new file mode 100644 index 0000000..7c58ee4 --- /dev/null +++ b/plugins/breadcrumbs/breadcrumbs.php @@ -0,0 +1,70 @@ + [ + ['autoload', 100001], + ['onPluginsInitialized', 0] + ] + ]; + } + + /** + * [onPluginsInitialized:100000] Composer autoload. + * + * @return ClassLoader + */ + public function autoload() + { + return require __DIR__ . '/vendor/autoload.php'; + } + + /** + * Initialize configuration + */ + public function onPluginsInitialized() + { + if ($this->isAdmin()) { + $this->active = false; + return; + } + + class_alias(Breadcrumbs::class, 'Grav\\Plugin\\Breadcrumbs'); + + $this->enable([ + 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], + 'onTwigSiteVariables' => ['onTwigSiteVariables', 0] + ]); + } + + /** + * Add current directory to twig lookup paths. + */ + public function onTwigTemplatePaths() + { + $this->grav['twig']->twig_paths[] = __DIR__ . '/templates'; + } + + /** + * Set needed variables to display breadcrumbs. + */ + public function onTwigSiteVariables() + { + $this->grav['twig']->twig_vars['breadcrumbs'] = new Breadcrumbs($this->config->get('plugins.breadcrumbs')); + + if ($this->config->get('plugins.breadcrumbs.built_in_css')) { + $this->grav['assets']->add('plugin://breadcrumbs/css/breadcrumbs.css'); + } + } +} diff --git a/plugins/breadcrumbs/breadcrumbs.yaml b/plugins/breadcrumbs/breadcrumbs.yaml new file mode 100644 index 0000000..5364d9d --- /dev/null +++ b/plugins/breadcrumbs/breadcrumbs.yaml @@ -0,0 +1,8 @@ +enabled: true +show_all: true +built_in_css: true +include_home: true +include_current: true +icon_home: '' +icon_divider_classes: 'fa fa-angle-right' +link_trailing: false diff --git a/plugins/breadcrumbs/classes/plugin/Breadcrumbs.php b/plugins/breadcrumbs/classes/plugin/Breadcrumbs.php new file mode 100644 index 0000000..4e3aef1 --- /dev/null +++ b/plugins/breadcrumbs/classes/plugin/Breadcrumbs.php @@ -0,0 +1,123 @@ +config = $config; + } + + /** + * Return an array of breadcrumbs for the current page. + * + * @return array An array of breadcrumbs. + */ + public function get() + { + // If the breadcrumbs have not yet been generated... + if (!$this->breadcrumbs) { + // Generate them now. + $this->build(); + } + + return $this->breadcrumbs; + } + + /** + * Build the array of breadcrumbs. + * + * The array is generated by starting at the current page and then climbing + * the hierarchy until the root is reached. The resulting crumbs are then + * stored in the $breadcrumbs instance variable. + * + * @internal + */ + protected function build() + { + // Used to hold the breadcrumbs as they are being generated. + $hierarchy = array(); + + $grav = Grav::instance(); + $current = $grav['page']; + + // If the page is not routable... + if (!$current) { + // Set up an empty array of crumbs. + $this->breadcrumbs = array(); + return; + } + + // If we are not at the root page... + if (!$current->root()) { + + // If we are configured to include the current page... + if ($this->config['include_current']) { + // Place the current page in the hierarchy. + $hierarchy[$current->url()] = $current; + } + + $current = $current->parent(); + + // As long as $current does not contain the root page... + while ($current && !$current->root()) { + // Get the frontmatter of the page. + $header = $current->header(); + + // Assume we may descend unless otherwise told. + $may_descend = true; + + // If the frontmatter contains a value for $may_descend... + if(isset( + $header->breadcrumbs, + $header->breadcrumbs['may_descend'] + )) { + // Get that value. + $may_descend = $header->breadcrumbs['may_descend']; + } + + // Then, if breadcrumbs should stop at this page... + if ($may_descend === false) { + // Empty the $hierarchy. + $hierarchy = []; + } + + // Place the current page in the hierarchy. + $hierarchy[$current->url()] = $current; + + // Get the parent of the current page. + $current = $current->parent(); + } + } + + // If we are configured to include the home page... + if ($this->config['include_home']) { + // Get the home page. + $home = $grav['pages']->dispatch('/'); + + // If the home page isn't already in the hierarchy... + if ($home && !array_key_exists($home->url(), $hierarchy)) { + // Place the home page in the hierarchy. + $hierarchy[] = $home; + } + } + + // Reverse the array of breadcrumbs, so that they are in descending + // order. + $this->breadcrumbs = array_reverse($hierarchy); + } +} diff --git a/plugins/breadcrumbs/composer.json b/plugins/breadcrumbs/composer.json new file mode 100644 index 0000000..21f1979 --- /dev/null +++ b/plugins/breadcrumbs/composer.json @@ -0,0 +1,32 @@ +{ + "name": "grav-plugin-breadcrumbs", + "type": "grav-plugin", + "description": "Breadcrumbs plugin for Grav CMS", + "keywords": ["breadcrumbs"], + "homepage": "https://github.com/getgrav/grav-plugin-breadcrumbs/", + "license": "MIT", + "authors": [ + { + "name": "Team Grav", + "email": "devs@getgrav.org", + "homepage": "http://getgrav.org", + "role": "Developer" + } + ], + "require": { + "php": ">=7.1.3", + "ext-json": "*", + "ext-mbstring": "*" + }, + "autoload": { + "psr-4": { + "Grav\\Plugin\\Breadcrumbs\\": "classes/plugin" + }, + "classmap": ["breadcrumbs.php"] + }, + "config": { + "platform": { + "php": "7.1.3" + } + } +} diff --git a/plugins/breadcrumbs/composer.lock b/plugins/breadcrumbs/composer.lock new file mode 100644 index 0000000..87e59c5 --- /dev/null +++ b/plugins/breadcrumbs/composer.lock @@ -0,0 +1,24 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "df6ebb29e1322fb9746644198a99943b", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=7.1.3", + "ext-json": "*", + "ext-mbstring": "*" + }, + "platform-dev": [], + "platform-overrides": { + "php": "7.1.3" + } +} diff --git a/plugins/breadcrumbs/css/breadcrumbs.css b/plugins/breadcrumbs/css/breadcrumbs.css new file mode 100644 index 0000000..90a9df6 --- /dev/null +++ b/plugins/breadcrumbs/css/breadcrumbs.css @@ -0,0 +1,18 @@ +#breadcrumbs { + height: 3rem; + line-height: 3rem; + padding-left: 3rem; +} +#breadcrumbs span { + display: inline-block; + padding: 0 1rem; +} +#breadcrumbs span:first-child { + padding-left: 0; +} +#breadcrumbs i { + display: inline-block; + width: 20px; + text-align: center; +} + diff --git a/plugins/breadcrumbs/hebe.json b/plugins/breadcrumbs/hebe.json new file mode 100644 index 0000000..4550344 --- /dev/null +++ b/plugins/breadcrumbs/hebe.json @@ -0,0 +1,15 @@ +{ + "project":"grav-plugin-breadcrumbs", + "platforms":{ + "grav":{ + "nodes":{ + "plugin":[ + { + "source":"/", + "destination":"/user/plugins/breadcrumbs" + } + ] + } + } + } +} diff --git a/plugins/breadcrumbs/languages.yaml b/plugins/breadcrumbs/languages.yaml new file mode 100644 index 0000000..8f20b37 --- /dev/null +++ b/plugins/breadcrumbs/languages.yaml @@ -0,0 +1,32 @@ +en: + PLUGIN_BREADCRUMBS: + SHOW_WITH_ONE_ITEM: 'Show even with one item' + BUILTIN_CSS: 'Use built in CSS' + BUILTIN_CSS_HELP: 'Include the CSS provided by the plugin' + INCLUDE_HOME: 'Include Home' + INCLUDE_CURRENT_PAGE: 'Include Current Page' + ICON_HOME: 'Icon home' + ICON_DIVIDER_CLASSES: 'Icon Divider Classes' + LINK_TRAILING: 'Link Trailing' + +uk: + PLUGIN_BREADCRUMBS: + SHOW_WITH_ONE_ITEM: 'Показувати навіть з одним елементом' + BUILTIN_CSS: 'Використовувати вбудований CSS' + BUILTIN_CSS_HELP: 'Включити CSS, що надається плагіном' + INCLUDE_HOME: 'Включити головну сторінку' + INCLUDE_CURRENT_PAGE: 'Включати активну сторінку' + ICON_HOME: 'Іконка головної сторінки' + ICON_DIVIDER_CLASSES: 'Клас іконки розділювача' + LINK_TRAILING: 'Трейлінг посилання' + +ru: + PLUGIN_BREADCRUMBS: + SHOW_WITH_ONE_ITEM: 'Показывать даже с одним элементом' + BUILTIN_CSS: 'Использовать встроенный CSS' + BUILTIN_CSS_HELP: 'Включить CSS, предоставляемый плагином' + INCLUDE_HOME: 'Включить главную страницу' + INCLUDE_CURRENT_PAGE: 'Включать текущую страницу' + ICON_HOME: 'Иконка главной страницы' + ICON_DIVIDER_CLASSES: 'Класс иконки разделителя' + LINK_TRAILING: 'Трейлинг ссылки' diff --git a/plugins/breadcrumbs/templates/partials/breadcrumbs.html.twig b/plugins/breadcrumbs/templates/partials/breadcrumbs.html.twig new file mode 100644 index 0000000..fcb255a --- /dev/null +++ b/plugins/breadcrumbs/templates/partials/breadcrumbs.html.twig @@ -0,0 +1,38 @@ +{% set crumbs = breadcrumbs.get() %} +{% set breadcrumbs_config = config.plugins.breadcrumbs %} +{% set divider = breadcrumbs_config.icon_divider_classes %} + +{% if crumbs|length > 1 or breadcrumbs_config.show_all %} +
+{% endif %} diff --git a/plugins/breadcrumbs/vendor/autoload.php b/plugins/breadcrumbs/vendor/autoload.php new file mode 100644 index 0000000..e0bc823 --- /dev/null +++ b/plugins/breadcrumbs/vendor/autoload.php @@ -0,0 +1,7 @@ + + * Jordi Boggiano