From 187f62c71f645baf5b91450c90b66da18076466a Mon Sep 17 00:00:00 2001 From: tonievalue Date: Tue, 29 Apr 2025 16:08:52 +0200 Subject: [PATCH 1/5] feat: add function type name in header --- web/astro.config.mjs | 1 + web/src/components/TypeBadge.astro | 51 +++++++++++++++++++++++++++ web/src/overrides/PageTitle.astro | 55 ++++++++++++++++++++++++++++++ web/src/pages/[func].astro | 44 ++++++++++++------------ web/src/styles/custom.css | 14 ++++++-- web/src/utils/functions.ts | 14 +++++--- web/src/utils/types.ts | 1 + 7 files changed, 151 insertions(+), 29 deletions(-) create mode 100644 web/src/components/TypeBadge.astro create mode 100644 web/src/overrides/PageTitle.astro create mode 100644 web/src/utils/types.ts diff --git a/web/astro.config.mjs b/web/astro.config.mjs index 8965ba23..77642022 100644 --- a/web/astro.config.mjs +++ b/web/astro.config.mjs @@ -27,6 +27,7 @@ export default defineConfig({ }, components: { // Override some default components + PageTitle: './src/overrides/PageTitle.astro', Pagination: './src/overrides/Pagination.astro', }, customCss: [ './src/styles/custom.css' ], diff --git a/web/src/components/TypeBadge.astro b/web/src/components/TypeBadge.astro new file mode 100644 index 00000000..e87fc808 --- /dev/null +++ b/web/src/components/TypeBadge.astro @@ -0,0 +1,51 @@ +--- +import { functionTypePrettyName } from '@src/utils/functions'; +import type { FunctionType } from '@src/utils/types'; + +interface Props { + type: FunctionType; +} + +const { type } = Astro.props; +--- + +{type == 'client' &&
{functionTypePrettyName['client']}
} +{type == 'server' &&
{functionTypePrettyName['server']}
} +{type == 'shared' &&
{functionTypePrettyName['shared']}
} + + \ No newline at end of file diff --git a/web/src/overrides/PageTitle.astro b/web/src/overrides/PageTitle.astro new file mode 100644 index 00000000..ef640329 --- /dev/null +++ b/web/src/overrides/PageTitle.astro @@ -0,0 +1,55 @@ +--- +import TypeBadge from '@src/components/TypeBadge.astro'; +--- +
+

{Astro.props.entry.data.title}

+ + + + +
+ + + + diff --git a/web/src/pages/[func].astro b/web/src/pages/[func].astro index e4efce4c..6f3348a3 100644 --- a/web/src/pages/[func].astro +++ b/web/src/pages/[func].astro @@ -36,27 +36,27 @@ if ( funcExamples.length > 0 ){ } }); } ---- - - -

Type: {funcTypePretty}

