Skip to content

Commit 717ec5c

Browse files
committed
chore(js): Extract Hugo params imports to single-purpose modules, fix environment-specific Hugo configs, use Hugo environments instead of specifying the config file, configure source maps and ESM for development and testing
1 parent cd087af commit 717ec5c

28 files changed

+477
-526
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- /home/circleci/bin
4242
- run:
4343
name: Hugo Build
44-
command: npx hugo --config config/production/config.yml --logLevel info --minify --gc --destination workspace/public
44+
command: yarn hugo --environment production --logLevel info --gc --destination workspace/public
4545
- persist_to_workspace:
4646
root: workspace
4747
paths:

.github/instructions/contributing.instructions.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,11 +1730,30 @@ If you're adding UI functionality that requires JavaScript, follow these steps:
17301730
17311731
### Debugging JavaScript
17321732
1733-
To debug JavaScript code used in the InfluxData documentation UI:
1733+
To debug JavaScript code used in the InfluxData documentation UI, choose one of the following methods:
1734+
1735+
- Use source maps and the Chrome DevTools debugger.
1736+
- Use debug helpers that provide breakpoints and console logging as a workaround or alternative for using source maps and the Chrome DevTools debugger.
1737+
1738+
#### Using source maps and Chrome DevTools debugger
1739+
1740+
1. In VS Code, select Run > Start Debugging.
1741+
2. Select the "Debug Docs (source maps)" configuration.
1742+
3. Click the play button to start the debugger.
1743+
5. Set breakpoints in the JavaScript source files--files in the
1744+
`assets/js/ns-hugo-imp:` namespace-- in the
1745+
VS Code editor or in the Chrome Developer Tools Sources panel:
1746+
1747+
- In the VS Code Debugger panel > "Loaded Scripts" section, find the
1748+
`assets/js/ns-hugo-imp:` namespace.
1749+
- In the Chrome Developer Tools Sources panel, expand
1750+
`js/ns-hugo-imp:/<YOUR_WORKSPACE_ROOT>/assets/js/`.
1751+
1752+
#### Using debug helpers
17341753
17351754
1. In your JavaScript module, import debug helpers from `assets/js/utils/debug-helpers.js`.
1736-
These helpers provide breakpoints and console logging as a workaround for
1737-
Hugo's lack of source map support in the asset pipeline.
1755+
These helpers provide breakpoints and console logging as a workaround or alternative for
1756+
using source maps and the Chrome DevTools debugger.
17381757
2. Insert debug statements by calling the helper functions in your code--for example:
17391758
17401759
```js
@@ -1757,7 +1776,7 @@ To debug JavaScript code used in the InfluxData documentation UI:
17571776
yarn hugo server
17581777
```
17591778
1760-
4. In VS Code, go to Run > Start Debugging, and select the "Debug Docs (console-based)" configuration.
1779+
4. In VS Code, go to Run > Start Debugging, and select the "Debug JS (debug-helpers)" configuration.
17611780
17621781
Your system uses the configuration in `launch.json` to launch the site in Chrome
17631782
and attach the debugger to the Developer Tools console.

.vscode/launch.json

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Debug Docs (console-based)",
5+
"name": "Debug JS (debug-helpers)",
66
"type": "chrome",
77
"request": "launch",
88
"url": "http://localhost:1313",
@@ -13,6 +13,35 @@
1313
"sourceMaps": false,
1414
"trace": true,
1515
"smartStep": false
16-
}
16+
},
17+
{
18+
"name": "Debug JS (source maps)",
19+
"type": "chrome",
20+
"request": "launch",
21+
"url": "http://localhost:1313",
22+
"webRoot": "${workspaceFolder}",
23+
"sourceMaps": true,
24+
"sourceMapPathOverrides": {
25+
"*": "${webRoot}/assets/js/*",
26+
"main.js": "${webRoot}/assets/js/main.js",
27+
"page-context.js": "${webRoot}/assets/js/page-context.js",
28+
"ask-ai-trigger.js": "${webRoot}/assets/js/ask-ai-trigger.js",
29+
"ask-ai.js": "${webRoot}/assets/js/ask-ai.js",
30+
"utils/*": "${webRoot}/assets/js/utils/*",
31+
"services/*": "${webRoot}/assets/js/services/*"
32+
},
33+
"skipFiles": [
34+
"<node_internals>/**",
35+
"node_modules/**",
36+
"chrome-extension://**"
37+
],
38+
"trace": true,
39+
"smartStep": true,
40+
"disableNetworkCache": true,
41+
"userDataDir": "${workspaceFolder}/.vscode/chrome-user-data",
42+
"runtimeArgs": [
43+
"--disable-features=VizDisplayCompositor"
44+
]
45+
},
1746
]
1847
}

