Skip to content

Commit

Permalink
search and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bamr87 committed May 24, 2024
1 parent 71853c8 commit 47ac0f3
Show file tree
Hide file tree
Showing 20 changed files with 806 additions and 214 deletions.
2 changes: 1 addition & 1 deletion 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="container text-center mt-5">
<h1 class="display-1 text-danger">404</h1>

<p class="h4 mt-4"><strong>Page not found :(</strong></p>
<p class="h4 mt-4"><strong>Page not found 😿</strong></p>
<p class="lead">The requested page could not be found.</p>

<div class="my-4">
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ end
# gem "kramdown-parser-gfm", "~> 1.1.0"
# gem "rouge", "~> 3.36.0"

# gem "algoliasearch"
# gem "algolia"
gem "jekyll-algolia"
# gem "html-proofer"
8 changes: 4 additions & 4 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ plugins:
- jekyll-seo-tag
- jekyll-paginate
# - jekyll-assets
# - jekyll-algolia
- jekyll-algolia
# - jekyll-mermaid # https://mermaidjs.github.io/
# - jekyll-admin # https://github.com/jekyll/jekyll-admin
# - jekyll-redirect-from
Expand Down Expand Up @@ -423,9 +423,9 @@ sass:
# - /usr/local/bundle/gems/bootstrap-5.3.3/assets/stylesheets

algolia:
application_id: '99CKJ6KQ3Z'
search_only_api_key: '03a0c530bc2ff9acfde23485092602f3'
index_name: dev_lifehacker
application_id: 'SP02Z3YYL4'
search_only_api_key: '3b9200e21085fbebc263950c157b2682'
index_name: dev_it-journey

atom_feed:
path : # blank (default) uses feed.xml
Expand Down
3 changes: 3 additions & 0 deletions _data/navigation/home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
- title: Roadmap
icon: bi-map
url: /roadmap
sublinks:
- title: Search
url: /search/

12 changes: 2 additions & 10 deletions _data/navigation/main.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
- title: Quick-Start
url: /quick-start
url: /quickstart
sublinks:
- title: Home
url: /quickstart
- title: Master Setup
url: /quickstart/machine-setup
- title: Journey
url: /posts
sublinks:
- title: Home
url: /posts
- title: Quests
url: /quests
- title: Pages
url: /pages
- title: Library
url: /docs/
sublinks:
- title: Home
url: /docs
- title: Jekyll
url: /docs/jekyll
- title: Categories
Expand All @@ -33,15 +27,13 @@
- title: About
url: /about/
sublinks:
- title: Home
url: /about
- title: Config
url: /about/config
- title: Theme
url: /about/theme
- title: Contributing
url: /about/contributing
- title: Map
- title: Sitemap
url: /about/sitemap
- title: Features
url: /about/features
Expand Down
117 changes: 31 additions & 86 deletions _includes/algolia.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,113 +2,58 @@
file: algolia.html
sources:
https://www.algolia.com/doc/onboarding/,
https://community.algolia.com/jekyll-algolia/blog.html,
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/#the-instantsearch-instance,
https://www.algolia.com/doc/guides/building-search-ui/getting-started/js/,
https://www.algolia.com/doc/guides/building-search-ui/installation/js/
TODO: Uplift Algolia functionality
-->

<!-- https://www.algolia.com/doc/guides/building-search-ui/installation/js/ -->
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/algoliasearch-lite.umd.js" integrity="sha256-1QNshz86RqXe/qsCBldsUu13eAX6n/O98uubKQs87UI=" crossorigin="anonymous"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4.67.0/dist/instantsearch.production.min.js" integrity="sha256-TW7D3X/i/W+RUgEeDppEnFT2ixv5lzplKH0c58D92dY=" crossorigin="anonymous"></script> -->
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.[email protected]/themes/reset-min.css" integrity="sha256-2AeJLzExpZvqLUxMfcs+4DWcMwNfpnjUeAAvEtPr0wU=" crossorigin="anonymous"> -->

<script src="https://cdn.jsdelivr.net/npm/algoliasearch@4.23.3/dist/algoliasearch-lite.umd.js" integrity="sha256-1QNshz86RqXe/qsCBldsUu13eAX6n/O98uubKQs87UI=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/instantsearch.[email protected]/dist/instantsearch.production.min.js" integrity="sha256-AEialBwCKmHcqym8j00nCLu/FDy3530TKG9n6okJobM=" crossorigin="anonymous"></script>


<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch.min.css">
<!-- <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/instantsearch-theme-algolia.min.css"> -->
<script>
const searchClient = algoliasearch('{{ site.algolia.application_id }}', '{{ site.algolia.search_only_api_key }}');

const search = instantsearch({
appId: '{{ site.algolia.application_id }}',
apiKey: '{{ site.algolia.search_only_api_key }}',
indexName: '{{ site.algolia.index_name }}'
});

const hitTemplate = function(hit) {
let date = '';
if (hit.date) {
date = moment.unix(hit.date).format('MMM D, YYYY');
}

let url = `{{ site.baseurl }}${hit.url}#${hit.anchor}`;

const title = hit._highlightResult.title.value;

let breadcrumbs = '';
if (hit._highlightResult.headings) {
breadcrumbs = hit._highlightResult.headings.map(match => {
return `<span class="post-breadcrumb">${match.value}</span>`
}).join(' > ')
indexName: '{{ site.algolia.index_name }}',
searchClient,
searchFunction(helper) {
const container = document.querySelector('#hits');
if (helper.state.query === '') {
container.style.display = 'none';
return;
}
container.style.display = 'block';
helper.search();
}
});

const content = hit._highlightResult.html.value;

return `
<div class="post-item">
<span class="post-meta">${date}</span>
<h2><a class="post-link" href="${url}">${title}</a></h2>
{{#breadcrumbs}}<a href="${url}" class="post-breadcrumbs">${breadcrumbs}</a>{{/breadcrumbs}}
<div class="post-snippet">${content}</div>
</div>
`;
}


