Skip to content

Commit

Permalink
Refactor cSpell words and cleanup deprecated content helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Adammatthiesen committed Dec 12, 2024
1 parent c51c3d6 commit 1262567
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 139 deletions.
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.gotoLocation.multipleDefinitions": "goto",
"cSpell.words": ["astrojs", "Libravatar", "oslojs", "robotstxt", "studiocms", "withstudiocms"]
"cSpell.words": [
"astrojs",
"Libravatar",
"onest",
"oslojs",
"robotstxt",
"studiocms",
"withstudiocms"
]
}
4 changes: 2 additions & 2 deletions packages/studiocms_auth/src/components/OAuthButtonStack.astro
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
import { getLangFromUrl, useTranslations } from 'studiocms:i18n';
import { useTranslations } from 'studiocms:i18n';
import { Divider } from '@studiocms/ui/components';
import OAuthButton from './OAuthButton.astro';
import { providerData, showOAuth } from './oAuthButtonProviders';
const lang = getLangFromUrl(Astro.url);
const lang = 'en-us';
const t = useTranslations(lang, '@studiocms/auth:oauth-stack');
const shouldShowOAuth = showOAuth && providerData.some(({ enabled }) => enabled);
Expand Down
15 changes: 1 addition & 14 deletions packages/studiocms_auth/src/components/StaticAuthCheck.astro
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
---
import { getUserData } from 'studiocms:auth/lib/user';
import { getLangFromUrl, useTranslatedPath } from 'studiocms:i18n';
import { StudioCMSRoutes } from 'studiocms:lib';
const { isLoggedIn } = await getUserData(Astro);
// Get the language and translations
const referer = Astro.request.headers.get('referer');
if (!referer) {
throw new Error('No referer found');
}
const lang = getLangFromUrl(new URL(referer));
const translatePath = useTranslatedPath(lang);
const {
mainLinks: { dashboardIndex },
} = StudioCMSRoutes;
---
<div
id="login-check"
style="display: none;"
data-isloggedin={`${isLoggedIn}`}
data-redirectroute={translatePath(dashboardIndex)}
data-redirectroute={StudioCMSRoutes.mainLinks.dashboardIndex}
></div>

<script is:inline>
Expand Down
38 changes: 12 additions & 26 deletions packages/studiocms_auth/src/components/oAuthButtonProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,37 @@ import { authEnvCheck } from 'studiocms:auth/utils/authEnvCheck';
import { AuthConfig } from 'studiocms:config';
import { StudioCMSRoutes } from 'studiocms:lib';

const { providers } = AuthConfig;
const authEnv = await authEnvCheck(AuthConfig.providers);

const {
authLinks: { googleIndex, auth0Index, discordIndex, githubIndex },
} = StudioCMSRoutes;
export const showOAuth = authEnv.SHOW_OAUTH;

const {
DISCORD: { ENABLED: discordEnabled },
GITHUB: { ENABLED: githubEnabled },
GOOGLE: { ENABLED: googleEnabled },
AUTH0: { ENABLED: auth0Enabled },
SHOW_OAUTH,
} = await authEnvCheck(providers);

export const showOAuth = SHOW_OAUTH;