CONTRIBUTING.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,11 +1718,30 @@ If you're adding UI functionality that requires JavaScript, follow these steps:
17181718
17191719
### Debugging JavaScript
17201720
1721-
To debug JavaScript code used in the InfluxData documentation UI:
1721+
To debug JavaScript code used in the InfluxData documentation UI, choose one of the following methods:
1722+
1723+
- Use source maps and the Chrome DevTools debugger.
1724+
- Use debug helpers that provide breakpoints and console logging as a workaround or alternative for using source maps and the Chrome DevTools debugger.
1725+
1726+
#### Using source maps and Chrome DevTools debugger
1727+
1728+
1. In VS Code, select Run > Start Debugging.
1729+
2. Select the "Debug Docs (source maps)" configuration.
1730+
3. Click the play button to start the debugger.
1731+
5. Set breakpoints in the JavaScript source files--files in the
1732+
`assets/js/ns-hugo-imp:` namespace-- in the
1733+
VS Code editor or in the Chrome Developer Tools Sources panel:
1734+
1735+
- In the VS Code Debugger panel > "Loaded Scripts" section, find the
1736+
`assets/js/ns-hugo-imp:` namespace.
1737+
- In the Chrome Developer Tools Sources panel, expand
1738+
`js/ns-hugo-imp:/<YOUR_WORKSPACE_ROOT>/assets/js/`.
1739+
1740+
#### Using debug helpers
17221741
17231742
1. In your JavaScript module, import debug helpers from `assets/js/utils/debug-helpers.js`.
1724-
These helpers provide breakpoints and console logging as a workaround for
1725-
Hugo's lack of source map support in the asset pipeline.
1743+
These helpers provide breakpoints and console logging as a workaround or alternative for
1744+
using source maps and the Chrome DevTools debugger.
17261745
2. Insert debug statements by calling the helper functions in your code--for example:
17271746
17281747
```js
@@ -1745,7 +1764,7 @@ To debug JavaScript code used in the InfluxData documentation UI:
17451764
yarn hugo server
17461765
```
17471766
1748-
4. In VS Code, go to Run > Start Debugging, and select the "Debug Docs (console-based)" configuration.
1767+
4. In VS Code, go to Run > Start Debugging, and select the "Debug JS (debug-helpers)" configuration.
17491768
17501769
Your system uses the configuration in `launch.json` to launch the site in Chrome
17511770
and attach the debugger to the Developer Tools console.

assets/js/api-libs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
///////////////// Preferred Client Library programming language ///////////////
33
////////////////////////////////////////////////////////////////////////////////
44
import { activateTabs, updateBtnURLs } from './tabbed-content.js';
5-
import { getPreference, setPreference } from './local-storage.js';
5+
import { getPreference, setPreference } from './services/local-storage.js';
66

77
function getVisitedApiLib() {
88
const path = window.location.pathname.match(

assets/js/ask-ai.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,31 @@ function setUser(userid, email) {
88
window[NAMESPACE] = {
99
user: {
1010
uniqueClientId: userid,
11-
email: email,
12-
}
13-
}
11+
email: email,
12+
},
13+
};
1414
}
1515

1616
// Initialize the chat widget
17-
function initializeChat({onChatLoad, chatAttributes}) {
18-
/* See https://docs.kapa.ai/integrations/website-widget/configuration for
17+
function initializeChat({ onChatLoad, chatAttributes }) {
18+
/* See https://docs.kapa.ai/integrations/website-widget/configuration for
1919
* available configuration options.
2020
* All values are strings.
2121
*/
22-
// If you make changes to data attributes here, you also need to port the changes to the api-docs/template.hbs API reference template.
22+
// If you make changes to data attributes here, you also need to
23+
// port the changes to the api-docs/template.hbs API reference template.
2324
const requiredAttributes = {
2425
websiteId: 'a02bca75-1dd3-411e-95c0-79ee1139be4d',
2526
projectName: 'InfluxDB',
2627
projectColor: '#020a47',
2728
projectLogo: '/img/influx-logo-cubo-white.png',
28-
}
29+
};
2930

3031
const optionalAttributes = {
31-
32-
modalDisclaimer: 'This AI can access [documentation for InfluxDB, clients, and related tools](https://docs.influxdata.com). Information you submit is used in accordance with our [Privacy Policy](https://www.influxdata.com/legal/privacy-policy/).',
33-
modalExampleQuestions: 'Use Python to write data to InfluxDB 3,How do I query using SQL?,How do I use MQTT with Telegraf?',
32+
modalDisclaimer:
33+
'This AI can access [documentation for InfluxDB, clients, and related tools](https://docs.influxdata.com). Information you submit is used in accordance with our [Privacy Policy](https://www.influxdata.com/legal/privacy-policy/).',
34+
modalExampleQuestions:
35+
'Use Python to write data to InfluxDB 3,How do I query using SQL?,How do I use MQTT with Telegraf?',
3436
buttonHide: 'true',
3537
exampleQuestionButtonWidth: 'auto',
3638
modalOpenOnCommandK: 'true',
@@ -52,28 +54,32 @@ function initializeChat({onChatLoad, chatAttributes}) {
5254
modalHeaderBorderBottom: 'none',
5355
modalTitleColor: '#fff',
5456
modalTitleFontSize: '1.25rem',
55-
}
57+
};
5658