search.addWidget(
search.addWidgets([
instantsearch.widgets.searchBox({
container: '#search-searchbar',
placeholder: 'Search...',
poweredBy: true // This is required if you're on the free Community plan
})
);
container: '#searchbox',
}),

search.addWidget(
instantsearch.widgets.hits({
container: '#search-hits',
container: '#hits',
templates: {
item: hitTemplate
item: function(hit) {
return `
<div>
<h2>${hit.title}</h2>
<p>${hit.content}</p>
</div>
`;
}
}
})
);

]);

search.start();

</script>

<!-- <style>
.ais-search-box {
max-width: 100%;
margin-bottom: 15px;
}
.post-item {
margin-bottom: 30px;
}
.post-link .ais-Highlight {
color: #111;
font-style: normal;
text-decoration: underline;
}
.post-breadcrumbs {
color: #424242;
display: block;
}
.post-breadcrumb {
font-size: 18px;
color: #424242;
}
.post-breadcrumb .ais-Highlight {
font-weight: bold;
font-style: normal;
}
.post-snippet .ais-Highlight {
color: #2a7ae2;
font-style: normal;
font-weight: bold;
}
.post-snippet img {
display: none;
}
</style> -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/themes/satellite-min.css" integrity="sha256-p/rGN4RGy6EDumyxF9t7LKxWGg6/MZfGhJM/asKkqvA=" crossorigin="anonymous">

8 changes: 4 additions & 4 deletions _includes/searchbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
source: https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/
-->
<div class="container order-1">
<div id="search-searchbar" class="" ></div>
<div id="search-hits" class="text-start"></div>
</div>
<div class="container order-1">
<div id="searchbox" class="" ></div>
<div id="hits" class="text-start"></div>
</div>
146 changes: 123 additions & 23 deletions _includes/sitemap.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,123 @@
<h2>Sitemap of current collection</h2>

<ul>
{% for item in page.collections %}
<li>
<a href="{{ item.url | relative_url }}">{{ item.title }}</a>
</li>
{% endfor %}
</ul>


<h1>Sitemap</h1>

{% for collection in site.collections %}
<h2>{{ collection.label }}</h2>
<ul>
{% for item in collection.docs %}
<li>
<a href="{{ item.url | relative_url }}">{{ item.title }}</a>
</li>
{% endfor %}
</ul>
{% endfor %}
<!--
file: sitemap.html
path: _includes/sitemap.html
description: This is the snippet for the sitemap page.
-->

<h1>Sitemap - Index</h1>

<input type="text" id="searchBar" onkeyup="searchFunction()" placeholder="Search for keywords..">

