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:
parent
269ccc1bef
commit
449ece843a
3 changed files with 64 additions and 50 deletions
|
@ -4,6 +4,7 @@
|
||||||
* Upgrade to Lucky 0.30.1
|
* Upgrade to Lucky 0.30.1
|
||||||
* Upgrade to Crystal 1.5.0
|
* Upgrade to Crystal 1.5.0
|
||||||
* Add scrollbar to long code blocks
|
* Add scrollbar to long code blocks
|
||||||
|
* Add a downloadable config file for Redirector extension
|
||||||
|
|
||||||
2022-05-21
|
2022-05-21
|
||||||
|
|
||||||
|
|
55
src/actions/redirection_config/index.cr
Normal file
55
src/actions/redirection_config/index.cr
Normal 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
|
|
@ -22,58 +22,16 @@ class Faq::IndexPage < MainLayout
|
||||||
a "This extension", href: "https://einaregilsson.com/redirector/"
|
a "This extension", href: "https://einaregilsson.com/redirector/"
|
||||||
text " works well across most browsers."
|
text " works well across most browsers."
|
||||||
end
|
end
|
||||||
para "Once installed, create a new redirect with the following settings:"
|
para do
|
||||||
ul do
|
text "Once installed download a configuration file by "
|
||||||
li do
|
link "clicking here", to: RedirectionConfig::Index
|
||||||
strong "Description: "
|
text "."
|
||||||
code "Medium -> Scribe"
|
|
||||||
end
|
|
||||||
li do
|
|
||||||
strong "Example URL: "
|
|
||||||
code "https://medium.com/@user/post-123456abcdef"
|
|
||||||
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
|
end
|
||||||
h3 "Advanced options"
|
para do
|
||||||
ul do
|
text "Install it by opening the extension preferences, editing redirects, clicking "
|
||||||
li do
|
code "Import"
|
||||||
strong "Exclude pattern: "
|
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!"
|
||||||
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
|
end
|
||||||
para "Visiting any medium.com site (including user.medium.com subdomains) should now redirect to Scribe instead!"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue