From ba2bea2051b0e2b0fc027491dfd6185a42ea060c Mon Sep 17 00:00:00 2001 From: Steve Parks Date: Wed, 26 Jun 2024 17:33:16 +0000 Subject: [PATCH] Upgrade to for Statamic 5.x, and provide as an addon --- DOCUMENTATION.md | 7 ++-- README.md | 9 +++-- composer.json | 37 +++++++++++++++++++ meta.yaml | 6 --- .../Modifiers/WikilinksModifier.php | 24 +++++++----- src/ServiceProvider.php | 18 +++++++++ 6 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 composer.json delete mode 100755 meta.yaml rename WikilinksModifier.php => src/Modifiers/WikilinksModifier.php (57%) mode change 100755 => 100644 create mode 100644 src/ServiceProvider.php diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 1c8783c..c2a1e6f 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -1,11 +1,12 @@ ## Installing -- Install by copying the files into `site/addons/Wikilinks`. -- That's it. +``` +composer require statamic/wikilinks +``` ## Usage -Wikilinks is a simple modifier that seeks out any content wrapped in [braces] and automatically links it to other entries or pages with the same title (or other field of your choosing). +Wikilinks provides a simple modifier that seeks out any content wrapped in [braces] and automatically links it to other entries or pages with the same title (or other field of your choosing). ### Example diff --git a/README.md b/README.md index aee90ee..52675e7 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ -# Wikilinks ![Statamic v2](https://img.shields.io/badge/statamic-v2-blue.svg?style=flat-square) +# Wikilinks ![Statamic v5](https://img.shields.io/badge/statamic-v5-blue.svg?style=flat-square) -## Modifier -Wikilinks is a simple modifier that seeks out any content wrapped in [braces] and automatically links it to other entries or pages with the same title (or other field of your choosing). +Wikilinks is an add-on for Statamic 5.x that enables Wiki style [links] in the content of your site. + +It provides a simple modifier that seeks out any content wrapped in [braces] and automatically links it to other entries or pages with the same title (or other field of your choosing). ``` {{ content | wikilinks }} ``` + +See the Documentation for more details of usage. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a51ad5b --- /dev/null +++ b/composer.json @@ -0,0 +1,37 @@ +{ + "name": "statamic/wikilinks", + "autoload": { + "psr-4": { + "Statamic\\Wikilinks\\": "src" + } + }, + "autoload-dev": { + "psr-4": { + "Statamic\\Wikilinks\\Tests\\": "tests" + } + }, + "require": { + "statamic/cms": "^5.0" + }, + "require-dev": { + "orchestra/testbench": "^9.0" + }, + "config": { + "allow-plugins": { + "pixelfear/composer-dist-plugin": true + } + }, + "extra": { + "statamic": { + "name": "Wikilinks", + "description": "Wikilinks addon" + }, + "laravel": { + "providers": [ + "Statamic\\Wikilinks\\ServiceProvider" + ] + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} \ No newline at end of file diff --git a/meta.yaml b/meta.yaml deleted file mode 100755 index 5d3ec5b..0000000 --- a/meta.yaml +++ /dev/null @@ -1,6 +0,0 @@ -name: Wikilinks -version: "1.0" -description: 'Autolinks content wrapped in [braces], like a wiki.' -url: https://statamic.com/marketplace/addons/wikilinks -developer: Statamic -developer_url: https://statamic.com diff --git a/WikilinksModifier.php b/src/Modifiers/WikilinksModifier.php old mode 100755 new mode 100644 similarity index 57% rename from WikilinksModifier.php rename to src/Modifiers/WikilinksModifier.php index 34c618f..e93bda6 --- a/WikilinksModifier.php +++ b/src/Modifiers/WikilinksModifier.php @@ -1,12 +1,15 @@ $query) { - if ($result = Search::get($query, [$field])) { + $result = Entry::query() + ->where($field, $query) + ->first(); + + if ($result) { - $id = array_get($result->first(), 'id'); - $url = Content::find($id)->url(); + $uri = $result->uri; - $replacements[] = ($url) ? "{$query}" : $query; + $replacements[] = ($uri) ? "{$query}" : $query; } } return str_replace($matches[0], $replacements, $value); diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php new file mode 100644 index 0000000..8bfaabe --- /dev/null +++ b/src/ServiceProvider.php @@ -0,0 +1,18 @@ +