type ProviderData = {
export const providerData: {
enabled: boolean;
href: string;
label: string;
image: string;
};

export const providerData: ProviderData[] = [
}[] = [
{
enabled: githubEnabled,
href: githubIndex,
enabled: authEnv.GITHUB.ENABLED,
href: StudioCMSRoutes.authLinks.githubIndex,
label: 'GitHub',
image: `<svg width="1.5rem" height="auto" viewBox="0 0 98 96" xmlns="http://www.w3.org/2000/svg" class="oauth-logo"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="currentColor"/></svg>`,
},
{
enabled: discordEnabled,
href: discordIndex,
enabled: authEnv.DISCORD.ENABLED,
href: StudioCMSRoutes.authLinks.discordIndex,
label: 'Discord',
image: `<svg xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="auto" viewBox="0 0 256 199" class="oauth-logo"><path fill="currentColor" d="M216.856 16.597A208.5 208.5 0 0 0 164.042 0c-2.275 4.113-4.933 9.645-6.766 14.046q-29.538-4.442-58.533 0c-1.832-4.4-4.55-9.933-6.846-14.046a207.8 207.8 0 0 0-52.855 16.638C5.618 67.147-3.443 116.4 1.087 164.956c22.169 16.555 43.653 26.612 64.775 33.193A161 161 0 0 0 79.735 175.3a136.4 136.4 0 0 1-21.846-10.632a109 109 0 0 0 5.356-4.237c42.122 19.702 87.89 19.702 129.51 0a132 132 0 0 0 5.355 4.237a136 136 0 0 1-21.886 10.653c4.006 8.02 8.638 15.67 13.873 22.848c21.142-6.58 42.646-16.637 64.815-33.213c5.316-56.288-9.08-105.09-38.056-148.36M85.474 135.095c-12.645 0-23.015-11.805-23.015-26.18s10.149-26.2 23.015-26.2s23.236 11.804 23.015 26.2c.02 14.375-10.148 26.18-23.015 26.18m85.051 0c-12.645 0-23.014-11.805-23.014-26.18s10.148-26.2 23.014-26.2c12.867 0 23.236 11.804 23.015 26.2c0 14.375-10.148 26.18-23.015 26.18"/></svg>`,
},
{
enabled: googleEnabled,
href: googleIndex,
enabled: authEnv.GOOGLE.ENABLED,
href: StudioCMSRoutes.authLinks.googleIndex,
label: 'Google',
image: `<svg xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="auto" viewBox="0 0 256 262" class="oauth-logo"><path fill="#4285f4" d="M255.878 133.451c0-10.734-.871-18.567-2.756-26.69H130.55v48.448h71.947c-1.45 12.04-9.283 30.172-26.69 42.356l-.244 1.622l38.755 30.023l2.685.268c24.659-22.774 38.875-56.282 38.875-96.027"/><path fill="#34a853" d="M130.55 261.1c35.248 0 64.839-11.605 86.453-31.622l-41.196-31.913c-11.024 7.688-25.82 13.055-45.257 13.055c-34.523 0-63.824-22.773-74.269-54.25l-1.531.13l-40.298 31.187l-.527 1.465C35.393 231.798 79.49 261.1 130.55 261.1"/><path fill="#fbbc05" d="M56.281 156.37c-2.756-8.123-4.351-16.827-4.351-25.82c0-8.994 1.595-17.697 4.206-25.82l-.073-1.73L15.26 71.312l-1.335.635C5.077 89.644 0 109.517 0 130.55s5.077 40.905 13.925 58.602z"/><path fill="#eb4335" d="M130.55 50.479c24.514 0 41.05 10.589 50.479 19.438l36.844-35.974C195.245 12.91 165.798 0 130.55 0C79.49 0 35.393 29.301 13.925 71.947l42.211 32.783c10.59-31.477 39.891-54.251 74.414-54.251"/></svg>`,
},
{
enabled: auth0Enabled,
href: auth0Index,
enabled: authEnv.AUTH0.ENABLED,
href: StudioCMSRoutes.authLinks.auth0Index,
label: 'Auth0',
image: `<svg xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="auto" viewBox="0 0 32 32" class="oauth-logo"><path fill="currentColor" d="M29.307 9.932L26.161 0H5.796L2.692 9.932c-1.802 5.75.042 12.271 5.089 16.021L16.01 32l8.208-6.068c5.005-3.75 6.911-10.25 5.089-16.021l-8.214 6.104l3.12 9.938l-8.208-6.13l-8.208 6.104l3.141-9.911l-8.25-6.063l10.177-.063l3.146-9.891l3.141 9.87z"/></svg>`,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/studiocms_auth/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export default defineIntegration({
enabled: dashboardEnabled && !options.dbStartPage,
},
{
pattern: 'logout',
pattern: 'logout/',
entrypoint: resolve('./routes/logout.astro'),
enabled: dashboardEnabled && !options.dbStartPage,
},
Expand Down
10 changes: 4 additions & 6 deletions packages/studiocms_auth/src/layouts/AuthLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { Toaster } from '@studiocms/ui/components';
import OAuthButtonStack from '../components/OAuthButtonStack.astro';
import StudioCMSLogoSVG from '../components/StudioCMSLogoSVG.astro';
const { faviconURL } = dashboardConfig;
interface Props {
title: string;
description: string;
Expand All @@ -24,11 +22,11 @@ interface Props {
const { title, description, lang, disableScreen } = Astro.props;
// Get the site config
const siteConfig = await studioCMS_SDK.GET.database.config();
const dbConfig = await studioCMS_SDK.GET.database.config();
// Get the login page background and custom image from the site config
const loginPageBackground = siteConfig?.loginPageBackground;
const loginPageCustomImage = siteConfig?.loginPageCustomImage;
const loginPageBackground = dbConfig?.loginPageBackground;
const loginPageCustomImage = dbConfig?.loginPageCustomImage;
const fallbackImageSrc =
loginPageBackground === 'custom'
Expand All @@ -40,7 +38,7 @@ const fallbackImageSrc =
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="icon" type="image/svg+xml" href={faviconURL} />
<link rel="icon" type="image/svg+xml" href={dashboardConfig.faviconURL} />
<link rel="preload" as="font" type="font/woff2" crossorigin="anonymous" href={onestWoff2} />
<meta name="generator" content={Astro.generator} />
<meta name="generator" content=`StudioCMS v${version}` />
Expand Down
19 changes: 4 additions & 15 deletions packages/studiocms_auth/src/routes/login.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
---
import { authEnvCheck } from 'studiocms:auth/utils/authEnvCheck';
import { AuthConfig } from 'studiocms:config';
import { getLangFromUrl, staticPaths, useTranslatedPath, useTranslations } from 'studiocms:i18n';
import { useTranslations } from 'studiocms:i18n';
import { StudioCMSRoutes } from 'studiocms:lib';
import { Button, Input } from '@studiocms/ui/components';
import type { GetStaticPaths } from 'astro';
import StaticAuthCheck from '../components/StaticAuthCheck.astro';
import AuthLayout from '../layouts/AuthLayout.astro';
const lang = getLangFromUrl(Astro.url);
const lang = 'en-us';
const t = useTranslations(lang, '@studiocms/auth:login');
const tPath = useTranslatedPath(lang);
export const getStaticPaths = (() => {
const paths = staticPaths();
return paths;
}) satisfies GetStaticPaths;
const {
providers,
Expand All @@ -25,10 +18,6 @@ const {
},
} = AuthConfig;
const {
authLinks: { loginAPI, signupURL },
} = StudioCMSRoutes;
const { SHOW_OAUTH } = await authEnvCheck(providers);
let paragraph: string;
Expand All @@ -51,7 +40,7 @@ if (usernameAndPassword && SHOW_OAUTH) {
</div>

{ usernameAndPassword && (
<form class="form" id="login-form" method="post" action={loginAPI}>
<form class="form" id="login-form" method="post" action={StudioCMSRoutes.authLinks.loginAPI}>

<Input label={t('username-label')} name="username" type="text" />
<Input label={t('password-label')} name="password" type='password' />
Expand All @@ -61,7 +50,7 @@ if (usernameAndPassword && SHOW_OAUTH) {
)}

{ allowUserRegistration && (
<p slot="footer">{t('allow-registration-noaccount')} <a href={tPath(signupURL)}>{t('allow-registration-register')}</a></p>
<p slot="footer">{t('allow-registration-noaccount')} <a href={StudioCMSRoutes.authLinks.signupURL}>{t('allow-registration-register')}</a></p>
)}

<StaticAuthCheck server:defer />
Expand Down
16 changes: 3 additions & 13 deletions packages/studiocms_auth/src/routes/logout.astro
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
---
import { getLangFromUrl, staticPaths, useTranslations } from 'studiocms:i18n';
import { useTranslations } from 'studiocms:i18n';
import { StudioCMSRoutes } from 'studiocms:lib';
import type { GetStaticPaths } from 'astro';
import AuthLayout from '../layouts/AuthLayout.astro';
const lang = getLangFromUrl(Astro.url);
const lang = 'en-us';
const t = useTranslations(lang, '@studiocms/auth:logout');
export const getStaticPaths = (() => {
const paths = staticPaths();
return paths;
}) satisfies GetStaticPaths;
const {
authLinks: { logoutAPI },
} = StudioCMSRoutes;
---
<AuthLayout title={t('title')} description={t('description')} lang={lang} disableScreen>

</AuthLayout>

<div style="display: none;" id="redirect-to-logout" data-redirect={logoutAPI}></div>
<div style="display: none;" id="redirect-to-logout" data-redirect={StudioCMSRoutes.authLinks.logoutAPI}></div>

<script>

Expand Down
19 changes: 4 additions & 15 deletions packages/studiocms_auth/src/routes/signup.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
---
import { authEnvCheck } from 'studiocms:auth/utils/authEnvCheck';
import { AuthConfig } from 'studiocms:config';
import { getLangFromUrl, staticPaths, useTranslatedPath, useTranslations } from 'studiocms:i18n';
import { useTranslations } from 'studiocms:i18n';
import { StudioCMSRoutes } from 'studiocms:lib';
import { Button, Input } from '@studiocms/ui/components';
import type { GetStaticPaths } from 'astro';
import StaticAuthCheck from '../components/StaticAuthCheck.astro';
import AuthLayout from '../layouts/AuthLayout.astro';
const lang = getLangFromUrl(Astro.url);
const lang = 'en-us';
const t = useTranslations(lang, '@studiocms/auth:signup');
const tPath = useTranslatedPath(lang);
export const getStaticPaths = (() => {
const paths = staticPaths();
return paths;
}) satisfies GetStaticPaths;
const {
providers,
Expand All @@ -25,10 +18,6 @@ const {
},
} = AuthConfig;
const {
authLinks: { registerAPI, loginURL },
} = StudioCMSRoutes;
const { SHOW_OAUTH } = await authEnvCheck(providers);
let paragraph: string;
Expand All @@ -51,7 +40,7 @@ if (usernameAndPassword && SHOW_OAUTH) {
</div>

{ usernameAndPassword && (
<form class="form" id="signup-form" method="post" action={registerAPI}>
<form class="form" id="signup-form" method="post" action={StudioCMSRoutes.authLinks.registerAPI}>

<Input label={t('username-label')} name="username" type="text" />
<Input label={t('email-label')} name="email" type="email" />
Expand All @@ -64,7 +53,7 @@ if (usernameAndPassword && SHOW_OAUTH) {
)}

{ allowUserRegistration && (
<p slot="footer">{t('allow-login-haveaccount')} <a href={tPath(loginURL)}>{t('allow-login-login')}</a></p>
<p slot="footer">{t('allow-login-haveaccount')} <a href={StudioCMSRoutes.authLinks.loginURL}>{t('allow-login-login')}</a></p>
)}

<StaticAuthCheck server:defer />
Expand Down
2 changes: 1 addition & 1 deletion packages/studiocms_auth/src/utils/routeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const makeDashboardRoute = (route: string, options: StudioCMSAuthOptions)
? removeLeadingTrailingSlashes(dashboardRouteOverride)
: 'dashboard';

return `[...locale]/${defaultDashboardRoute}/${route}`;
return `${defaultDashboardRoute}/${route}`;
};

export const injectAuthAPIRoutes = defineUtility('astro:config:setup')(
Expand Down
19 changes: 12 additions & 7 deletions packages/studiocms_core/src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import type { AstroGlobal } from 'astro';

export { default as LanguageSelector } from './LanguageSelector.astro';

// Note: Translations are not currently used in StudioCMS, so we
// will only allow 'en-us' to be used for now on the Dashboard.

// If you still want to help translate our library while we
// prepare to implement i18n, feel free to add the new translations on
// https://i18n.studiocms.dev/ or PR them into the `translations` folder:
// `packages/studiocms_core/src/i18n/translations/` on https://github.com/withstudiocms/studiocms

// --- i18n Config --- //

// Translations
Expand Down Expand Up @@ -31,12 +39,12 @@ type UiComponentKeys = keyof UiTranslations['en-us']['translations'];
// God please forgive me for what I am about to do
type UiTranslationComponent<
L extends UiLanguageKeys,
T extends UiComponentKeys
> = typeof uiTranslations[L]['translations'][T];
T extends UiComponentKeys,
> = (typeof uiTranslations)[L]['translations'][T];

type UiTranslationKey<
L extends UiLanguageKeys,
T extends UiComponentKeys
T extends UiComponentKeys,
> = keyof UiTranslationComponent<L, T>;

// Default language - Must match one of the keys in the `ui` object above
Expand All @@ -55,10 +63,7 @@ const showDefaultLang: boolean = false;
* @param component - The component key to use for translations.
* @returns A function that takes a translation key and returns the corresponding translated string.
*/
export function useTranslations<
L extends UiLanguageKeys,
T extends UiComponentKeys
>(
export function useTranslations<L extends UiLanguageKeys, T extends UiComponentKeys>(
lang: L,
component: T
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
import { getLangFromUrl, useTranslations } from 'studiocms:i18n';
import { useTranslations } from 'studiocms:i18n';
import DiscordLogo from '@studiocms/assets/svgs/discord.svg?raw';
import { Button } from '@studiocms/ui/components';
import Icon from '@studiocms/ui/utils/Icon.astro';
import UserName from './islands/dashboard/UserName.astro';
const lang = getLangFromUrl(Astro.url);
const lang = 'en-us';
const t = useTranslations(lang, '@studiocms/dashboard:index');
---

Expand Down
Loading

0 comments on commit 1262567

Please sign in to comment.