- - {funcPair && ( -

Pair: { funcPair }

- )} - - - - {funcExamples.length > 0 && funcExamples.map((example: any) => ( -
-

- -
- ))} +--- -
+
+ + {funcPair && ( +

Pair: { funcPair }

+ )} + + + + + {funcExamples.length > 0 && funcExamples.map((example: any) => ( +
+

+ +
+ ))} +
+
\ No newline at end of file diff --git a/web/src/styles/custom.css b/web/src/styles/custom.css index 737f4dd0..3df973cb 100644 --- a/web/src/styles/custom.css +++ b/web/src/styles/custom.css @@ -1,12 +1,20 @@ /* Custom MTA Wiki CSS */ +:root { + --color-type-shared: rgba(117, 117, 255, 1); + --color-type-shared-background: rgba(117, 117, 255, 0.05); + --color-type-client: rgba(255, 50, 50, 1); + --color-type-client-background: rgba(255, 50, 50, 0.05); + --color-type-server: rgba(232, 115, 0, 1); + --color-type-server-background: rgba(232, 115, 0, 0.05); +} /* Styling for "Client-side / Server-side / Shared" */ .side-shared { - color: rgb(117, 117, 255); + color: var(--color-type-shared); } .side-client { - color: rgb(255, 50, 50); + color: var(--color-type-client); } .side-server { - color: rgb(232, 115, 0); + color: var(--color-type-server); } diff --git a/web/src/utils/functions.ts b/web/src/utils/functions.ts index 0ed9c837..b75c7151 100644 --- a/web/src/utils/functions.ts +++ b/web/src/utils/functions.ts @@ -1,6 +1,8 @@ import { getCollection } from 'astro:content'; import path from 'path'; +import type { FunctionType } from './types'; + type FunctionItem = Awaited>[number]; type FunctionsByCategory = { @@ -18,16 +20,20 @@ export type FunctionData = { server?: any; }; -function getFunctionType(data: FunctionData): 'shared' | 'client' | 'server' { +export const functionTypePrettyName = { + 'client': 'Client-side', + 'server': 'Server-side', + 'shared': 'Shared', +}; + +function getFunctionType(data: FunctionData): FunctionType { if (data.shared) return 'shared'; if (data.client) return 'client'; return 'server'; } function getFunctionTypePretty(data: FunctionData): string { const funcType = getFunctionType(data); - if (funcType === 'shared') return 'Shared'; - if (funcType === 'client') return 'Client-side'; - return 'Server-side'; + return functionTypePrettyName[funcType] ?? 'Server-side'; } export function getFunctionInfo(data: FunctionData): any { diff --git a/web/src/utils/types.ts b/web/src/utils/types.ts new file mode 100644 index 00000000..0fc79202 --- /dev/null +++ b/web/src/utils/types.ts @@ -0,0 +1 @@ +export type FunctionType = 'shared' | 'client' | 'server'; \ No newline at end of file From f761556e3ec4a122462623f0fa4e00b4f33c489b Mon Sep 17 00:00:00 2001 From: tonievalue Date: Tue, 29 Apr 2025 16:24:00 +0200 Subject: [PATCH 2/5] fix: fix badges on higher resolutions --- web/src/overrides/PageTitle.astro | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/src/overrides/PageTitle.astro b/web/src/overrides/PageTitle.astro index ef640329..014adb1e 100644 --- a/web/src/overrides/PageTitle.astro +++ b/web/src/overrides/PageTitle.astro @@ -45,6 +45,11 @@ import TypeBadge from '@src/components/TypeBadge.astro'; } @media (width >= 48rem) { + h1 { + display: initial; + width: auto; + } + .page-title-container { justify-content: space-between; align-items: center; From ba07d05efbd581210c12ca57c2622b5375e49da5 Mon Sep 17 00:00:00 2001 From: tonievalue Date: Tue, 29 Apr 2025 19:57:33 +0200 Subject: [PATCH 3/5] feat: improve visibility of function type --- web/src/components/TypeBadge.astro | 51 ---------------------- web/src/overrides/PageTitle.astro | 69 +++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 67 deletions(-) delete mode 100644 web/src/components/TypeBadge.astro diff --git a/web/src/components/TypeBadge.astro b/web/src/components/TypeBadge.astro deleted file mode 100644 index e87fc808..00000000 --- a/web/src/components/TypeBadge.astro +++ /dev/null @@ -1,51 +0,0 @@ ---- -import { functionTypePrettyName } from '@src/utils/functions'; -import type { FunctionType } from '@src/utils/types'; - -interface Props { - type: FunctionType; -} - -const { type } = Astro.props; ---- - -{type == 'client' &&
{functionTypePrettyName['client']}
} -{type == 'server' &&
{functionTypePrettyName['server']}
} -{type == 'shared' &&
{functionTypePrettyName['shared']}
} - - \ No newline at end of file diff --git a/web/src/overrides/PageTitle.astro b/web/src/overrides/PageTitle.astro index 014adb1e..93e41a80 100644 --- a/web/src/overrides/PageTitle.astro +++ b/web/src/overrides/PageTitle.astro @@ -1,21 +1,15 @@ --- -import TypeBadge from '@src/components/TypeBadge.astro'; +import { functionTypePrettyName } from '@src/utils/functions'; ---

{Astro.props.entry.data.title}

- - - +
{functionTypePrettyName['client']}
+
{functionTypePrettyName['server']}
+
{functionTypePrettyName['shared']}
From f5b7699508749550362dfbb98156ad9a0fad321c Mon Sep 17 00:00:00 2001 From: tonievalue Date: Tue, 29 Apr 2025 20:03:13 +0200 Subject: [PATCH 4/5] feat: user proper color for border --- web/src/overrides/PageTitle.astro | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/web/src/overrides/PageTitle.astro b/web/src/overrides/PageTitle.astro index 93e41a80..4d7472cf 100644 --- a/web/src/overrides/PageTitle.astro +++ b/web/src/overrides/PageTitle.astro @@ -10,6 +10,16 @@ import { functionTypePrettyName } from '@src/utils/functions';