Skip to content

Commit ffef19f

Browse files
authored
Merge branch 'master' into jmercer/complete-plugin-sync-fix
2 parents 6f59a22 + f084fe3 commit ffef19f

File tree

44 files changed

+2717
-1542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2717
-1542
lines changed

.github/instructions/layouts.instructions.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ applyTo: "layouts/**/*.html"
1111

1212
When creating or modifying Hugo layouts and shortcodes:
1313

14-
1. Use Hugo template syntax and functions
15-
2. Follow existing patterns in `/layouts/shortcodes/`
16-
3. Test in [content/example.md](../../content/example.md)
17-
4. Document new shortcodes in [DOCS-SHORTCODES.md](../../DOCS-SHORTCODES.md)
14+
1. Use test-driven development using `/cypress/`
15+
2. Use Hugo template syntax and functions
16+
3. Follow existing patterns in `/layouts/shortcodes/`
17+
4. Test in [content/example.md](../../content/example.md)
18+
5. Document new shortcodes in [DOCS-SHORTCODES.md](../../DOCS-SHORTCODES.md)
1819

1920
## Shortcode Pattern
2021

@@ -30,9 +31,32 @@ When creating or modifying Hugo layouts and shortcodes:
3031

3132
## Testing
3233

33-
Add usage examples to `content/example.md` to verify:
34+
**IMPORTANT:** Use test-driven development with Cypress.
35+
36+
Add shortcode usage examples to `content/example.md` to verify:
37+
3438
- Rendering in browser
3539
- Hugo build succeeds
3640
- No console errors
41+
- JavaScript functionality works as expected (check browser console for errors)
42+
- Interactive elements behave correctly (click links, buttons, etc.)
43+
44+
### TDD Workflow
45+
46+
1. Add Cypress tests (high-level to start).
47+
2. Run tests and make sure they fail.
48+
3. Implement code changes
49+
4. Run tests and make sure they pass.
50+
5. Add and refine tests.
51+
6. Repeat.
52+
53+
### Manual Testing Workflow
54+
55+
1. Make changes to shortcode/layout files
56+
2. Wait for Hugo to rebuild (check terminal output)
57+
3. Get the server URL from the log
58+
4. Open browser DevTools console (F12)
59+
5. Test the functionality and check for JavaScript errors
60+
6. Verify the feature works as intended before marking complete
3761

3862
See [DOCS-SHORTCODES.md](../../DOCS-SHORTCODES.md) for complete shortcode documentation.

.husky/_/pre-commit

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ call_lefthook()
3333
then
3434
"$dir/node_modules/lefthook/bin/index.js" "$@"
3535

36+
elif go tool lefthook -h >/dev/null 2>&1
37+
then
38+
go tool lefthook "$@"
3639
elif bundle exec lefthook -h >/dev/null 2>&1
3740
then
3841
bundle exec lefthook "$@"
@@ -42,12 +45,21 @@ call_lefthook()
4245
elif pnpm lefthook -h >/dev/null 2>&1
4346
then
4447
pnpm lefthook "$@"
45-
elif swift package plugin lefthook >/dev/null 2>&1
48+
elif swift package lefthook >/dev/null 2>&1
4649
then
47-
swift package --disable-sandbox plugin lefthook "$@"
50+
swift package --build-path .build/lefthook --disable-sandbox lefthook "$@"
4851
elif command -v mint >/dev/null 2>&1
4952
then
5053
mint run csjones/lefthook-plugin "$@"
54+
elif uv run lefthook -h >/dev/null 2>&1
55+
then
56+
uv run lefthook "$@"
57+
elif mise exec -- lefthook -h >/dev/null 2>&1
58+
then
59+
mise exec -- lefthook "$@"
60+
elif devbox run lefthook -h >/dev/null 2>&1
61+
then
62+
devbox run lefthook "$@"
5163
else
5264
echo "Can't find lefthook in PATH"
5365
fi

.husky/_/pre-push

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ call_lefthook()
3333
then
3434
"$dir/node_modules/lefthook/bin/index.js" "$@"
3535

36+
elif go tool lefthook -h >/dev/null 2>&1
37+
then
38+
go tool lefthook "$@"
3639
elif bundle exec lefthook -h >/dev/null 2>&1
3740
then
3841
bundle exec lefthook "$@"
@@ -42,12 +45,21 @@ call_lefthook()
4245
elif pnpm lefthook -h >/dev/null 2>&1
4346
then
4447
pnpm lefthook "$@"
45-
elif swift package plugin lefthook >/dev/null 2>&1
48+
elif swift package lefthook >/dev/null 2>&1
4649
then
47-
swift package --disable-sandbox plugin lefthook "$@"
50+
swift package --build-path .build/lefthook --disable-sandbox lefthook "$@"
4851
elif command -v mint >/dev/null 2>&1
4952
then
5053
mint run csjones/lefthook-plugin "$@"
54+
elif uv run lefthook -h >/dev/null 2>&1
55+
then
56+
uv run lefthook "$@"
57+
elif mise exec -- lefthook -h >/dev/null 2>&1
58+
then
59+
mise exec -- lefthook "$@"
60+
elif devbox run lefthook -h >/dev/null 2>&1
61+
then
62+
devbox run lefthook "$@"
5163
else
5264
echo "Can't find lefthook in PATH"
5365
fi

