Skip to content

Commit fa12ab8

Browse files
committed
feat: add strategy selection to form
1 parent feae0ef commit fa12ab8

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

public/auto_source.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
margin-right: 0;
2020
}
2121

22+
.auto_source > form label {
23+
display: flex;
24+
justify-content: center;
25+
align-items: center;
26+
}
27+
28+
.auto_source > form label > span {
29+
flex: 1;
30+
}
31+
32+
.auto_source > form label > input {
33+
flex: 0;
34+
}
35+
2236
.auto_source > nav {
2337
display: flex;
2438
flex-direction: column;

public/auto_source.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ const autoSource = (function () {
9393

9494
if (this.isValidUrl(url)) {
9595
const encodedUrl = this.encodeUrl(url);
96-
const autoSourceUrl = this.generateAutoSourceUrl(encodedUrl);
96+
const params = {};
97+
const strategy = this.form?.querySelector('input[name="strategy"]:checked')?.value;
98+
if (strategy) {
99+
params["strategy"] = strategy;
100+
}
101+
102+
const autoSourceUrl = this.generateAutoSourceUrl(encodedUrl, params);
97103

98104
this.rssUrlInput.value = autoSourceUrl;
99105
this.rssUrlInput.select();
@@ -132,9 +138,12 @@ const autoSource = (function () {
132138
* @param {string} encodedUrl - The base64 encoded URL.
133139
* @returns {string} The generated auto-source URL.
134140
*/
135-
generateAutoSourceUrl(encodedUrl) {
141+
generateAutoSourceUrl(encodedUrl, params = {}) {
136142
const baseUrl = new URL(window.location.origin);
137-
return `${baseUrl}${BASE_PATH}/${encodedUrl}`;
143+
144+
const url = new URL(`${baseUrl}${BASE_PATH}/${encodedUrl}`);
145+
url.search = new URLSearchParams(params).toString();
146+
return url.toString();
138147
}
139148

140149
/**

views/auto_source/index.erb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,29 @@
2121
autocomplete="on"
2222
token-list="url"
2323
autofocus
24-
required>
24+
required
25+
>
26+
27+
<%- default_strategy_name = Html2rss::RequestService.default_strategy_name %>
28+
<fieldset>
29+
<legend>Strategy</legend>
30+
<% Html2rss::RequestService.strategy_names.each do |strategy| %>
31+
<label>
32+
<input type="radio" name="strategy"
33+
value="<%= strategy %>"
34+
<%= 'checked' if strategy.to_sym == default_strategy_name %>
35+
>
36+
<span><%= strategy %></span>
37+
</label>
38+
<% end %>
39+
</fieldset>
2540
<input type="submit" value="Generate">
2641
</form>
2742

2843
<label>
2944
<img src="/feed.svg" height="16" width="16" alt="the orange RSS icon" role="presentation"/>
30-
Feed URL
31-
<input type="url" id="rss_url" readonly>
45+
Feed URL
46+
<input type="url" id="rss_url" readonly>
3247
</label>
3348

3449
<nav>

0 commit comments

Comments
 (0)