mirror of
https://github.com/neocities/neocities.git
synced 2025-08-13 04:49:34 +02:00
persist browse page search prefs, scrub not allowed chars for tag entry
This commit is contained in:
parent
2a76e75c6f
commit
321f8c6e29
3 changed files with 35 additions and 6 deletions
|
@ -2,6 +2,11 @@ get '/browse/?' do
|
||||||
@page = params[:page]
|
@page = params[:page]
|
||||||
@page = 1 if @page.not_an_integer?
|
@page = 1 if @page.not_an_integer?
|
||||||
|
|
||||||
|
if params[:tag]
|
||||||
|
params[:tag] = params[:tag].gsub(Tag::INVALID_TAG_REGEX, '').gsub(/\s+/, '').slice(0, Tag::NAME_LENGTH_MAX)
|
||||||
|
@title = "Sites tagged #{params[:tag]}"
|
||||||
|
end
|
||||||
|
|
||||||
if is_education?
|
if is_education?
|
||||||
ds = education_sites_dataset
|
ds = education_sites_dataset
|
||||||
else
|
else
|
||||||
|
@ -20,10 +25,6 @@ get '/browse/?' do
|
||||||
@site_tags[site_id] = tags.select {|t| t[:site_id] == site_id}.collect {|t| t[:name]}
|
@site_tags[site_id] = tags.select {|t| t[:site_id] == site_id}.collect {|t| t[:name]}
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:tag]
|
|
||||||
@title = "Sites tagged #{params[:tag]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
erb :browse
|
erb :browse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,35 @@
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<li>
|
<li>
|
||||||
<a href="/browse">Websites</a>
|
<a href="/browse" id="browse-link">Websites</a>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const browseLink = document.getElementById('browse-link');
|
||||||
|
|
||||||
|
if (window.location.pathname === '/browse') {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
const persistParams = new URLSearchParams();
|
||||||
|
const validPattern = /^[a-zA-Z0-9 ]+$/;
|
||||||
|
|
||||||
|
['sort_by', 'tag'].forEach(key => {
|
||||||
|
if (params.has(key)) {
|
||||||
|
const value = params.get(key);
|
||||||
|
if (value.length <= <%= Tag::NAME_LENGTH_MAX %> && validPattern.test(value)) {
|
||||||
|
persistParams.set(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
localStorage.setItem('browseQuery', persistParams.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
const savedQuery = localStorage.getItem('browseQuery');
|
||||||
|
|
||||||
|
if (savedQuery) {
|
||||||
|
browseLink.href = `/browse?${savedQuery}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</li>
|
</li>
|
||||||
<% unless is_education? %>
|
<% unless is_education? %>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<fieldset class="grouping">
|
<fieldset class="grouping">
|
||||||
<% unless is_education? %>
|
<% unless is_education? %>
|
||||||
<label class="text-Label" for="tag"><span class="hide-on-mobile">Filter by </span>Tag:</label>
|
<label class="text-Label" for="tag"><span class="hide-on-mobile">Filter by </span>Tag:</label>
|
||||||
<input class="input-Area typeahead" id="tag" name="tag" type="text" placeholder="pokemon" value="<%= params[:tag] %>" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" dir="auto">
|
<input class="input-Area typeahead" id="tag" name="tag" type="text" placeholder="pokemon" value="<%= params[:tag] %>" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" dir="auto" oninput="this.value = this.value.replace(/[^a-zA-Z0-9]+/g, '')">
|
||||||
<input style="vertical-align: -4px;margin-left: 4px;" type="submit" class="btn-Action" value="Filter">
|
<input style="vertical-align: -4px;margin-left: 4px;" type="submit" class="btn-Action" value="Filter">
|
||||||
<% else %>
|
<% else %>
|
||||||
<% if params[:tag] %>
|
<% if params[:tag] %>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue