Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions app/modules/niklan/assets/js/hljs.init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
((Drupal, once, drupalSettings) => {

let worker;
let requestId = 0;
const pendingRequests = new Map();
Expand All @@ -9,9 +8,9 @@
detail: {
element,
originalCode: element.textContent,
highlightedHTML: html
highlightedHTML: html,
},
bubbles: true
bubbles: true,
});

const handleIntersection = (entries) => {
Expand All @@ -29,7 +28,8 @@
requestId: currentRequestId,
code: codeElement.textContent,
language: preElement.dataset.language,
esModulesBasePath: drupalSettings.highlightJs.esModulesBasePath
esModulesBasePath: drupalSettings.highlightJs.esModulesBasePath,
cacheBustingQueryString: drupalSettings.cacheQueryBustingString,
});
});
};
Expand Down Expand Up @@ -57,8 +57,11 @@
.from(once('code-highlight', 'pre > code'))
.forEach(code => observer.observe(code));

worker = new Worker(drupalSettings.highlightJs.workerPath, { type: 'module' });
worker.addEventListener('message', handleWorkerMessage);
worker = new Worker(
`${drupalSettings.highlightJs.workerPath}?${drupalSettings.cacheQueryBustingString}`,
{ type: "module" },
);
worker.addEventListener("message", handleWorkerMessage);
};


Expand Down
6 changes: 3 additions & 3 deletions app/modules/niklan/assets/js/hljs.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ const supportedLanguages = {

onmessage = async (event) => {
try {
const { requestId, code, language, esModulesBasePath } = event.data;
const { requestId, code, language, esModulesBasePath, cacheBustingQueryString } = event.data;

const hljsModule = await import(`${esModulesBasePath}/highlight.min.js`);
const hljsModule = await import(`${esModulesBasePath}/highlight.min.js?${cacheBustingQueryString}`);
const hljs = hljsModule.default;

if (language && supportedLanguages[language]) {
const langModule = await import(`${esModulesBasePath}/${supportedLanguages[language]}`);
const langModule = await import(`${esModulesBasePath}/${supportedLanguages[language]}?${cacheBustingQueryString}`);
hljs.registerLanguage(language, langModule.default);
}

Expand Down
21 changes: 21 additions & 0 deletions app/modules/niklan/src/Hook/Asset/CacheBustingQuerySetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Drupal\niklan\Hook\Asset;

use Drupal\Core\Asset\AssetQueryStringInterface;
use Drupal\Core\Hook\Attribute\Hook;

#[Hook('js_settings_build')]
final readonly class CacheBustingQuerySetting {

public function __construct(
private AssetQueryStringInterface $queryString,
) {}

public function __invoke(array &$settings): void {
$settings['cacheQueryBustingString'] = $this->queryString->get();
}

}