Skip to content

feat: search as URL parameter #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: search as URL parameters
  • Loading branch information
Malix-Labs authored Oct 1, 2024
commit da541606bd5787aa030da100dbc4cabc8a8c6861
34 changes: 29 additions & 5 deletions collections.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ <h1 style="margin-left: auto;margin-right: auto;">Collections</h1>
</p>

<input type="text" id="searchInput" placeholder="Search">

<br>
<br>

Expand Down Expand Up @@ -47,9 +46,7 @@ <h1 style="margin-left: auto;margin-right: auto;">Collections</h1>
const collectionTable = document.getElementById('collectionTable');
const rows = collectionTable.getElementsByTagName('tr');

searchInput.addEventListener('input', function () {
const searchValue = searchInput.value.toLowerCase();

function updateSearchResults(searchValue) {
for (let i = 1; i < rows.length; i++) {
const name = rows[i].getElementsByTagName('td')[0].textContent.toLowerCase();
const maintainer = rows[i].getElementsByTagName('td')[1].textContent.toLowerCase();
Expand All @@ -61,5 +58,32 @@ <h1 style="margin-left: auto;margin-right: auto;">Collections</h1>
rows[i].style.display = 'none';
}
}
}

function getSearchParameter() {
const params = new URLSearchParams(window.location.search);
return params.get('search') || '';
}

function setSearchParameter(value) {
const params = new URLSearchParams(window.location.search);
if (value) {
params.set('search', value);
} else {
params.delete('search');
}
window.history.replaceState({}, '', `${window.location.pathname}?${params.toString()}`);
}

searchInput.addEventListener('input', function () {
const searchValue = searchInput.value.toLowerCase();
setSearchParameter(searchValue);
updateSearchResults(searchValue);
});

document.addEventListener('DOMContentLoaded', function () {
const searchValue = getSearchParameter();
searchInput.value = searchValue;
updateSearchResults(searchValue);
});
</script>
</script>
37 changes: 31 additions & 6 deletions features.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Featur
<td class="tg-0lax"><b>Reference</b></td>
<td class="tg-0lax"><b>Latest Version</b></td>
</tr>

{% for c in site.data.devcontainer-index.collections %}
{% for f in c.features %}
{% if f.deprecated != true %}
Expand All @@ -48,7 +48,7 @@ <h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Featur
</tr>
{% endif %}
{% endfor %}

{% endfor %}
</table>

Expand All @@ -57,9 +57,7 @@ <h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Featur
const collectionTable = document.getElementById('collectionTable');
const rows = collectionTable.getElementsByTagName('tr');

searchInput.addEventListener('input', function () {
const searchValue = searchInput.value.toLowerCase();

function updateSearchResults(searchValue) {
for (let i = 1; i < rows.length; i++) {
const name = rows[i].getElementsByTagName('td')[0].textContent.toLowerCase();
const maintainer = rows[i].getElementsByTagName('td')[1].textContent.toLowerCase();
Expand All @@ -71,5 +69,32 @@ <h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Featur
rows[i].style.display = 'none';
}
}
}

function getSearchParameter() {
const params = new URLSearchParams(window.location.search);
return params.get('search') || '';
}

function setSearchParameter(value) {
const params = new URLSearchParams(window.location.search);
if (value) {
params.set('search', value);
} else {
params.delete('search');
}
window.history.replaceState({}, '', `${window.location.pathname}?${params.toString()}`);
}

searchInput.addEventListener('input', function () {
const searchValue = searchInput.value.toLowerCase();
setSearchParameter(searchValue);
updateSearchResults(searchValue);
});

document.addEventListener('DOMContentLoaded', function () {
const searchValue = getSearchParameter();
searchInput.value = searchValue;
updateSearchResults(searchValue);
});
</script>
</script>
47 changes: 37 additions & 10 deletions templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

<h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Templates</h1>
<p style="margin-left: auto;margin-right: auto;">
This table contains all official and community-supported <a href="implementors/templates/">Dev Container Templates</a>
known at the time of crawling <a href="collections">each registered collection</a>. This list is continuously
updated with the latest available Template information. See the <a href="https://github.com/devcontainers/template-starter">
Template quick start repository</a> to add your own!
This table contains all official and community-supported <a href="implementors/templates/">Dev Container
Templates</a>
known at the time of crawling <a href="collections">each registered collection</a>. This list is continuously
updated with the latest available Template information. See the <a
href="https://github.com/devcontainers/template-starter">
Template quick start repository</a> to add your own!
<br><br>
Templates listed here will be presented in the UX of <a href="supporting">supporting tools</a>.
<br><br>
Expand All @@ -33,7 +35,7 @@ <h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Templa
<td class="tg-0lax"><b>Reference</b></td>
<td class="tg-0lax"><b>Latest Version</b></td>
</tr>

{% for c in site.data.devcontainer-index.collections %}
{% for f in c.templates %}
<tr>
Expand All @@ -44,7 +46,7 @@ <h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Templa
<td class="tg-0lax"><code>{{ f.version | strip_html }}</code></td>
</tr>
{% endfor %}

{% endfor %}
</table>

Expand All @@ -53,9 +55,7 @@ <h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Templa
const collectionTable = document.getElementById('collectionTable');
const rows = collectionTable.getElementsByTagName('tr');

searchInput.addEventListener('input', function () {
const searchValue = searchInput.value.toLowerCase();

function updateSearchResults(searchValue) {
for (let i = 1; i < rows.length; i++) {
const name = rows[i].getElementsByTagName('td')[0].textContent.toLowerCase();
const maintainer = rows[i].getElementsByTagName('td')[1].textContent.toLowerCase();
Expand All @@ -66,5 +66,32 @@ <h1 style="margin-left: auto;margin-right: auto;">Available Dev Container Templa
rows[i].style.display = 'none';
}
}
}

function getSearchParameter() {
const params = new URLSearchParams(window.location.search);
return params.get('search') || '';
}

function setSearchParameter(value) {
const params = new URLSearchParams(window.location.search);
if (value) {
params.set('search', value);
} else {
params.delete('search');
}
window.history.replaceState({}, '', `${window.location.pathname}?${params.toString()}`);
}

searchInput.addEventListener('input', function () {
const searchValue = searchInput.value.toLowerCase();
setSearchParameter(searchValue);
updateSearchResults(searchValue);
});

document.addEventListener('DOMContentLoaded', function () {
const searchValue = getSearchParameter();
searchInput.value = searchValue;
updateSearchResults(searchValue);
});
</script>
</script>