From 449ece843a1e92246a25d060a29f128c4b8ddb60 Mon Sep 17 00:00:00 2001 From: Edward Loveall Date: Sun, 17 Jul 2022 14:40:02 -0400 Subject: [PATCH] Provide a configuration file for the Redirector extension Instead of providing long detailed instructions for how to configure the Redirector extension, this provides a single json file that users can import. I started by making a single file stored in the `public/assets` directory, but then realized this was a regression since the instructions were customized to each domain. Instead I can use Lucky's [data] response to dynamically build the JSON config. [data]: https://luckyframework.org/guides/http-and-routing/request-and-response# handling-responses --- CHANGELOG | 1 + src/actions/redirection_config/index.cr | 55 +++++++++++++++++++++++ src/pages/faq/index_page.cr | 58 ++++--------------------- 3 files changed, 64 insertions(+), 50 deletions(-) create mode 100644 src/actions/redirection_config/index.cr diff --git a/CHANGELOG b/CHANGELOG index d90eb3c..dfab3ea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ * Upgrade to Lucky 0.30.1 * Upgrade to Crystal 1.5.0 * Add scrollbar to long code blocks +* Add a downloadable config file for Redirector extension 2022-05-21 diff --git a/src/actions/redirection_config/index.cr b/src/actions/redirection_config/index.cr new file mode 100644 index 0000000..fa7af09 --- /dev/null +++ b/src/actions/redirection_config/index.cr @@ -0,0 +1,55 @@ +class RedirectionConfig::Index < Lucky::Action + include Lucky::ProtectFromForgery + include Lucky::EnforceUnderscoredRoute + include Lucky::SecureHeaders::DisableFLoC + + default_format :json + + get "/redirection_config" do + data( + data: config_json, + content_type: "application/json", + disposition: "attachment", + filename: "redirector-config.json" + ) + end + + private def config_json + <<-JSON + { + "createdBy": "Redirector v3.5.3", + "createdAt": "2022-07-17T00:00:00.000Z", + "redirects": [ + { + "description": "Medium -> Scribe", + "exampleUrl": "https://medium.com/@user/post-123456abcdef", + "exampleResult": "https://#{app_domain}/@user/post-123456abcdef", + "error": null, + "includePattern": "^https?://(?:.*\\.)*(? Scribe" - end - li do - strong "Example URL: " - code "https://medium.com/@user/post-123456abcdef" - end - li do - strong "Include pattern: " - code "^https?://(?:.*\\.)*(?