From 847005546b60c5a71a9803c6dcdc869dc7d0526e Mon Sep 17 00:00:00 2001 From: avanimathur Date: Wed, 23 Oct 2024 12:49:56 +0530 Subject: [PATCH 01/10] implement search bar --- _layouts/default.html | 29 ++++++++++++++++++++++++---- assets/css/style.css | 28 +++++++++++++++++++++++++++ assets/js/search.js | 45 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 assets/css/style.css diff --git a/_layouts/default.html b/_layouts/default.html index 89e492849c5..ac9af3c6072 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -1,19 +1,40 @@ -{% include head.html %} + {% include head.html %}
+ +
+ + +
+
+ + {{ content }}
+ + + + + - + - + \ No newline at end of file diff --git a/assets/css/style.css b/assets/css/style.css new file mode 100644 index 00000000000..e211566bbc4 --- /dev/null +++ b/assets/css/style.css @@ -0,0 +1,28 @@ +#searchBar { + width: 300px; + padding: 8px; +} + +button { + padding: 8px 12px; + background-color: #28a745; + color: white; + border: none; + cursor: pointer; +} + +#results div { + margin-top: 20px; + padding: 10px; + border: 1px solid #ddd; + background-color: #f9f9f9; +} + +#results h3 { + margin: 0; + font-size: 1.2em; +} + +#results p { + margin: 5px 0 0 0; +} diff --git a/assets/js/search.js b/assets/js/search.js index 40049c0fecb..602a244ec6e 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -98,4 +98,49 @@ function maintainHistoryState(event) { } } + // Additional code for Lunr.js integration + var searchBox = document.getElementById('searchBar'); + var searchResultsDiv = document.getElementById('results'); + + // Initialize Lunr.js + const documents = [ + { "id": 1, "title": "How to Contribute", "content": "Learn how to contribute to open source projects." }, + { "id": 2, "title": "Building a Community", "content": "Guidelines for creating and nurturing a community." }, + { "id": 3, "title": "Finding Users for Your Project", "content": "Strategies for getting users for your open source project." }, + // Add more guide data dynamically or statically + ]; + + const idx = lunr(function () { + this.ref('id'); + this.field('title'); + this.field('content'); + + documents.forEach(function (doc) { + this.add(doc); + }, this); + }); + + // Handle form submission and search + document.getElementById('searchForm').addEventListener('submit', function (e) { + e.preventDefault(); + const query = searchBox.value; + const results = idx.search(query); + displayResults(results); + }); + + // Function to display search results + function displayResults(results) { + searchResultsDiv.innerHTML = ''; // Clear previous results + + if (results.length > 0) { + results.forEach(result => { + const doc = documents.find(d => d.id === parseInt(result.ref)); + const resultItem = `

${doc.title}

${doc.content}

