Release v2.19.1: repair managed font references
This commit is contained in:
1 parent
90253e98a4
commit
9ca372429b
11 files changed
+212
-23
No files matched your search
@@ -1,4 +1,5 @@
|
||||
const crypto = require('crypto');
|
||||
const { BASE_FONT_FAMILIES } = require('./font-families');
|
||||
|
||||
const REFERENCE_TYPES_BY_FIELD = {
|
||||
source_id: 'api-request',
|
||||
@@ -34,7 +35,10 @@ function addReference(references, seen, ownerKey, referenceType, value) {
|
||||
if (!Number.isFinite(numericValue)) return;
|
||||
referenceValue = String(numericValue);
|
||||
}
|
||||
if (referenceType === 'font-family') referenceValue = normalizeFontFamily(referenceValue);
|
||||
if (referenceType === 'font-family') {
|
||||
referenceValue = normalizeFontFamily(referenceValue);
|
||||
if (BASE_FONT_FAMILIES.has(referenceValue)) return;
|
||||
}
|
||||
if (!referenceValue) return;
|
||||
const key = String(ownerKey || '') + '\u0000' + referenceType + '\u0000' + referenceValue;
|
||||
if (seen.has(key)) return;
|
||||
@@ -75,10 +79,13 @@ function collectValueReferences(value, ownerKey, references, seen) {
|
||||
if (normalized) addReference(references, seen, ownerKey, 'media', normalized);
|
||||
});
|
||||
|
||||
const fontFamilies = /font-family\s*:\s*(?:"([^"]+)"|'([^']+)'|([^;}"']+))/gi;
|
||||
const fontValue = value.replace(/&(?:quot|apos|#0*34|#0*39|#x0*22|#x0*27);/gi, function (entity) {
|
||||
return /^&(?:quot|#0*34|#x0*22);$/i.test(entity) ? '"' : "'";
|
||||
});
|
||||
const fontFamilies = /font-family\s*:\s*((?:"[^"]*"|'[^']*'|[^;}"'])+)/gi;
|
||||
let match;
|
||||
while ((match = fontFamilies.exec(value))) {
|
||||
getFontFamilyCandidates(match[1] || match[2] || match[3]).forEach(function (family) {
|
||||
while ((match = fontFamilies.exec(fontValue))) {
|
||||
getFontFamilyCandidates(match[1]).forEach(function (family) {
|
||||
addReference(references, seen, ownerKey, 'font-family', family);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
const DEFAULT_FONT_FAMILY_FORMATS = [
|
||||
'Arial=Arial,Helvetica,sans-serif',
|
||||
'Comic Sans MS=Comic Sans MS,cursive,sans-serif',
|
||||
'Courier New=Courier New,Courier,monospace',
|
||||
'Georgia=Georgia,serif',
|
||||
'Helvetica=Helvetica,Arial,sans-serif',
|
||||
'Impact=Impact,Charcoal,sans-serif',
|
||||
'Lucida Sans Unicode=Lucida Sans Unicode,Lucida Grande,sans-serif',
|
||||
'Palatino Linotype=Palatino Linotype,Book Antiqua,Palatino,serif',
|
||||
'Tahoma=Tahoma,Geneva,sans-serif',
|
||||
'Times New Roman=Times New Roman,Times,serif',
|
||||
'Trebuchet MS=Trebuchet MS,Helvetica,sans-serif',
|
||||
'Verdana=Verdana,Geneva,sans-serif'
|
||||
];
|
||||
|
||||
const BASE_FONT_FAMILIES = new Set(DEFAULT_FONT_FAMILY_FORMATS.flatMap(function (entry) {
|
||||
return entry.split('=')[1].split(',').map(function (family) { return family.toLowerCase(); });
|
||||
}).concat(['system-ui', 'ui-serif', 'ui-sans-serif', 'ui-monospace', 'ui-rounded', 'fantasy', 'math', 'fangsong', 'emoji', 'inherit', 'initial', 'unset', 'revert', 'revert-layer']));
|
||||
|
||||
module.exports = { DEFAULT_FONT_FAMILY_FORMATS, BASE_FONT_FAMILIES };
|
||||
@@ -825,6 +825,58 @@ const VERSIONED_MIGRATIONS = [
|
||||
lastRegionId = Number(regions[regions.length - 1].id);
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
version: '2.19.1',
|
||||
label: 'v2.19.1 rebuild managed font references',
|
||||
run: async function (pool) {
|
||||
const connection = await pool.getConnection();
|
||||
try {
|
||||
await connection.beginTransaction();
|
||||
await connection.query('DELETE FROM c_content_references WHERE reference_type = ?', ['font-family']);
|
||||
|
||||
let lastSlideId = 0;
|
||||
while (true) {
|
||||
const [slides] = await connection.query(
|
||||
'SELECT id, content_json FROM c_slides WHERE id > ? AND content_json IS NOT NULL ORDER BY id ASC LIMIT 500',
|
||||
[lastSlideId]
|
||||
);
|
||||
if (!slides.length) break;
|
||||
const references = [];
|
||||
slides.forEach(function (slide) {
|
||||
references.push.apply(references, collectContentReferences('slide', slide.id, parseJsonSafe(slide.content_json) || {})
|
||||
.filter(function (reference) { return reference.reference_type === 'font-family'; }));
|
||||
});
|
||||
await insertContentReferences(connection, references);
|
||||
lastSlideId = Number(slides[slides.length - 1].id);
|
||||
}
|
||||
|
||||
let lastRegionId = 0;
|
||||
while (true) {
|
||||
const [regions] = await connection.query(
|
||||
'SELECT id, template_id, region_key, default_content_json FROM c_template_regions WHERE id > ? AND default_content_json IS NOT NULL ORDER BY id ASC LIMIT 500',
|
||||
[lastRegionId]
|
||||
);
|
||||
if (!regions.length) break;
|
||||
const references = [];
|
||||
regions.forEach(function (region) {
|
||||
const regionContent = {};
|
||||
regionContent[region.region_key] = parseJsonSafe(region.default_content_json) || {};
|
||||
references.push.apply(references, collectContentReferences('template', region.template_id, regionContent)
|
||||
.filter(function (reference) { return reference.reference_type === 'font-family'; }));
|
||||
});
|
||||
await insertContentReferences(connection, references);
|
||||
lastRegionId = Number(regions[regions.length - 1].id);
|
||||
}
|
||||
|
||||
await connection.commit();
|
||||
} catch (error) {
|
||||
await connection.rollback();
|
||||
throw error;
|
||||
} finally {
|
||||
connection.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -2,24 +2,11 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const { migrateLegacyAssets } = require('#src/web/lib/media/assets-storage');
|
||||
const { DEFAULT_FONT_FAMILY_FORMATS } = require('#src/data/font-families');
|
||||
|
||||
const FONT_LIBRARY_DIR_NAME = 'assets/fonts';
|
||||
const FONT_MANIFEST_FILE = 'fonts.json';
|
||||
const FONT_STYLESHEET_FILE = 'fonts.css';
|
||||
const DEFAULT_FONT_FAMILY_FORMATS = [
|
||||
'Arial=Arial,Helvetica,sans-serif',
|
||||
'Comic Sans MS=Comic Sans MS,cursive,sans-serif',
|
||||
'Courier New=Courier New,Courier,monospace',
|
||||
'Georgia=Georgia,serif',
|
||||
'Helvetica=Helvetica,Arial,sans-serif',
|
||||
'Impact=Impact,Charcoal,sans-serif',
|
||||
'Lucida Sans Unicode=Lucida Sans Unicode,Lucida Grande,sans-serif',
|
||||
'Palatino Linotype=Palatino Linotype,Book Antiqua,Palatino,serif',
|
||||
'Tahoma=Tahoma,Geneva,sans-serif',
|
||||
'Times New Roman=Times New Roman,Times,serif',
|
||||
'Trebuchet MS=Trebuchet MS,Helvetica,sans-serif',
|
||||
'Verdana=Verdana,Geneva,sans-serif'
|
||||
];
|
||||
const FONT_FILE_EXTENSIONS = new Map([
|
||||
['.woff2', 'woff2'],
|
||||
['.woff', 'woff'],
|
||||
|
||||
Reference in new issue
Block a user