Prettifier fixes.

This commit is contained in:
Lauri Ojansivu 2020-05-25 18:04:32 +03:00
parent d52affe658
commit 05349a5deb
2 changed files with 38 additions and 31 deletions

View file

@ -467,7 +467,7 @@ Template.exportBoard.events({
'click .html-export-board': async event => { 'click .html-export-board': async event => {
event.preventDefault(); event.preventDefault();
await ExportHtml(Popup)(); await ExportHtml(Popup)();
} },
}); });
Template.labelsWidget.events({ Template.labelsWidget.events({

View file

@ -1,6 +1,6 @@
const JSZip = require('jszip'); const JSZip = require('jszip');
window.ExportHtml = (Popup) => { window.ExportHtml = Popup => {
const saveAs = function(blob, filename) { const saveAs = function(blob, filename) {
let dl = document.createElement('a'); let dl = document.createElement('a');
dl.href = window.URL.createObjectURL(blob); dl.href = window.URL.createObjectURL(blob);
@ -12,21 +12,22 @@ window.ExportHtml = (Popup) => {
dl.click(); dl.click();
}; };
const asyncForEach = async function (array, callback) { const asyncForEach = async function(array, callback) {
for (let index = 0; index < array.length; index++) { for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array); await callback(array[index], index, array);
} }
}; };
const getPageHtmlString = () => { const getPageHtmlString = () => {
return `<!doctype html>${ return `<!doctype html>${window.document.querySelector('html').outerHTML}`;
window.document.querySelector('html').outerHTML
}`;
}; };
const removeAnchors = htmlString => { const removeAnchors = htmlString => {
const replaceOpenAnchor = htmlString.replace(new RegExp('<a ', 'gim'), '<span '); const replaceOpenAnchor = htmlString.replace(
return replaceOpenAnchor.replace(new RegExp('<\/a', 'gim'), '</span'); new RegExp('<a ', 'gim'),
'<span ',
);
return replaceOpenAnchor.replace(new RegExp('</a', 'gim'), '</span');
}; };
const ensureSidebarRemoved = () => { const ensureSidebarRemoved = () => {
@ -83,9 +84,8 @@ window.ExportHtml = (Popup) => {
elem.src = elem.src; elem.src = elem.src;
}); });
Array.from(document.querySelectorAll('.is-editable')).forEach(elem => { Array.from(document.querySelectorAll('.is-editable')).forEach(elem => {
elem.classList.remove('is-editable') elem.classList.remove('is-editable');
}) });
}; };
const getBoardSlug = () => { const getBoardSlug = () => {
@ -104,7 +104,8 @@ window.ExportHtml = (Popup) => {
const responseBody = await response.text(); const responseBody = await response.text();
const finalResponse = responseBody.replace( const finalResponse = responseBody.replace(
new RegExp('packages\/[^\/]+\/upstream\/', 'gim'), '../' new RegExp('packages/[^/]+/upstream/', 'gim'),
'../',
); );
const filename = elem.href const filename = elem.href
@ -138,30 +139,33 @@ window.ExportHtml = (Popup) => {
}; };
const removeCssUrlSurround = url => { const removeCssUrlSurround = url => {
const working = url || ""; const working = url || '';
return working return working
.split("url(") .split('url(')
.join("") .join('')
.split("\")") .split('")')
.join("") .join('')
.split("\"") .split('"')
.join("") .join('')
.split("')") .split("')")
.join("") .join('')
.split("'") .split("'")
.join("") .join('')
.split(")") .split(')')
.join(""); .join('');
}; };
const getCardCovers = () => { const getCardCovers = () => {
return Array.from(document.querySelectorAll('.minicard-cover')) return Array.from(document.querySelectorAll('.minicard-cover')).filter(
.filter(elem => elem.style['background-image']) elem => elem.style['background-image'],
} );
};
const downloadCardCovers = async (elements, zip, boardSlug) => { const downloadCardCovers = async (elements, zip, boardSlug) => {
await asyncForEach(elements, async elem => { await asyncForEach(elements, async elem => {
const response = await fetch(removeCssUrlSurround(elem.style['background-image'])); const response = await fetch(
removeCssUrlSurround(elem.style['background-image']),
);
const responseBody = await response.blob(); const responseBody = await response.blob();
const filename = removeCssUrlSurround(elem.style['background-image']) const filename = removeCssUrlSurround(elem.style['background-image'])
.split('/') .split('/')
@ -179,9 +183,12 @@ window.ExportHtml = (Popup) => {
const addBoardHTMLToZip = (boardSlug, zip) => { const addBoardHTMLToZip = (boardSlug, zip) => {
ensureSidebarRemoved(); ensureSidebarRemoved();
const htmlOutputPath = `${boardSlug}/index.html`; const htmlOutputPath = `${boardSlug}/index.html`;
zip.file(htmlOutputPath, new Blob([ zip.file(
removeAnchors(getPageHtmlString()) htmlOutputPath,
], { type: 'application/html' })); new Blob([removeAnchors(getPageHtmlString())], {
type: 'application/html',
}),
);
}; };
return async () => { return async () => {
@ -202,5 +209,5 @@ window.ExportHtml = (Popup) => {
const content = await zip.generateAsync({ type: 'blob' }); const content = await zip.generateAsync({ type: 'blob' });
saveAs(content, `${boardSlug}.zip`); saveAs(content, `${boardSlug}.zip`);
window.location.reload(); window.location.reload();
} };
}; };