5759
const scriptUrl = 'https://widget.kapa.ai/kapa-widget.bundle.js';
5860
const script = document.createElement('script');
5961
script.async = true;
6062
script.src = scriptUrl;
61-
script.onload = function() {
63+
script.onload = function () {
6264
onChatLoad();
6365
window.influxdatadocs.AskAI = AskAI;
6466
};
65-
script.onerror = function() {
67+
script.onerror = function () {
6668
console.error('Error loading AI chat widget script');
6769
};
6870

69-
const dataset = {...requiredAttributes, ...optionalAttributes, ...chatAttributes};
70-
Object.keys(dataset).forEach(key => {
71-
// Assign dataset attributes from the object
71+
const dataset = {
72+
...requiredAttributes,
73+
...optionalAttributes,
74+
...chatAttributes,
75+
};
76+
Object.keys(dataset).forEach((key) => {
77+
// Assign dataset attributes from the object
7278
script.dataset[key] = dataset[key];
7379
});
7480

7581
// Check for an existing script element to remove
76-
const oldScript= document.querySelector(`script[src="${scriptUrl}"]`);
82+
const oldScript = document.querySelector(`script[src="${scriptUrl}"]`);
7783
if (oldScript) {
7884
oldScript.remove();
7985
}
@@ -82,22 +88,21 @@ function initializeChat({onChatLoad, chatAttributes}) {
8288

8389
function getProductExampleQuestions() {
8490
const questions = productData?.product?.ai_sample_questions;
85-
return questions?.join(',') || '';
91+
return questions?.join(',') || '';
8692
}
8793

88-
/**
94+
/**
8995
* chatParams: specify custom (for example, page-specific) attribute values for the chat, pass the dataset key-values (collected in ...chatParams). See https://docs.kapa.ai/integrations/website-widget/configuration for available configuration options.
9096
* onChatLoad: function to call when the chat widget has loaded
9197
* userid: optional, a unique user ID for the user (not currently used for public docs)
92-
*/
98+
*/
9399
export default function AskAI({ userid, email, onChatLoad, ...chatParams }) {
94-
95100
const modalExampleQuestions = getProductExampleQuestions();
96101
const chatAttributes = {
97102
...(modalExampleQuestions && { modalExampleQuestions }),
98103
...chatParams,
99-
}
100-
initializeChat({onChatLoad, chatAttributes});
104+
};
105+
initializeChat({ onChatLoad, chatAttributes });
101106

102107
if (userid) {
103108
setUser(userid, email);

assets/js/code-controls.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import $ from 'jquery';
2+
import { debugBreak } from './utils/debug-helpers.js';
23

34
function initialize() {
45
var codeBlockSelector = '.article--content pre';
5-
var codeBlocks = $(codeBlockSelector);
6+
var $codeBlocks = $(codeBlockSelector);
67

78
var appendHTML = `
89
<div class="code-controls">
@@ -15,7 +16,7 @@ function initialize() {
1516
`;
1617

1718
// Wrap all codeblocks with a new 'codeblock' div
18-
$(codeBlocks).each(function () {
19+
$codeBlocks.each(function () {
1920
$(this).wrap("<div class='codeblock'></div>");
2021
});
2122

@@ -68,7 +69,9 @@ function initialize() {
6869
// Trigger copy failure state lifecycle
6970

7071
$('.copy-code').click(function () {
71-
let text = $(this).closest('.code-controls').prevAll('pre:has(code)')[0].innerText;
72+
let text = $(this)
73+
.closest('.code-controls')
74+
.prevAll('pre:has(code)')[0].innerText;
7275

7376
const copyContent = async () => {
7477
try {
@@ -90,7 +93,10 @@ Disable scrolling on the body.
9093
Disable user selection on everything but the fullscreen codeblock.
9194
*/
9295
$('.fullscreen-toggle').click(function () {
93-
var code = $(this).closest('.code-controls').prevAll('pre:has(code)').clone();
96+
var code = $(this)
97+
.closest('.code-controls')
98+
.prevAll('pre:has(code)')
99+
.clone();
94100

95101
$('#fullscreen-code-placeholder').replaceWith(code[0]);
96102
$('body').css('overflow', 'hidden');

0 commit comments

Comments
 (0)