diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8864d4a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 + +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..9008348 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# ⚓ Broken Links Checker Widget by [@wottpal](https://twitter.com/wottpal) + + +![Release](https://img.shields.io/github/release/wottpal/kirby-broken-links-widget/all.svg) +[![MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/wottpal/kirby-broken-links-widget/master/LICENSE) +[![Tweet](https://img.shields.io/twitter/url/https/github.com/wottpal/kirby-broken-links-widget.svg?style=social)](https://twitter.com/intent/tweet?text=⚓ Anchor-Headings for @getkirby by @wottpal&url=https://git.io/v7aFU) + + +A panel-widget for the [Kirby CMS](https://getkirby.com) which shows broken links within the pages. + + +![Screenshot of the Broken-Links Panel-Widget](demo.png) + +_Disclaimer:_ This is a pre-release and it is not feature-complete yet. (see *Roadmap* below) + + +# Installation + +Use [Kirby's CLI](https://github.com/getkirby/cli) and install the plugin via: `kirby plugin:install wottpal/kirby-broken-links-widget` or place the repo manually under `site/plugins` (without the `kirby-` prefix). + +🎉 **That's it.** + + +# Options + +The following options can be set globally in your `config.php` with `c::set($key, $value = null)`. You can also set multiple keys with `c::set([$key => $value, ..])`. 🤓 + +**Please prefix every key with `broken-links.`!** + +key | default | description +----------------- | ------- | ------------------------------------------------ +`include-external` | `false` | Not only test for internal links but also for external ones.* + +\* **Not recommended yet because it only works synchonously with the page-load of your panel which will slow everything quite down a bit.** + + +# Changelog + +Have a look at the [releases page](https://github.com/wottpal/kirby-anchor-headings/releases). + + +# Roadmap + +- [ ] Do checks asynchronously +- [ ] Make pages/links excludable +- [ ] At the moment it only looks at fields with the name `text`. Make this user-definable per page. +- [ ] Check for internet-connection (if external links are enabled) + + + +# 💰‍ Pricing +Just kidding. This plugin is totally free. Please consider following [me](https://twitter.com/wottpal) on Twitter if it saved your day. + +[![Twitter Follow](https://img.shields.io/twitter/follow/wottpal.svg?style=social&label=Follow)](https://twitter.com/wottpal) + +You can also check out one of [my other Kirby-plugins](https://wottpal.com/items/my-kirby-plugins): + +* [Lightbox-Gallery](https://github.com/wottpal/kirby-lightbox-gallery) - Easily inline beautifully aligned galleries with lightbox-support powered by PhotoSwipe. +* [HTML5-Video Kirbytag](https://github.com/wottpal/kirby-video) - Adds a kirbytag for embedding HTML5-videos with a variety of features. +* [Anchor-Headings](https://github.com/wottpal/kirby-anchor-headings) - A kirby field-method which enumerates heading-elements, generates IDs for anchor-links and inserts custom markup based on your needs. diff --git a/broken-links-widget.php b/broken-links-widget.php new file mode 100644 index 0000000..6c1d8c2 --- /dev/null +++ b/broken-links-widget.php @@ -0,0 +1,13 @@ + +* @version 0.1.0 +* +*/ + + +$kirby->set('widget', 'broken-links', __DIR__ . DS . 'broken-links'); diff --git a/broken-links/broken-links.php b/broken-links/broken-links.php new file mode 100644 index 0000000..2aa2f55 --- /dev/null +++ b/broken-links/broken-links.php @@ -0,0 +1,59 @@ + 'Broken Links', + + // 'options' => [ + // [ + // 'text' => 'Check now', + // 'icon' => 'play-circle-o', + // 'link' => '#imagekit-action-create', + // ], + // ], + + 'html' => function () { + $site = panel()->site(); + $all_links = []; + $broken_links = []; + $regex = '/https?\:\/\/[^\" \n]+/i'; + $base_url = $site->url(); + + // Gather Plugin-Options + $include_external = c::get('broken-links.include-external', false); + + // Determine all links in all pages + foreach($site->index() as $page) { + if ($page->text()->isNotEmpty()) { + $text = $page->text()->kt(); + preg_match_all($regex, $text, $matches); + + // Determine internal & broken links + foreach($matches[0] as $link) { + $is_internal = substr($link, 0, strlen($base_url)) === $base_url; + if (!$is_internal && !$include_external) continue; + + $is_broken = get_http_response_code($link) == '404'; + if (!$is_broken) continue; + + // Remove Base-URL Prefix (internal) + if ($is_internal) { + $link = substr($link, strlen($base_url)); + } + + $broken_links[$page->id()][] = $link; + } + } + } + + // Populate the Widget-Template + return tpl::load(__DIR__ . DS . 'template.php', [ + 'broken_links' => $broken_links, + 'has_broken_links' => !empty(array_filter($broken_links)) + ]); + } + +]; diff --git a/broken-links/template.php b/broken-links/template.php new file mode 100644 index 0000000..1abe87a --- /dev/null +++ b/broken-links/template.php @@ -0,0 +1,50 @@ + + + + + + + +
+
All internal links seem to be okay.
+
+ + + + + + + + diff --git a/demo.png b/demo.png new file mode 100644 index 0000000..1884f1f Binary files /dev/null and b/demo.png differ diff --git a/helpers.php b/helpers.php new file mode 100644 index 0000000..9fd6772 --- /dev/null +++ b/helpers.php @@ -0,0 +1,19 @@ + (https://wottpal.com)", + "version": "0.1.0", + "type": "kirby-plugin", + "license": "MIT" +}