rename pageBasename by pageId
This commit is contained in:
parent
6eccd313b6
commit
307650aaea
4
src/bin/build-keycloak-theme/generateFtl/error.ftl
Normal file
4
src/bin/build-keycloak-theme/generateFtl/error.ftl
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<script>const _=
|
||||||
|
{
|
||||||
|
}
|
||||||
|
</script>
|
@ -9,7 +9,9 @@ import fs from "fs";
|
|||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import { objectKeys } from "evt/tools/typeSafety/objectKeys";
|
import { objectKeys } from "evt/tools/typeSafety/objectKeys";
|
||||||
|
|
||||||
function loadFtlFile(ftlFileBasename: "template.ftl" | "login.ftl" | "register.ftl" | "info.ftl") {
|
export type PageId = "login.ftl" | "register.ftl" | "info.ftl" | "error.ftl";
|
||||||
|
|
||||||
|
function loadFtlFile(ftlFileBasename: PageId | "template.ftl") {
|
||||||
return fs.readFileSync(pathJoin(__dirname, ftlFileBasename))
|
return fs.readFileSync(pathJoin(__dirname, ftlFileBasename))
|
||||||
.toString("utf8")
|
.toString("utf8")
|
||||||
.match(/^<script>const _=((?:.|\n)+)<\/script>[\n]?$/)![1];
|
.match(/^<script>const _=((?:.|\n)+)<\/script>[\n]?$/)![1];
|
||||||
@ -98,16 +100,16 @@ export function generateFtlFilesCodeFactory(
|
|||||||
|
|
||||||
function generateFtlFilesCode(
|
function generateFtlFilesCode(
|
||||||
params: {
|
params: {
|
||||||
pageBasename: "login.ftl" | "register.ftl" | "info.ftl"
|
pageId: PageId;
|
||||||
}
|
}
|
||||||
): { ftlCode: string; } {
|
): { ftlCode: string; } {
|
||||||
|
|
||||||
const { pageBasename } = params;
|
const { pageId } = params;
|
||||||
|
|
||||||
const $ = cheerio.load(partiallyFixedIndexHtmlCode);
|
const $ = cheerio.load(partiallyFixedIndexHtmlCode);
|
||||||
|
|
||||||
const ftlPlaceholders = {
|
const ftlPlaceholders = {
|
||||||
'{ "x": "kxOlLqMeOed9sdLdIdOxd444" }': loadFtlFile(pageBasename),
|
'{ "x": "kxOlLqMeOed9sdLdIdOxd444" }': loadFtlFile(pageId),
|
||||||
...ftlCommonPlaceholders
|
...ftlCommonPlaceholders
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -117,7 +119,7 @@ export function generateFtlFilesCodeFactory(
|
|||||||
'<script>',
|
'<script>',
|
||||||
'',
|
'',
|
||||||
` window.${ftlValuesGlobalName} = Object.assign(`,
|
` window.${ftlValuesGlobalName} = Object.assign(`,
|
||||||
` { "pageBasename": "${pageBasename}" },`,
|
` { "pageId": "${pageId}" },`,
|
||||||
` ${objectKeys(ftlPlaceholders)[0]}`,
|
` ${objectKeys(ftlPlaceholders)[0]}`,
|
||||||
' );',
|
' );',
|
||||||
'',
|
'',
|
||||||
|
@ -70,12 +70,12 @@ export function generateKeycloakThemeResources(
|
|||||||
).toString("utf8")
|
).toString("utf8")
|
||||||
});
|
});
|
||||||
|
|
||||||
(["login.ftl", "register.ftl"] as const).forEach(pageBasename => {
|
(["login.ftl", "register.ftl"] as const).forEach(pageId => {
|
||||||
|
|
||||||
const { ftlCode } = generateFtlFilesCode({ pageBasename });
|
const { ftlCode } = generateFtlFilesCode({ pageId });
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
pathJoin(themeDirPath, pageBasename),
|
pathJoin(themeDirPath, pageId),
|
||||||
Buffer.from(ftlCode, "utf8")
|
Buffer.from(ftlCode, "utf8")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
38
src/lib/components/Error.tsx
Normal file
38
src/lib/components/Error.tsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
import { memo } from "react";
|
||||||
|
import { Template } from "./Template";
|
||||||
|
import type { KcProps } from "./KcProps";
|
||||||
|
import { assert } from "../tools/assert";
|
||||||
|
import { kcContext } from "../kcContext";
|
||||||
|
import { useKcTranslation } from "../i18n/useKcTranslation";
|
||||||
|
|
||||||
|
export const Error = memo((props: KcProps) => {
|
||||||
|
|
||||||
|
const { t } = useKcTranslation();
|
||||||
|
|
||||||
|
assert(
|
||||||
|
kcContext !== undefined &&
|
||||||
|
kcContext.pageId === "error.ftl" &&
|
||||||
|
kcContext.message !== undefined
|
||||||
|
);
|
||||||
|
|
||||||
|
const { message, client } = kcContext;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Template
|
||||||
|
{...props}
|
||||||
|
displayMessage={false}
|
||||||
|
headerNode={t("errorTitle")}
|
||||||
|
formNode={
|
||||||
|
<div id="kc-error-message">
|
||||||
|
<p className="instruction">{message.summary}</p>
|
||||||
|
<#if client?? && client.baseUrl?has_content>
|
||||||
|
<p><a id="backToApplication" href="${client.baseUrl}">${kcSanitize(msg("backToApplication"))?no_esc}</a></p>
|
||||||
|
</#if>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
@ -12,7 +12,7 @@ export const Info = memo((props: KcProps) => {
|
|||||||
|
|
||||||
assert(
|
assert(
|
||||||
kcContext !== undefined &&
|
kcContext !== undefined &&
|
||||||
kcContext.pageBasename === "info.ftl" &&
|
kcContext.pageId === "info.ftl" &&
|
||||||
kcContext.message !== undefined
|
kcContext.message !== undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ export const KcApp = memo((props: KcProps) => {
|
|||||||
|
|
||||||
assert(kcContext !== undefined, "App is not currently served by a Keycloak server");
|
assert(kcContext !== undefined, "App is not currently served by a Keycloak server");
|
||||||
|
|
||||||
switch (kcContext.pageBasename) {
|
switch (kcContext.pageId) {
|
||||||
case "login.ftl": return <Login {...props} />;
|
case "login.ftl": return <Login {...props} />;
|
||||||
case "register.ftl": return <Register {...props} />;
|
case "register.ftl": return <Register {...props} />;
|
||||||
case "info.ftl": return <Info {...props} />;
|
case "info.ftl": return <Info {...props} />;
|
||||||
|
@ -14,7 +14,7 @@ export const Login = memo((props: KcProps) => {
|
|||||||
|
|
||||||
assert(
|
assert(
|
||||||
kcContext !== undefined &&
|
kcContext !== undefined &&
|
||||||
kcContext.pageBasename === "login.ftl"
|
kcContext.pageId === "login.ftl"
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -12,7 +12,7 @@ export const Register = memo((props: KcProps) => {
|
|||||||
|
|
||||||
assert(
|
assert(
|
||||||
kcContext !== undefined &&
|
kcContext !== undefined &&
|
||||||
kcContext.pageBasename === "register.ftl"
|
kcContext.pageId === "register.ftl"
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
@ -9,5 +9,6 @@ export * from "./components/Login";
|
|||||||
export * from "./components/Template";
|
export * from "./components/Template";
|
||||||
export * from "./components/KcApp";
|
export * from "./components/KcApp";
|
||||||
export * from "./components/Info";
|
export * from "./components/Info";
|
||||||
|
export * from "./components/Error";
|
||||||
|
|
||||||
export * from "./tools/assert";
|
export * from "./tools/assert";
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import { ftlValuesGlobalName } from "../bin/build-keycloak-theme/ftlValuesGlobalName";
|
import { ftlValuesGlobalName } from "../bin/build-keycloak-theme/ftlValuesGlobalName";
|
||||||
import type { generateFtlFilesCodeFactory } from "../bin/build-keycloak-theme/generateFtl";
|
import type { PageId } from "../bin/build-keycloak-theme/generateFtl";
|
||||||
import { id } from "evt/tools/typeSafety/id";
|
import { id } from "evt/tools/typeSafety/id";
|
||||||
import type { KcLanguageTag } from "./i18n/KcLanguageTag";
|
import type { KcLanguageTag } from "./i18n/KcLanguageTag";
|
||||||
import { doExtends } from "evt/tools/typeSafety/doExtends";
|
import { doExtends } from "evt/tools/typeSafety/doExtends";
|
||||||
@ -10,7 +10,7 @@ import type { LanguageLabel } from "./i18n/KcLanguageTag";
|
|||||||
type ExtractAfterStartingWith<Prefix extends string, StrEnum> =
|
type ExtractAfterStartingWith<Prefix extends string, StrEnum> =
|
||||||
StrEnum extends `${Prefix}${infer U}` ? U : never;
|
StrEnum extends `${Prefix}${infer U}` ? U : never;
|
||||||
|
|
||||||
export type KcContext = KcContext.Login | KcContext.Register | KcContext.Info;
|
export type KcContext = KcContext.Login | KcContext.Register | KcContext.Info | KcContext.Error;
|
||||||
export declare namespace KcContext {
|
export declare namespace KcContext {
|
||||||
|
|
||||||
export type Template = {
|
export type Template = {
|
||||||
@ -55,7 +55,7 @@ export declare namespace KcContext {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Login = Template & {
|
export type Login = Template & {
|
||||||
pageBasename: "login.ftl";
|
pageId: "login.ftl";
|
||||||
url: {
|
url: {
|
||||||
loginResetCredentialsUrl: string;
|
loginResetCredentialsUrl: string;
|
||||||
registrationUrl: string;
|
registrationUrl: string;
|
||||||
@ -87,7 +87,7 @@ export declare namespace KcContext {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Register = Template & {
|
export type Register = Template & {
|
||||||
pageBasename: "register.ftl";
|
pageId: "register.ftl";
|
||||||
url: {
|
url: {
|
||||||
registrationAction: string;
|
registrationAction: string;
|
||||||
};
|
};
|
||||||
@ -120,7 +120,7 @@ export declare namespace KcContext {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Info = Template & {
|
export type Info = Template & {
|
||||||
pageBasename: "info.ftl";
|
pageId: "info.ftl";
|
||||||
messageHeader?: string;
|
messageHeader?: string;
|
||||||
requiredActions?: ExtractAfterStartingWith<"requiredAction.",MessageKey>[];
|
requiredActions?: ExtractAfterStartingWith<"requiredAction.",MessageKey>[];
|
||||||
skipLink: boolean;
|
skipLink: boolean;
|
||||||
@ -131,14 +131,13 @@ export declare namespace KcContext {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Error = Template & {
|
||||||
|
pageId: "error.ftl"
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
doExtends<KcContext["pageId"], PageId>();
|
||||||
type T = KcContext["pageBasename"];
|
doExtends<PageId, KcContext["pageId"]>();
|
||||||
type U = Parameters<ReturnType<typeof generateFtlFilesCodeFactory>["generateFtlFilesCode"]>[0]["pageBasename"];
|
|
||||||
|
|
||||||
doExtends<T, U>();
|
|
||||||
doExtends<U, T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
export const kcContext = id<KcContext | undefined>((window as any)[ftlValuesGlobalName]);
|
export const kcContext = id<KcContext | undefined>((window as any)[ftlValuesGlobalName]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user