diff --git a/_includes/nav.html b/_includes/nav.html index 5a63da061fb..710fec33199 100644 --- a/_includes/nav.html +++ b/_includes/nav.html @@ -2,8 +2,15 @@ + \ No newline at end of file diff --git a/_layouts/default.html b/_layouts/default.html index 89e492849c5..010fc72a303 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -1,19 +1,74 @@ -{% include head.html %} + {% include head.html %}
+
+ + {{ content }}
+ + + + + - + + + + - + \ No newline at end of file diff --git a/assets/css/style.scss b/assets/css/style.scss new file mode 100644 index 00000000000..e31e4a012d1 --- /dev/null +++ b/assets/css/style.scss @@ -0,0 +1,29 @@ +#searchBar { + width: 300px; + padding: 8px; + align-items: center; +} + +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-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 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

'; + } + } + })();