`; + searchResultsDiv.innerHTML += resultItem; + }); + } else { + searchResultsDiv.innerHTML = '

No results found

'; + } + } + })(); From f14148aac861182b09b4e48db645637586063bc7 Mon Sep 17 00:00:00 2001 From: avanimathur Date: Wed, 23 Oct 2024 13:06:27 +0530 Subject: [PATCH 02/10] align search bar --- assets/css/{style.css => style.scss} | 1 + 1 file changed, 1 insertion(+) rename assets/css/{style.css => style.scss} (93%) diff --git a/assets/css/style.css b/assets/css/style.scss similarity index 93% rename from assets/css/style.css rename to assets/css/style.scss index e211566bbc4..e31e4a012d1 100644 --- a/assets/css/style.css +++ b/assets/css/style.scss @@ -1,6 +1,7 @@ #searchBar { width: 300px; padding: 8px; + align-items: center; } button { From d138e573fbbda0bf9accc6c3f92d20df2544f0dc Mon Sep 17 00:00:00 2001 From: avanimathur Date: Wed, 23 Oct 2024 13:35:38 +0530 Subject: [PATCH 03/10] add search.json --- _layouts/default.html | 41 ++++++++++++++++++++++++++++++++++++- assets/js/search-index.json | 27 ++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 assets/js/search-index.json diff --git a/_layouts/default.html b/_layouts/default.html index ac9af3c6072..70e61d7245a 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -6,7 +6,7 @@
-
+
@@ -35,6 +35,45 @@ }(jQuery)); var $mcj = jQuery.noConflict(true); + + + \ No newline at end of file diff --git a/assets/js/search-index.json b/assets/js/search-index.json new file mode 100644 index 00000000000..51456667441 --- /dev/null +++ b/assets/js/search-index.json @@ -0,0 +1,27 @@ +[ + { + "id": "1", + "title": "Building Community", + "content": "A guide for building a healthy and inclusive open-source community. It covers steps like defining community roles, setting clear expectations, and offering mentorship." + }, + { + "id": "2", + "title": "Best Practices", + "content": "This guide discusses open-source best practices, including creating a clear README, using version control, writing contributing guidelines, and managing issues and pull requests effectively." + }, + { + "id": "3", + "title": "Starting an Open Source Project", + "content": "Learn how to start an open-source project. It includes tips on choosing a license, writing documentation, and finding contributors." + }, + { + "id": "4", + "title": "Leadership and Governance", + "content": "This article explains the importance of governance in open-source projects and provides advice on leadership structures and decision-making processes." + }, + { + "id": "5", + "title": "Metrics and Measuring Success", + "content": "Focuses on the importance of tracking metrics in open-source projects. It covers ways to measure success, including community growth, code contributions, and user feedback." + } + ] \ No newline at end of file From 419b6868681d1bce2e130faec6cb5ca345d12e6c Mon Sep 17 00:00:00 2001 From: avanimathur Date: Wed, 23 Oct 2024 14:52:34 +0530 Subject: [PATCH 04/10] update path --- assets/js/search-index.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/search-index.json b/assets/js/search-index.json index 51456667441..7ead78b0a60 100644 --- a/assets/js/search-index.json +++ b/assets/js/search-index.json @@ -2,7 +2,7 @@ { "id": "1", "title": "Building Community", - "content": "A guide for building a healthy and inclusive open-source community. It covers steps like defining community roles, setting clear expectations, and offering mentorship." + "content": "https://opensource.guide/maintaining-balance-for-open-source-maintainers/" }, { "id": "2", From 47982849ae0ee7499185d6002a56b15bc93d2886 Mon Sep 17 00:00:00 2001 From: avanimathur Date: Wed, 23 Oct 2024 15:17:14 +0530 Subject: [PATCH 05/10] implement search bar --- assets/js/search-index.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/search-index.json b/assets/js/search-index.json index 7ead78b0a60..51456667441 100644 --- a/assets/js/search-index.json +++ b/assets/js/search-index.json @@ -2,7 +2,7 @@ { "id": "1", "title": "Building Community", - "content": "https://opensource.guide/maintaining-balance-for-open-source-maintainers/" + "content": "A guide for building a healthy and inclusive open-source community. It covers steps like defining community roles, setting clear expectations, and offering mentorship." }, { "id": "2", From a312977f3993c9211ff0ff761f096bd1c3a4df49 Mon Sep 17 00:00:00 2001 From: avanimathur Date: Fri, 25 Oct 2024 11:00:28 +0530 Subject: [PATCH 06/10] update ui of searchbar --- _includes/nav.html | 10 ++++++++-- _layouts/default.html | 5 ----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/_includes/nav.html b/_includes/nav.html index 5a63da061fb..1aa4dc53a0f 100644 --- a/_includes/nav.html +++ b/_includes/nav.html @@ -2,6 +2,12 @@
- + \ No newline at end of file diff --git a/_layouts/default.html b/_layouts/default.html index 70e61d7245a..010fc72a303 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -5,11 +5,6 @@
- -
- - -
From 010ac84a5f80bdaf63cd57356ba70440cdfb7ff5 Mon Sep 17 00:00:00 2001 From: avanimathur Date: Fri, 25 Oct 2024 11:36:48 +0530 Subject: [PATCH 07/10] update ui --- _includes/nav.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_includes/nav.html b/_includes/nav.html index 1aa4dc53a0f..32da05388d4 100644 --- a/_includes/nav.html +++ b/_includes/nav.html @@ -5,7 +5,7 @@
- +