Skip to content

Commit

Permalink
Merge pull request #24 from AayushSharma-1/main
Browse files Browse the repository at this point in the history
updated ai baithak & resources
  • Loading branch information
monk1337 authored Sep 18, 2024
2 parents 2f8ef19 + 894542c commit 8a6ab7f
Show file tree
Hide file tree
Showing 15 changed files with 523 additions and 106 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ gem "jekyll-github-metadata", ">= 2.15"
gem "jekyll-include-cache", group: :jekyll_plugins

gem "html-proofer", "~> 5.0", :group => :development

gem 'jekyll-remote-include'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ GEM
octokit (>= 4, < 7, != 4.4.0)
jekyll-include-cache (0.2.1)
jekyll (>= 3.7, < 5.0)
jekyll-remote-include (1.0.2)
jekyll-sass-converter (3.0.0)
sass-embedded (~> 1.54)
jekyll-seo-tag (2.8.0)
Expand Down Expand Up @@ -152,6 +153,7 @@ DEPENDENCIES
html-proofer (~> 5.0)
jekyll-github-metadata (>= 2.15)
jekyll-include-cache
jekyll-remote-include
just-the-docs!

BUNDLED WITH
Expand Down
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ plugins:
- jekyll-seo-tag
- jekyll-github-metadata
- jekyll-include-cache
- jekyll-remote-include

kramdown:
syntax_highlighter_opts:
Expand Down
45 changes: 37 additions & 8 deletions _site/assets/js/just-the-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ function initNav() {
menuButton.ariaPressed = false;
}
});

{%- if site.search_enabled != false and site.search.button %}
const searchInput = document.getElementById('search-input');
const searchButton = document.getElementById('search-button');

jtd.addEvent(searchButton, 'click', function(e){
e.preventDefault();

mainHeader.classList.add('nav-open');
searchInput.focus();
});
{%- endif %}
}

// The <head> element is assumed to include the following stylesheets:
Expand All @@ -69,32 +81,38 @@ function disableHeadStyleSheets() {
activation.disabled = true;
}
}

{%- if site.search_enabled != false %}
// Site search

function initSearch() {
var request = new XMLHttpRequest();
request.open('GET', '/assets/js/search-data.json', true);
request.open('GET', '{{ "assets/js/search-data.json" | relative_url }}', true);

request.onload = function(){
if (request.status >= 200 && request.status < 400) {
var docs = JSON.parse(request.responseText);

lunr.tokenizer.separator = /[\s/]+/
lunr.tokenizer.separator = {{ site.search.tokenizer_separator | default: site.search_tokenizer_separator | default: "/[\s\-/]+/" }}

var index = lunr(function(){
this.ref('id');
this.field('title', { boost: 200 });
this.field('content', { boost: 2 });
{%- if site.search.rel_url != false %}
this.field('relUrl');
{%- endif %}
this.metadataWhitelist = ['position']

for (var i in docs) {

{% include lunr/custom-index.js %}
this.add({
id: i,
title: docs[i].title,
content: docs[i].content,
{%- if site.search.rel_url != false %}
relUrl: docs[i].relUrl
{%- endif %}
});
}
});
Expand Down Expand Up @@ -258,7 +276,7 @@ function searchLoaded(index, docs) {
var previewEnd = position[0] + position[1];
var ellipsesBefore = true;
var ellipsesAfter = true;
for (var k = 0; k < 3; k++) {
for (var k = 0; k < {{ site.search.preview_words_before | default: 5 }}; k++) {
var nextSpace = doc.content.lastIndexOf(' ', previewStart - 2);
var nextDot = doc.content.lastIndexOf('. ', previewStart - 2);
if ((nextDot >= 0) && (nextDot > nextSpace)) {
Expand All @@ -273,7 +291,7 @@ function searchLoaded(index, docs) {
}
previewStart = nextSpace + 1;
}
for (var k = 0; k < 3; k++) {
for (var k = 0; k < {{ site.search.preview_words_after | default: 10 }}; k++) {
var nextSpace = doc.content.indexOf(' ', previewEnd + 1);
var nextDot = doc.content.indexOf('. ', previewEnd + 1);
if ((nextDot >= 0) && (nextDot < nextSpace)) {
Expand Down Expand Up @@ -333,7 +351,7 @@ function searchLoaded(index, docs) {
resultLink.appendChild(resultPreviews);

var content = doc.content;
for (var j = 0; j < Math.min(previewPositions.length, 2); j++) {
for (var j = 0; j < Math.min(previewPositions.length, {{ site.search.previews | default: 3 }}); j++) {
var position = previewPositions[j];

var resultPreview = document.createElement('div');
Expand All @@ -349,10 +367,13 @@ function searchLoaded(index, docs) {
}
}
}

{%- if site.search.rel_url != false %}
var resultRelUrl = document.createElement('span');
resultRelUrl.classList.add('search-result-rel-url');
resultRelUrl.innerText = doc.relUrl;
resultTitle.appendChild(resultRelUrl);
{%- endif %}
}

function addHighlightedText(parent, text, start, end, positions) {
Expand Down Expand Up @@ -442,6 +463,7 @@ function searchLoaded(index, docs) {
}
});
}
{%- endif %}

// Switch theme

Expand All @@ -452,7 +474,7 @@ jtd.getTheme = function() {

jtd.setTheme = function(theme) {
var cssFile = document.querySelector('[rel="stylesheet"]');
cssFile.setAttribute('href', '/assets/css/just-the-docs-' + theme + '.css');
cssFile.setAttribute('href', '{{ "assets/css/just-the-docs-" | relative_url }}' + theme + '.css');
}

// Note: pathname can have a trailing slash on a local jekyll server
Expand Down Expand Up @@ -500,13 +522,18 @@ function activateNav() {

jtd.onReady(function(){
initNav();
{%- if site.search_enabled != false %}
initSearch();
{%- endif %}
activateNav();
scrollNav();
});

// Copy button on code


{%- if site.enable_copy_code_button != false %}

jtd.onReady(function(){

if (!window.isSecureContext) {
Expand Down Expand Up @@ -547,6 +574,8 @@ jtd.onReady(function(){

});

})(window.jtd = window.jtd || {});
{%- endif %}

})(window.jtd = window.jtd || {});

{% include js/custom.js %}
Loading

0 comments on commit 8a6ab7f

Please sign in to comment.