Files
FreshRSS/docs/assets/js/docs.js
T
InverleandAlexandre Alapetite 0285dc8970 Check SVG optimization in the tests CI workflow with SVGO (#9361)
* Check SVG optimization in the tests CI workflow with SVGO

Previously it was only recommended by the documentation that SVG images should be optimized using [SVGOMG](https://github.com/jakearchibald/svgomg), the web GUI version of https://github.com/svg/svgo (CLI)


Now all SVG images are optimized, and optimization is mandatory enforced by the tests CI workflow.
\+ SVGs are sanitized of potentially malicious JS code using the https://svgo.dev/docs/plugins/removeScripts/ plugin

* Output prettified SVGs instead and remove unchanged files from stdout

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>

* Use `removeScripts` SVGO plugin to reduce risk of malicious SVGs

* Move the CLI options to the JS config instead

* Disable `removeComments` plugin included in the default preset

* editorconfig, and easier config

---------

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
2026-09-29 16:18:01 +02:00

60 lines
1.6 KiB
JavaScript

/* globals i18n */
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.head.insertAdjacentHTML('beforeend', `
<meta name="darkreader-lock">
`);
}
let asideNav;
window.addEventListener('beforeunload', () => {
sessionStorage.setItem('sidebar_scrollTop', asideNav.scrollTop);
});
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
location.hash = 'close';
}
});
document.addEventListener('DOMContentLoaded', () => {
asideNav = document.querySelector('aside > nav.docs');
const sidebar_scrollTop = sessionStorage.getItem('sidebar_scrollTop');
if (sidebar_scrollTop) {
asideNav.scrollTo(0, sidebar_scrollTop);
sessionStorage.removeItem('sidebar_scrollTop');
}
const copyIconSvg = document.querySelector('template#copy-svg-icon').innerHTML;
for (const el of document.querySelectorAll('div.highlight')) {
el.insertAdjacentHTML('afterbegin', `
<button class="copy" title="${i18n.copy_to_clipboard}">
${copyIconSvg}
</button>
`);
const copyBtn = el.querySelector('button.copy');
copyBtn.addEventListener('click', () => {
const snippet = el.querySelector('code').innerText;
if (navigator.clipboard) {
navigator.clipboard.writeText(snippet);
} else {
// Fallback if no HTTPS
const input = document.createElement('textarea');
input.innerHTML = snippet;
document.body.append(input);
input.select();
document.execCommand('copy');
input.remove();
}
});
}
for (const el of document.querySelectorAll('img')) {
if (el.parentNode.tagName !== 'A') {
el.outerHTML = `<a href="${el.getAttribute('src')}">${el.outerHTML}</a>`;
}
}
});