Commit 92a9f2b8 authored by Nicolas Frandeboeuf's avatar Nicolas Frandeboeuf
Browse files

Fix themes not working with subdirectories

parent eb10476e
Pipeline #31652 passed with stages
in 9 minutes and 56 seconds
......@@ -17,7 +17,7 @@ class ThemeLink extends React.Component {
isStyleSheetLoaded() {
return Array.from(document.styleSheets).some(sheet => {
return sheet.href.endsWith(`themes/${this.props.theme}/bundle.css`);
return sheet.href.endsWith(`themes-${this.props.theme}-bundle.css`);
});
}
......@@ -92,7 +92,7 @@ class ThemeLink extends React.Component {
};
return (
<link rel="stylesheet" href={`themes/${this.props.theme}/bundle.css`} ref={refLink} />
<link rel="stylesheet" href={`themes-${this.props.theme}-bundle.css`} ref={refLink} />
);
}
}
......
......@@ -5,6 +5,7 @@ const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const SpritesmithPlugin = require('webpack-spritesmith');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
// List available locales, to fetch only the required locales from Moment.JS:
// Build a regexp that selects the locale's name without the JS extension (due
......@@ -33,9 +34,11 @@ let entries = {
]
};
fs.readdirSync('client/themes').filter(
const themes = fs.readdirSync('client/themes').filter(
f => fs.statSync(`client/themes/${f}`).isDirectory()
).forEach(theme => {
);
themes.forEach(theme => {
entries[`themes/${theme}`] = `./client/themes/${theme}/style.css`;
});
......@@ -83,8 +86,7 @@ const config = {
{
loader: 'file-loader',
query: {
name: 'assets/images/[sha512:hash:hex].[ext]',
publicPath: '../../'
name: 'assets/images/[sha512:hash:hex].[ext]'
}
},
{
......@@ -109,8 +111,7 @@ const config = {
query: {
limit: 10000,
mimetype: 'application/font-woff',
name: 'assets/fonts/[name]-[hash].[ext]',
publicPath: '../../'
name: 'assets/fonts/[name]-[hash].[ext]'
}
}
]
......@@ -121,8 +122,7 @@ const config = {
{
loader: 'file-loader',
query: {
name: 'assets/fonts/[name]-[sha512:hash:hex].[ext]',
publicPath: '../../'
name: 'assets/fonts/[name]-[sha512:hash:hex].[ext]'
}
}
]
......@@ -150,7 +150,7 @@ const config = {
let pathname = getPath('[name]');
// Entries names with '/' refer to themes paths.
if (pathname.indexOf('/') !== -1) {
return `${pathname}/bundle.css`;
return `${pathname.replace('/', '-')}-bundle.css`;
}
return `${pathname}.css`;
},
......@@ -172,7 +172,9 @@ const config = {
}
}),
// Only keep the useful locales from Moment
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, locales)
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, locales),
// Generate a themes.json files with the list of themes
new GenerateJsonPlugin('themes.json', {themes: themes})
]
}
......
......@@ -20,14 +20,14 @@ const ERR_MSG_LOADING_ALL = 'Error when loading all Kresus data';
const ENCRYPTION_ALGORITHM = 'aes-256-ctr';
const PASSPHRASE_VALIDATION_REGEXP = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}$/;
const ENCRYPTED_CONTENT_TAG = new Buffer('KRE');
const readdir = promisify(fs.readdir);
const readFile = promisify(fs.readFile);
async function getThemes() {
const themesDirPath = path.resolve(__dirname, '..', '..', '..', 'client', 'themes');
const children = await readdir(themesDirPath);
return children.filter(child => {
return fs.statSync(`${themesDirPath}/${child}`).isDirectory();
});
const themesManifest = await readFile(
`${path.resolve(__dirname, '..', '..', '..', 'client')}/themes.json`,
'utf8'
);
return JSON.parse(themesManifest).themes;
}
async function getAllData(isExport = false, cleanPassword = true) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment