Skip to content

Commit

Permalink
update pkgdown
Browse files Browse the repository at this point in the history
  • Loading branch information
bcallaway11 committed Jan 31, 2025
1 parent 4363c18 commit e3b397b
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
^\.Rproj\.user$
^docs$
^R/imputation_functions.R$
^_pkgdown\.yml$
^pkgdown$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
docs
14 changes: 14 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
url: https://bcallaway11.github.io/ptetools

template:
bootstrap: 5
bootswatch: united

navbar:
structure:
left: [reference, articles, news]
right: [github]
components:
github:
icon: fa-github
href: https://github.com/bcallaway11/ptetools
176 changes: 111 additions & 65 deletions docs/pkgdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,43 @@
(function($) {
$(function() {

$('.navbar-fixed-top').headroom();
$('nav.navbar').headroom();

$('body').css('padding-top', $('.navbar').height() + 10);
$(window).resize(function(){
$('body').css('padding-top', $('.navbar').height() + 10);
Toc.init({
$nav: $("#toc"),
$scope: $("main h2, main h3, main h4, main h5, main h6")
});

$('[data-toggle="tooltip"]').tooltip();

var cur_path = paths(location.pathname);
var links = $("#navbar ul li a");
var max_length = -1;
var pos = -1;
for (var i = 0; i < links.length; i++) {
if (links[i].getAttribute("href") === "#")
continue;
// Ignore external links
if (links[i].host !== location.host)
continue;

var nav_path = paths(links[i].pathname);

var length = prefix_length(nav_path, cur_path);
if (length > max_length) {
max_length = length;
pos = i;
}
}

// Add class to parent <li>, and enclosing <li> if in dropdown
if (pos >= 0) {
var menu_anchor = $(links[pos]);
menu_anchor.parent().addClass("active");
menu_anchor.closest("li.dropdown").addClass("active");
}
});

function paths(pathname) {
var pieces = pathname.split("/");
pieces.shift(); // always starts with /

var end = pieces[pieces.length - 1];
if (end === "index.html" || end === "")
pieces.pop();
return(pieces);
}

// Returns -1 if not found
function prefix_length(needle, haystack) {
if (needle.length > haystack.length)
return(-1);

// Special case for length-0 haystack, since for loop won't run
if (haystack.length === 0) {
return(needle.length === 0 ? 0 : -1);
if ($('#toc').length) {
$('body').scrollspy({
target: '#toc',
offset: $("nav.navbar").outerHeight() + 1
});
}

for (var i = 0; i < haystack.length; i++) {
if (needle[i] != haystack[i])
return(i);
}
// Activate popovers
$('[data-bs-toggle="popover"]').popover({
container: 'body',
html: true,
trigger: 'focus',
placement: "top",
sanitize: false,
});

return(haystack.length);
}
$('[data-bs-toggle="tooltip"]').tooltip();

/* Clipboard --------------------------*/

function changeTooltipMessage(element, msg) {
var tooltipOriginalTitle=element.getAttribute('data-original-title');
element.setAttribute('data-original-title', msg);
var tooltipOriginalTitle=element.getAttribute('data-bs-original-title');
element.setAttribute('data-bs-original-title', msg);
$(element).tooltip('show');
element.setAttribute('data-original-title', tooltipOriginalTitle);
element.setAttribute('data-bs-original-title', tooltipOriginalTitle);
}

if(ClipboardJS.isSupported()) {
$(document).ready(function() {
var copyButton = "<button type='button' class='btn btn-primary btn-copy-ex' type = 'submit' title='Copy to clipboard' aria-label='Copy to clipboard' data-toggle='tooltip' data-placement='left auto' data-trigger='hover' data-clipboard-copy><i class='fa fa-copy'></i></button>";
var copyButton = "<button type='button' class='btn btn-primary btn-copy-ex' title='Copy to clipboard' aria-label='Copy to clipboard' data-toggle='tooltip' data-placement='left' data-trigger='hover' data-clipboard-copy><i class='fa fa-copy'></i></button>";

$("div.sourceCode").addClass("hasCopyButton");

Expand All @@ -89,20 +49,106 @@
$('.btn-copy-ex').tooltip({container: 'body'});

// Initialize clipboard:
var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', {
var clipboard = new ClipboardJS('[data-clipboard-copy]', {
text: function(trigger) {
return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, "");
}
});

clipboardBtnCopies.on('success', function(e) {
clipboard.on('success', function(e) {
changeTooltipMessage(e.trigger, 'Copied!');
e.clearSelection();
});

clipboardBtnCopies.on('error', function() {
clipboard.on('error', function(e) {
changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy');
});

});
}

/* Search marking --------------------------*/
var url = new URL(window.location.href);
var toMark = url.searchParams.get("q");
var mark = new Mark("main#main");
if (toMark) {
mark.mark(toMark, {
accuracy: {
value: "complementary",
limiters: [",", ".", ":", "/"],
}
});
}

/* Search --------------------------*/
/* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */
// Initialise search index on focus
var fuse;
$("#search-input").focus(async function(e) {
if (fuse) {
return;
}

$(e.target).addClass("loading");
var response = await fetch($("#search-input").data("search-index"));
var data = await response.json();

var options = {
keys: ["what", "text", "code"],
ignoreLocation: true,
threshold: 0.1,
includeMatches: true,
includeScore: true,
};
fuse = new Fuse(data, options);

$(e.target).removeClass("loading");
});

// Use algolia autocomplete
var options = {
autoselect: true,
debug: true,
hint: false,
minLength: 2,
};
var q;
async function searchFuse(query, callback) {
await fuse;

var items;
if (!fuse) {
items = [];
} else {
q = query;
var results = fuse.search(query, { limit: 20 });
items = results
.filter((x) => x.score <= 0.75)
.map((x) => x.item);
if (items.length === 0) {
items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}];
}
}
callback(items);
}
$("#search-input").autocomplete(options, [
{
name: "content",
source: searchFuse,
templates: {
suggestion: (s) => {
if (s.title == s.what) {
return `${s.dir} > <div class="search-details"> ${s.title}</div>`;
} else if (s.previous_headings == "") {
return `${s.dir} > <div class="search-details"> ${s.title}</div> > ${s.what}`;
} else {
return `${s.dir} > <div class="search-details"> ${s.title}</div> > ${s.previous_headings} > ${s.what}`;
}
},
},
},
]).on('autocomplete:selected', function(event, s) {
window.location.href = s.path + "?q=" + q + "#" + s.id;
});
});
})(window.jQuery || window.$)
5 changes: 4 additions & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ pandoc: 3.1.3
pkgdown: 2.1.0
pkgdown_sha: ~
articles: {}
last_built: 2025-01-31T14:31Z
last_built: 2025-01-31T15:29Z
urls:
reference: https://bcallaway11.github.io/ptetools/reference
article: https://bcallaway11.github.io/ptetools/articles
Binary file removed inst/.CITATION.swp
Binary file not shown.

0 comments on commit e3b397b

Please sign in to comment.