.husky/_/prepare-commit-msg

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ call_lefthook()
3333
then
3434
"$dir/node_modules/lefthook/bin/index.js" "$@"
3535

36+
elif go tool lefthook -h >/dev/null 2>&1
37+
then
38+
go tool lefthook "$@"
3639
elif bundle exec lefthook -h >/dev/null 2>&1
3740
then
3841
bundle exec lefthook "$@"
@@ -42,12 +45,21 @@ call_lefthook()
4245
elif pnpm lefthook -h >/dev/null 2>&1
4346
then
4447
pnpm lefthook "$@"
45-
elif swift package plugin lefthook >/dev/null 2>&1
48+
elif swift package lefthook >/dev/null 2>&1
4649
then
47-
swift package --disable-sandbox plugin lefthook "$@"
50+
swift package --build-path .build/lefthook --disable-sandbox lefthook "$@"
4851
elif command -v mint >/dev/null 2>&1
4952
then
5053
mint run csjones/lefthook-plugin "$@"
54+
elif uv run lefthook -h >/dev/null 2>&1
55+
then
56+
uv run lefthook "$@"
57+
elif mise exec -- lefthook -h >/dev/null 2>&1
58+
then
59+
mise exec -- lefthook "$@"
60+
elif devbox run lefthook -h >/dev/null 2>&1
61+
then
62+
devbox run lefthook "$@"
5163
else
5264
echo "Can't find lefthook in PATH"
5365
fi

assets/js/ask-ai-trigger.js

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,117 @@
11
import AskAI from './ask-ai.js';
22

3+
/**
4+
* Global state for Ask AI initialization
5+
*/
6+
const state = {
7+
kapaInitialized: false,
8+
linksListenerInitialized: false,
9+
};
10+
11+
/**
12+
* Initialize the Kapa widget
13+
*/
14+
function initializeKapa() {
15+
if (!state.kapaInitialized) {
16+
AskAI();
17+
state.kapaInitialized = true;
18+
19+
// Store in global namespace for debugging
20+
window.influxdatadocs = window.influxdatadocs || {};
21+
window.influxdatadocs.kapaInitialized = true;
22+
}
23+
}
24+
25+
/**
26+
* Show the trigger button by removing inline display: none style
27+
* @param {HTMLElement} element - The trigger button element
28+
*/
329
function showTrigger(element) {
4-
// Remove the inline display: none style
5-
element.removeAttribute('style');
30+
if (element) {
31+
element.removeAttribute('style');
32+
}
633
}
734

35+
/**
36+
* Initialize Ask AI trigger button component
37+
* @param {Object} options - Component options
38+
* @param {HTMLElement} options.component - The trigger button element
39+
*/
840
export default function AskAITrigger({ component }) {
941
const kapaContainer = document.querySelector('#kapa-widget-container');
42+
1043
if (!component && !kapaContainer) {
1144
return;
1245
}
46+
1347
if (!kapaContainer) {
1448
// Initialize the chat widget
1549
AskAI({ onChatLoad: () => showTrigger(component) });
50+
state.kapaInitialized = true;
51+
window.influxdatadocs = window.influxdatadocs || {};
52+
window.influxdatadocs.kapaInitialized = true;
1653
} else {
1754
showTrigger(component);
1855
}
19-
}
56+
}
57+
58+
/**
59+
* Handle ask-ai-link clicks globally
60+
* This ensures ask-ai-link shortcodes work even without the trigger button
61+
*/
62+
function handleAskAILinks() {
63+
if (state.linksListenerInitialized) {
64+
return;
65+
}
66+
67+
state.linksListenerInitialized = true;
68+
69+
// Store in global namespace for debugging
70+
window.influxdatadocs = window.influxdatadocs || {};
71+
window.influxdatadocs.askAILinksInitialized = true;
72+
73+
// Listen for clicks on ask-ai-link elements
74+
document.addEventListener(
75+
'click',
76+
(event) => {
77+
const link = event.target.closest('.ask-ai-open');
78+
if (!link) return;
79+
80+
const query = link.getAttribute('data-query');
81+
82+
// Initialize Kapa if not already done
83+
if (!state.kapaInitialized) {
84+
initializeKapa();
85+
86+
// Wait for Kapa to be ready, then open with query
87+
if (query && window.Kapa?.open) {
88+
// Give Kapa a moment to initialize
89+
setTimeout(() => {
90+
if (window.Kapa?.open) {
91+
window.Kapa.open({
92+
mode: 'ai',
93+
query: query,
94+
});
95+
}
96+
}, 100);
97+
}
98+
} else {
99+
// Kapa is already initialized - open with query if provided
100+
if (query && window.Kapa?.open) {
101+
window.Kapa.open({
102+
mode: 'ai',
103+
query: query,
104+
});
105+
}
106+
}
107+
},
108+
{ passive: true }
109+
);
110+
}
111+
112+
// Initialize ask-ai-link handling when DOM is ready
113+
if (document.readyState === 'loading') {
114+
document.addEventListener('DOMContentLoaded', handleAskAILinks);
115+
} else {
116+
handleAskAILinks();
117+
}

assets/js/ask-ai.js

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)