<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col" data-type="string" data-order="desc">Collection <i class="sort-icon"></i></th>
<th scope="col" data-type="string" data-order="desc">Page <i class="sort-icon"></i></th>
<th scope="col" data-type="string" data-order="desc">Description<i class="sort-icon"></i></th>
<th scope="col" data-type="string" data-order="desc">Excerpt<i class="sort-icon"></i></th>
<th scope="col" data-type="string" data-order="desc">Path<i class="sort-icon"></i></th>
<th scope="col" data-type="date" data-order="desc">Last Modified Date <i class="sort-icon"></i></th>
<th scope="col" data-type="string" data-order="desc">Categories<i class="sort-icon"></i></th>
<th scope="col" data-type="string" data-order="desc">Tags<i class="sort-icon"></i></th>
<th scope="col" data-type="string" data-order="desc">Absolute URL<i class="sort-icon"></i></th>
<th scope="col" data-type="string" data-order="desc">Author <i class="sort-icon"></i></th>

</tr>
</thead>
<tbody>
{% for collection in site.collections %}
{% for item in collection.docs %}
<tr>
<td>{{ collection.label }}</td>
<td>
<a href="{{ item.url | relative_url }}">{{ item.title }}</a>
</td>
<td>{{ item.description }}</td>
<td>{{ item.excerpt }}</td>
<td>{{ item.path }}</td>
<td>{{ item.lastmod | date: "%Y/%m/%d" | default: "null" }}</td>
<td>{{ item.categories | join: ", " }}</td>
<td>{{ item.tags | join: ", " }}</td>
<td>
<a href="{{ site.url }}{{ item.url }}">{{ site.url }}{{ item.url }}</a>
</td>
<td>{{ item.author }}</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>

<!-- Sorting feature -->

<script>
document.querySelectorAll('th').forEach(header => {
header.addEventListener('click', () => {
const tableElement = document.querySelector('table');
const headerIndex = Array.prototype.indexOf.call(header.parentNode.children, header);
const currentTbody = tableElement.querySelector('tbody');
const newTbody = currentTbody.cloneNode(true);
const rows = Array.from(newTbody.querySelectorAll('tr'));
const type = header.getAttribute('data-type');
const order = header.getAttribute('data-order');
const sortedRows = rows.sort((a, b) => {
const aValue = a.children[headerIndex].textContent;
const bValue = b.children[headerIndex].textContent;
if (type === 'date') {
const aDate = aValue === "null" ? new Date(0) : new Date(...aValue.split('/').map((val, idx) => parseInt(val) - (idx === 1 ? 1 : 0))); // subtract 1 from month
const bDate = bValue === "null" ? new Date(0) : new Date(...bValue.split('/').map((val, idx) => parseInt(val) - (idx === 1 ? 1 : 0))); // subtract 1 from month
return order === 'asc' ? aDate - bDate : bDate - aDate;
}
return order === 'asc' ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
});
sortedRows.forEach(row => newTbody.appendChild(row));
tableElement.replaceChild(newTbody, currentTbody);
header.setAttribute('data-order', order === 'asc' ? 'desc' : 'asc');
document.querySelectorAll('.sort-icon').forEach(icon => icon.className = 'sort-icon'); // clear all icons
header.querySelector('.sort-icon').className = order === 'asc' ? 'sort-icon bi bi-arrow-down' : 'sort-icon bi bi-arrow-up'; // set the icon for the sorted column

});
});
</script>

<!-- searchbar script -->

<script>
function searchFunction() {
var input, filter, table, tr, td, i, j, txtValue;
input = document.getElementById("searchBar");
filter = input.value.toLowerCase();
table = document.getElementsByTagName("table");
tr = table[0].getElementsByTagName("tr");

for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td");
for (j = 0; j < td.length; j++) {
if (td[j]) {
txtValue = td[j].textContent || td[j].innerText;
if (txtValue.toLowerCase().indexOf(filter) > -1) {
tr[i].style.display = "";
break;
} else {
tr[i].style.display = "none";
}
}
}
}
}
</script>

<script>
// Parse the URL query parameters
const urlParams = new URLSearchParams(window.location.search);
// Get the 'q' parameter
const searchQuery = urlParams.get('q');
// If a search query was provided, set it as the value of the search bar
if (searchQuery) {
document.getElementById('searchBar').value = searchQuery;
// Call the search function
searchFunction();
}
</script>
Loading

0 comments on commit 47ac0f3

Please sign in to comment.