Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Docs: Add client-side search functionality
Maximilian Roosb2c3d70f51ba
diff --git a/docs/content/commands.md b/docs/content/commands.mdindex 41cd1e17a..72d34c710 100644--- a/docs/content/commands.md+++ b/docs/content/commands.md@@ -7,7 +7,7 @@ weight = 6<!-- ⚠️ AUTO-GENERATED from `wt switch --help-md` — edit source to update -->-```+```bashwt switch — Switch to a worktreeUsage: wt switch [OPTIONS] <BRANCH>@@ -161,7 +161,7 @@ wt remove @ # Remove current worktree<!-- ⚠️ AUTO-GENERATED from `wt merge --help-md` — edit source to update -->-```+```bashwt merge — Merge worktree into target branchUsage: wt merge [OPTIONS] [TARGET]@@ -281,7 +281,7 @@ wt merge --no-verify<!-- ⚠️ AUTO-GENERATED from `wt remove --help-md` — edit source to update -->-```+```bashwt remove — Remove worktree and branchUsage: wt remove [OPTIONS] [WORKTREES]...@@ -419,7 +419,7 @@ wt remove # (when already in main worktree)<!-- ⚠️ AUTO-GENERATED from `wt list --help-md` — edit source to update -->-```+```bashwt list — List worktrees and optionally branchesUsage: wt list [OPTIONS]wt list <COMMAND>@@ -562,7 +562,7 @@ jq '.[] | select(.is_current == true)'<!-- ⚠️ AUTO-GENERATED from `wt config --help-md` — edit source to update -->-```+```bashwt config — Manage configuration and shell integrationUsage: wt config [OPTIONS] <COMMAND>@@ -662,7 +662,7 @@ Docs: <https://llm.datasette.io/> | <https://github.com/sigoden/aichat><!-- ⚠️ AUTO-GENERATED from `wt step --help-md` — edit source to update -->-```+```bashwt step — Workflow building blocksUsage: wt step [OPTIONS] <COMMAND>diff --git a/docs/sass/custom.scss b/docs/sass/custom.scssindex de17fa2b4..5508044d0 100644--- a/docs/sass/custom.scss+++ b/docs/sass/custom.scss@@ -100,6 +100,13 @@ header {color: var(--wt-color-text);}+// Navigation+nav {+ display: flex;+ align-items: center;+ gap: 0.25rem;+}+// Navigation links.nav-item {font-size: 0.9rem;@@ -116,6 +123,87 @@ header {}}+// ============================================================================+// Search - Dropdown style (elasticlunr)+// ============================================================================++.search-container {+ position: relative;+ margin-right: 1rem;+}++#userinput {+ width: 180px;+ padding: 0.4rem 0.75rem;+ font-size: 0.9rem;+ font-family: var(--wt-font-sans);+ color: var(--wt-color-text);+ background: var(--wt-color-bg);+ border: 1px solid var(--wt-color-border-subtle);+ border-radius: 0.5rem;+ transition: width 150ms, border-color 150ms;++ &::placeholder {+ color: var(--wt-color-text-soft);+ }++ &:focus {+ width: 240px;+ border-color: var(--wt-color-accent);+ outline: none;+ }+}++#suggestions {+ display: none;+ position: absolute;+ top: calc(100% + 0.5rem);+ left: 0;+ width: 400px;+ max-height: 70vh;+ overflow-y: auto;+ background: var(--wt-color-bg-elevated);+ border: 1px solid var(--wt-color-border-subtle);+ border-radius: 0.5rem;+ box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);+ z-index: 1000;+}++.search-result {+ display: flex;+ flex-direction: column;+ padding: 0.75rem 1rem;+ border-bottom: 1px solid var(--wt-color-border-subtle);+ text-decoration: none;+ transition: background 150ms;++ &:last-child {+ border-bottom: none;+ }++ &:hover, &:focus {+ background: var(--wt-color-bg-soft);+ outline: none;+ }+}++.search-title {+ font-weight: 600;+ color: var(--wt-color-text);+ margin-bottom: 0.25rem;+}++.search-excerpt {+ font-size: 0.85rem;+ color: var(--wt-color-text-muted);+ line-height: 1.4;++ b {+ color: var(--wt-color-text);+ font-weight: 600;+ }+}+// ============================================================================// Main Content Area// ============================================================================@@ -544,6 +632,10 @@ ul > li::marker {height: auto;}+ .search-container {+ display: none; // Hide search on mobile for now+ }+main {padding: var(--wt-main-padding-top);flex-direction: column;diff --git a/docs/static/search.js b/docs/static/search.jsnew file mode 100644index 000000000..c83688269--- /dev/null+++ b/docs/static/search.js@@ -0,0 +1,190 @@+// Search functionality adapted from Adidoks theme+// Uses Zola's built-in elasticlunr search index++var suggestions = document.getElementById('suggestions');+var userinput = document.getElementById('userinput');++// Focus search on '/' key, blur on Escape+document.addEventListener('keydown', function(e) {+ if (e.key === '/' && document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA') {+ e.preventDefault();+ userinput.focus();+ }+ if (e.key === 'Escape') {+ userinput.blur();+ suggestions.style.display = 'none';+ }+});++// Hide suggestions when clicking outside+document.addEventListener('click', function(event) {+ if (!suggestions.contains(event.target) && event.target !== userinput) {+ suggestions.style.display = 'none';+ }+});++// Arrow key navigation through results+document.addEventListener('keydown', function(e) {+ const focusable = suggestions.querySelectorAll('a');+ if (suggestions.style.display === 'none' || focusable.length === 0) return;++ const index = Array.from(focusable).indexOf(document.activeElement);++ if (e.key === 'ArrowUp') {+ e.preventDefault();+ const nextIndex = index > 0 ? index - 1 : 0;+ focusable[nextIndex].focus();+ } else if (e.key === 'ArrowDown') {+ e.preventDefault();+ const nextIndex = index + 1 < focusable.length ? index + 1 : index;+ focusable[nextIndex].focus();+ }+});++// Main search functionality+(function() {+ var index = elasticlunr.Index.load(window.searchIndex);++ userinput.addEventListener('input', function() {+ var value = this.value.trim();++ if (!value) {+ suggestions.style.display = 'none';+ suggestions.innerHTML = '';+ return;+ }++ var results = index.search(value, {+ bool: "OR",+ fields: {+ title: { boost: 2 },+ body: { boost: 1 }+ }+ });++ var items = value.split(/\s+/);+ suggestions.innerHTML = '';++ if (results.length === 0) {+ suggestions.style.display = 'none';+ return;+ }++ suggestions.style.display = 'block';++ results.slice(0, 8).forEach(function(page) {+ if (page.doc.body !== '') {+ var entry = document.createElement('a');+ entry.href = page.ref;+ entry.className = 'search-result';+ entry.innerHTML = '<span class="search-title">' + escapeHtml(page.doc.title) + '</span>' ++ '<span class="search-excerpt">' + makeTeaser(page.doc.body, items) + '</span>';+ suggestions.appendChild(entry);+ }+ });+ });++ // Clear suggestions when clicking a result+ suggestions.addEventListener('click', function() {+ suggestions.innerHTML = '';+ suggestions.style.display = 'none';+ });++ function escapeHtml(text) {+ var div = document.createElement('div');+ div.textContent = text;+ return div.innerHTML;+ }++ // Generate search excerpt with highlighted terms (adapted from mdbook/Adidoks)+ function makeTeaser(body, terms) {+ var TERM_WEIGHT = 40;+ var NORMAL_WORD_WEIGHT = 2;+ var FIRST_WORD_WEIGHT = 8;+ var TEASER_MAX_WORDS = 30;++ var stemmedTerms = terms.map(function(w) {+ return elasticlunr.stemmer(w.toLowerCase());+ });+ var termFound = false;+ var index = 0;+ var weighted = [];++ var sentences = body.toLowerCase().split(". ");+ for (var i in sentences) {+ var words = sentences[i].split(/[\s\n]/);+ var value = FIRST_WORD_WEIGHT;+ for (var j in words) {+ var word = words[j];+ if (word.length > 0) {+ for (var k in stemmedTerms) {+ if (elasticlunr.stemmer(word).startsWith(stemmedTerms[k])) {+ value = TERM_WEIGHT;+ termFound = true;+ }+ }+ weighted.push([word, value, index]);+ value = NORMAL_WORD_WEIGHT;+ }+ index += word.length + 1;+ }+ index += 1;+ }++ if (weighted.length === 0) {+ return body.length > TEASER_MAX_WORDS * 10+ ? escapeHtml(body.substring(0, TEASER_MAX_WORDS * 10)) + '...'+ : escapeHtml(body);+ }++ var windowSize = Math.min(weighted.length, TEASER_MAX_WORDS);+ var windowWeights = [];+ var curSum = 0;++ for (var i = 0; i < windowSize; i++) {+ curSum += weighted[i][1];+ }+ windowWeights.push(curSum);++ for (var i = 0; i < weighted.length - windowSize; i++) {+ curSum -= weighted[i][1];+ curSum += weighted[i + windowSize][1];+ windowWeights.push(curSum);+ }++ var maxSumIndex = 0;+ if (termFound) {+ var maxFound = 0;+ for (var i = windowWeights.length - 1; i >= 0; i--) {+ if (windowWeights[i] > maxFound) {+ maxFound = windowWeights[i];+ maxSumIndex = i;+ }+ }+ }++ var teaser = [];+ var startIndex = weighted[maxSumIndex][2];++ for (var i = maxSumIndex; i < maxSumIndex + windowSize; i++) {+ var word = weighted[i];+ if (startIndex < word[2]) {+ teaser.push(escapeHtml(body.substring(startIndex, word[2])));+ startIndex = word[2];+ }++ if (word[1] === TERM_WEIGHT) {+ teaser.push('<b>');+ }++ startIndex = word[2] + word[0].length;+ teaser.push(escapeHtml(body.substring(word[2], startIndex)));++ if (word[1] === TERM_WEIGHT) {+ teaser.push('</b>');+ }+ }+ teaser.push('...');+ return teaser.join('');+ }+})();diff --git a/docs/templates/base.html b/docs/templates/base.htmlindex 3114d4e2e..0c80b8b6c 100644--- a/docs/templates/base.html+++ b/docs/templates/base.html@@ -31,7 +31,6 @@<meta name="twitter:description" content="{{ config.extra.site_description }}"><!-- <meta name="twitter:image" content="{{ config.base_url }}social-card.png"> -->-<link rel="stylesheet" href="{{ get_url(path='custom.css') }}"><!-- Google tag (gtag.js) --><script async src="https://www.googletagmanager.com/gtag/js?id=G-6YY8BDJ4QH"></script><script>@@ -62,6 +61,10 @@window.IntersectionObserver.prototype = RealIntersectionObserver.prototype;})();</script>+<link rel="stylesheet" href="/custom.css">+<script src="/elasticlunr.min.js" defer></script>+<script src="/search_index.en.js" defer></script>+<script src="/search.js" defer></script>{% endblock head %}{% block header %}@@ -73,6 +76,10 @@</div></a><nav>+ <div class="search-container">+ <input id="userinput" type="search" placeholder="Search..." aria-label="Search documentation">+ <div id="suggestions"></div>+ </div>{% for menu in config.extra.juice_extra_menu %}<a class="nav-item subtitle-text" href="{{ menu.link | safe }}">{{ menu.title }}</a>{% endfor %}