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
This commit is contained in:
Edward Loveall 2022-07-17 14:40:02 -04:00
parent 269ccc1bef
commit 449ece843a
No known key found for this signature in database
GPG key ID: A7606DFEC2BA731F
3 changed files with 64 additions and 50 deletions

View file

@ -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

View file

@ -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?://(?:.*\\.)*(?<!(link\\.|cdn\\-images\\-\\d+\\.))medium\\.com(/.*)?$",
"excludePattern": "",
"patternDesc": "",
"redirectUrl": "https://#{app_domain}$2",
"patternType": "R",
"processMatches": "noProcessing",
"disabled": false,
"grouped": false,
"appliesTo": [
"main_frame",
"sub_frame",
"xmlhttprequest",
"history",
"other"
]
}
]
}
JSON
end
private def app_domain
URI.parse(Home::Index.url).normalize
.to_s
.sub(/\/$/, "")
.sub(/^https?:\/\//, "")
end
end

View file

@ -22,58 +22,16 @@ class Faq::IndexPage < MainLayout
a "This extension", href: "https://einaregilsson.com/redirector/"
text " works well across most browsers."
end
para "Once installed, create a new redirect with the following settings:"
ul do
li do
strong "Description: "
code "Medium -> Scribe"
para do
text "Once installed download a configuration file by "
link "clicking here", to: RedirectionConfig::Index
text "."
end
li do
strong "Example URL: "
code "https://medium.com/@user/post-123456abcdef"
para do
text "Install it by opening the extension preferences, editing redirects, clicking "
code "Import"
text " and selecting the downloaded file. This will add a new redirection and not overwrite any existing ones. Now visiting any medium.com site (including user.medium.com subdomains) should redirect to Scribe instead!"
end
li do
strong "Include pattern: "
code "^https?://(?:.*\\.)*(?<!(link\\.|cdn\\-images\\-\\d+\\.))medium\\.com(/.*)?$"
end
li do
strong "Redirect to: "
code "https://"
code app_domain
code "$2"
end
li do
strong "Pattern type: "
code "( ) Wildcard (•) Regular Expression"
end
end
h3 "Advanced options"
ul do
li do
strong "Exclude pattern: "
text "(leave blank)"
end
li do
strong "Process matches: "
code "No Processing"
end
li do
strong "Apply to: "
ul do
li { code "[x] Main window (address bar)" }
li { code "[x] IFrames" }
li { code "[ ] Stylesheets" }
li { code "[ ] Scripts" }
li { code "[ ] Images" }
li { code "[ ] Responsive images" }
li { code "[ ] Objects" }
li { code "[x] XMLHttpRequests" }
li { code "[x] History State" }
li { code "[x] Other" }
end
end
end
para "Visiting any medium.com site (including user.medium.com subdomains) should now redirect to Scribe instead!"
end
end