support homepage with urlPath
This commit is contained in:
parent
0cc02c292f
commit
1cb5dd461b
@ -34,10 +34,11 @@ export function generateFtlFilesCodeFactory(
|
||||
ftlValuesGlobalName: string;
|
||||
cssGlobalsToDefine: Record<string, string>;
|
||||
indexHtmlCode: string;
|
||||
urlPathname: string;
|
||||
}
|
||||
) {
|
||||
|
||||
const { ftlValuesGlobalName, cssGlobalsToDefine, indexHtmlCode } = params;
|
||||
const { ftlValuesGlobalName, cssGlobalsToDefine, indexHtmlCode, urlPathname } = params;
|
||||
|
||||
const $ = cheerio.load(indexHtmlCode);
|
||||
|
||||
@ -60,11 +61,17 @@ export function generateFtlFilesCodeFactory(
|
||||
|
||||
const href = $(element).attr(attrName);
|
||||
|
||||
if (!href?.startsWith("/")) {
|
||||
if (href === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
$(element).attr(attrName, "${url.resourcesPath}/build" + href);
|
||||
$(element).attr(
|
||||
attrName,
|
||||
href.replace(
|
||||
new RegExp(`^${urlPathname.replace(/\//g, "\\/")}`),
|
||||
"${url.resourcesPath}/build/"
|
||||
)
|
||||
);
|
||||
|
||||
})
|
||||
);
|
||||
@ -89,9 +96,10 @@ export function generateFtlFilesCodeFactory(
|
||||
...(Object.keys(cssGlobalsToDefine).length === 0 ? [] : [
|
||||
'',
|
||||
'<style>',
|
||||
generateCssCodeToDefineGlobals(
|
||||
{ cssGlobalsToDefine }
|
||||
).cssCodeToPrependInHead,
|
||||
generateCssCodeToDefineGlobals({
|
||||
cssGlobalsToDefine,
|
||||
urlPathname
|
||||
}).cssCodeToPrependInHead,
|
||||
'</style>',
|
||||
''
|
||||
]),
|
||||
|
@ -16,13 +16,14 @@ import { isInside } from "../tools/isInside";
|
||||
|
||||
export function generateKeycloakThemeResources(
|
||||
params: {
|
||||
urlPathname: string;
|
||||
themeName: string;
|
||||
reactAppBuildDirPath: string;
|
||||
keycloakThemeBuildingDirPath: string;
|
||||
}
|
||||
) {
|
||||
|
||||
const { themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath } = params;
|
||||
const { themeName, reactAppBuildDirPath, keycloakThemeBuildingDirPath, urlPathname } = params;
|
||||
|
||||
const themeDirPath = pathJoin(keycloakThemeBuildingDirPath, "src", "main", "resources", "theme", themeName, "login");
|
||||
|
||||
@ -80,7 +81,8 @@ export function generateKeycloakThemeResources(
|
||||
ftlValuesGlobalName,
|
||||
"indexHtmlCode": fs.readFileSync(
|
||||
pathJoin(reactAppBuildDirPath, "index.html")
|
||||
).toString("utf8")
|
||||
).toString("utf8"),
|
||||
urlPathname
|
||||
});
|
||||
|
||||
pageIds.forEach(pageId => {
|
||||
|
@ -6,6 +6,7 @@ import type { ParsedPackageJson } from "./generateJavaStackFiles";
|
||||
import { join as pathJoin, relative as pathRelative, basename as pathBasename } from "path";
|
||||
import * as child_process from "child_process";
|
||||
import { generateDebugFiles, containerLaunchScriptBasename } from "./generateDebugFiles";
|
||||
import { URL } from "url";
|
||||
|
||||
|
||||
const reactProjectDirPath = process.cwd();
|
||||
@ -22,7 +23,16 @@ if (require.main === module) {
|
||||
generateKeycloakThemeResources({
|
||||
keycloakThemeBuildingDirPath,
|
||||
"reactAppBuildDirPath": pathJoin(reactProjectDirPath, "build"),
|
||||
"themeName": parsedPackageJson.name
|
||||
"themeName": parsedPackageJson.name,
|
||||
"urlPathname": (()=>{
|
||||
|
||||
const { homepage } = parsedPackageJson;
|
||||
|
||||
return homepage === undefined ?
|
||||
"/" :
|
||||
new URL(homepage).pathname.replace(/([^/])$/, "$1/");
|
||||
|
||||
})()
|
||||
});
|
||||
|
||||
const { jarFilePath } = generateJavaStackFiles({
|
||||
|
@ -11,8 +11,8 @@ export function replaceImportFromStaticInJsCode(
|
||||
const { jsCode, ftlValuesGlobalName } = params;
|
||||
|
||||
const fixedJsCode = jsCode!.replace(
|
||||
/"static\//g,
|
||||
`window.${ftlValuesGlobalName}.url.resourcesPath.replace(/^\\//,"") + "/build/static/`
|
||||
/ [^ ]+"static\//g,
|
||||
` window.${ftlValuesGlobalName}.url.resourcesPath + "/build/static/`
|
||||
);
|
||||
|
||||
return { fixedJsCode };
|
||||
@ -60,12 +60,13 @@ export function replaceImportFromStaticInCssCode(
|
||||
export function generateCssCodeToDefineGlobals(
|
||||
params: {
|
||||
cssGlobalsToDefine: Record<string, string>;
|
||||
urlPathname: string;
|
||||
}
|
||||
): {
|
||||
cssCodeToPrependInHead: string;
|
||||
} {
|
||||
|
||||
const { cssGlobalsToDefine } = params;
|
||||
const { cssGlobalsToDefine, urlPathname } = params;
|
||||
|
||||
return {
|
||||
"cssCodeToPrependInHead": [
|
||||
@ -74,7 +75,7 @@ export function generateCssCodeToDefineGlobals(
|
||||
.map(cssVariableName => [
|
||||
`--${cssVariableName}:`,
|
||||
cssGlobalsToDefine[cssVariableName]
|
||||
.replace(/url\(/g, "url(${url.resourcesPath}/build")
|
||||
.replace(new RegExp(`url\\(${urlPathname.replace(/\//g,"\\/")}`, "g"),"url(${url.resourcesPath}/build/")
|
||||
].join(" "))
|
||||
.map(line => ` ${line};`),
|
||||
"}"
|
||||
|
@ -9,8 +9,9 @@ import {
|
||||
setupSampleReactProject();
|
||||
|
||||
generateKeycloakThemeResources({
|
||||
"themeName": "onyxia-ui",
|
||||
"themeName": "keycloakify-demo-app",
|
||||
"reactAppBuildDirPath": pathJoin(sampleReactProjectDirPath, "build"),
|
||||
"keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme")
|
||||
"keycloakThemeBuildingDirPath": pathJoin(sampleReactProjectDirPath, "build_keycloak_theme"),
|
||||
"urlPathname": "/keycloakify-demo-app/"
|
||||
});
|
||||
|
||||
|
@ -45,6 +45,6 @@ const { fixedCssCode, cssGlobalsToDefine } = replaceImportFromStaticInCssCode({
|
||||
console.log({ fixedCssCode, cssGlobalsToDefine });
|
||||
|
||||
|
||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({ cssGlobalsToDefine });
|
||||
const { cssCodeToPrependInHead } = generateCssCodeToDefineGlobals({ cssGlobalsToDefine, "urlPathname": "/" });
|
||||
|
||||
console.log({ cssCodeToPrependInHead });
|
Loading…
x
Reference in New Issue
Block a user