mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: copy FA fonts to build directory instead of serving them directly (#11891)
resolves issues when proxies don't fall back to NodeBB for assets
This commit is contained in:
2
public/scss/fontawesome/loader.scss
vendored
2
public/scss/fontawesome/loader.scss
vendored
@@ -1,4 +1,4 @@
|
|||||||
$fa-font-path: "./vendor/fontawesome/webfonts";
|
$fa-font-path: "./fontawesome/webfonts";
|
||||||
@import "fontawesome";
|
@import "fontawesome";
|
||||||
@import "v4-shims";
|
@import "v4-shims";
|
||||||
@import "nodebb-shims";
|
@import "nodebb-shims";
|
||||||
@@ -5,6 +5,7 @@ const winston = require('winston');
|
|||||||
const nconf = require('nconf');
|
const nconf = require('nconf');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const { mkdirp } = require('mkdirp');
|
||||||
|
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
@@ -139,6 +140,20 @@ function getFontawesomeStyle() {
|
|||||||
return styles.map(style => `@import "fontawesome/style-${style}";`).join('\n');
|
return styles.map(style => `@import "fontawesome/style-${style}";`).join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function copyFontAwesomeFiles() {
|
||||||
|
await mkdirp(path.join(__dirname, '../../build/public/fontawesome/webfonts'));
|
||||||
|
const fonts = await fs.promises.opendir(path.join(utils.getFontawesomePath(), '/webfonts'));
|
||||||
|
const copyOperations = [];
|
||||||
|
for await (const file of fonts) {
|
||||||
|
if (file.isFile() && file.name.match(/\.(woff2|ttf|eot)?$/)) { // there shouldn't be any legacy eot files, but just in case we'll allow it
|
||||||
|
copyOperations.push(
|
||||||
|
fs.promises.copyFile(path.join(fonts.path, file.name), path.join(__dirname, '../../build/public/fontawesome/webfonts/', file.name))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await Promise.all(copyOperations);
|
||||||
|
}
|
||||||
|
|
||||||
async function filterMissingFiles(filepaths) {
|
async function filterMissingFiles(filepaths) {
|
||||||
const exists = await Promise.all(
|
const exists = await Promise.all(
|
||||||
filepaths.map(async (filepath) => {
|
filepaths.map(async (filepath) => {
|
||||||
@@ -186,7 +201,7 @@ async function getBundleMetadata(target) {
|
|||||||
const paths = [
|
const paths = [
|
||||||
path.join(__dirname, '../../node_modules'),
|
path.join(__dirname, '../../node_modules'),
|
||||||
path.join(__dirname, '../../public/scss'),
|
path.join(__dirname, '../../public/scss'),
|
||||||
path.join(__dirname, '../../public/vendor/fontawesome/scss'),
|
path.join(__dirname, '../../public/fontawesome/scss'),
|
||||||
path.join(utils.getFontawesomePath(), 'scss'),
|
path.join(utils.getFontawesomePath(), 'scss'),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -324,6 +339,7 @@ CSS.buildBundle = async function (target, fork) {
|
|||||||
await Promise.all([
|
await Promise.all([
|
||||||
fs.promises.writeFile(path.join(__dirname, '../../build/public', `${target}.css`), ltr.code),
|
fs.promises.writeFile(path.join(__dirname, '../../build/public', `${target}.css`), ltr.code),
|
||||||
fs.promises.writeFile(path.join(__dirname, '../../build/public', `${target}-rtl.css`), rtl.code),
|
fs.promises.writeFile(path.join(__dirname, '../../build/public', `${target}-rtl.css`), rtl.code),
|
||||||
|
copyFontAwesomeFiles(),
|
||||||
]);
|
]);
|
||||||
return [ltr.code, rtl.code];
|
return [ltr.code, rtl.code];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ const meta = require('../meta');
|
|||||||
const controllers = require('../controllers');
|
const controllers = require('../controllers');
|
||||||
const controllerHelpers = require('../controllers/helpers');
|
const controllerHelpers = require('../controllers/helpers');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
const utils = require('../utils');
|
|
||||||
|
|
||||||
const authRoutes = require('./authentication');
|
const authRoutes = require('./authentication');
|
||||||
const writeRoutes = require('./write');
|
const writeRoutes = require('./write');
|
||||||
@@ -173,7 +172,6 @@ function addCoreRoutes(app, router, middleware, mounts) {
|
|||||||
const statics = [
|
const statics = [
|
||||||
{ route: '/assets', path: path.join(__dirname, '../../build/public') },
|
{ route: '/assets', path: path.join(__dirname, '../../build/public') },
|
||||||
{ route: '/assets', path: path.join(__dirname, '../../public') },
|
{ route: '/assets', path: path.join(__dirname, '../../public') },
|
||||||
{ route: '/assets/vendor/fontawesome/webfonts', path: path.join(utils.getFontawesomePath(), 'webfonts') },
|
|
||||||
];
|
];
|
||||||
const staticOptions = {
|
const staticOptions = {
|
||||||
maxAge: app.enabled('cache') ? 5184000000 : 0,
|
maxAge: app.enabled('cache') ? 5184000000 : 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user