1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-03 08:35:29 +02:00
joplin/packages/renderer/assetsToHeaders.js
2023-06-01 12:02:36 +01:00

29 lines
834 B
JavaScript

// Utility function to convert the plugin assets to a list of LINK or SCRIPT tags
// that can be included in the HEAD tag.
function assetsToHeaders(pluginAssets, options = null) {
options = { asHtml: false, ...options };
const headers = {};
for (let i = 0; i < pluginAssets.length; i++) {
const asset = pluginAssets[i];
if (asset.mime === 'text/css') {
headers[asset.name] = `<link rel="stylesheet" href="pluginAssets/${asset.name}">`;
} else if (asset.mime === 'application/javascript') {
// NOT TESTED!!
headers[asset.name] = `<script type="application/javascript" src="pluginAssets/${asset.name}"></script>`;
}
}
if (options.asHtml) {
const output = [];
for (const name in headers) {
output.push(headers[name]);
}
return output.join('');
}
return headers;
}
module.exports = assetsToHeaders;