Skip to content

Commit

Permalink
fix: fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
charIeszhao committed Jan 20, 2025
1 parent c3057a8 commit 92babfe
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 67 deletions.
4 changes: 2 additions & 2 deletions i18n/de/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@
"message": "Datenschutz"
},
"theme.common.sdk.placeholder": {
"message": "Ihr SDK"
"message": "dein SDK"
},
"theme.common.connector.placeholder": {
"message": "Ihr Anbieter"
"message": "dein anbieter"
},
"theme.common.sdk.native": {
"message": "Nativ"
Expand Down
4 changes: 2 additions & 2 deletions i18n/es/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@
"message": "Privacidad"
},
"theme.common.sdk.placeholder": {
"message": "Tu SDK"
"message": "tu SDK"
},
"theme.common.connector.placeholder": {
"message": "Tu proveedor"
"message": "tu proveedor"
},
"theme.common.sdk.native": {
"message": "Nativo"
Expand Down
4 changes: 2 additions & 2 deletions i18n/fr/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@
"message": "Confidentialité"
},
"theme.common.sdk.placeholder": {
"message": "Votre SDK"
"message": "ton SDK"
},
"theme.common.connector.placeholder": {
"message": "Votre fournisseur"
"message": "ton fournisseur"
},
"theme.common.sdk.native": {
"message": "Natif"
Expand Down
4 changes: 2 additions & 2 deletions i18n/pt-BR/code.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@
"message": "Privacidade"
},
"theme.common.sdk.placeholder": {
"message": "Seu SDK"
"message": "seu SDK"
},
"theme.common.connector.placeholder": {
"message": "Seu provedor"
"message": "seu provedor"
},
"theme.common.sdk.native": {
"message": "Nativo"
Expand Down
24 changes: 14 additions & 10 deletions src/hooks/use-categorized-tutorial-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type DocMetadata } from '@docusaurus/plugin-content-docs';
import { useMemo } from 'react';

import metadata from '@site/tutorial/build-with-logto/metadata.json';

Expand Down Expand Up @@ -47,16 +48,19 @@ const useCategorizedTutorialMetadata = () => {
{ nativeSdks: [], traditionalSdks: [], spaSdks: [] }
);

return {
allSdks: sdks,
allConnectors: [...socialConnectors, ...emailConnectors, ...smsConnectors],
nativeSdks,
traditionalSdks,
spaSdks,
socialConnectors,
emailConnectors,
smsConnectors,
};
return useMemo(
() => ({
allSdks: sdks,
allConnectors: [...socialConnectors, ...emailConnectors, ...smsConnectors],
nativeSdks,
traditionalSdks,
spaSdks,
socialConnectors,
emailConnectors,
smsConnectors,
}),
[sdks, socialConnectors, emailConnectors, smsConnectors, nativeSdks, traditionalSdks, spaSdks]
);
};

export default useCategorizedTutorialMetadata;
1 change: 1 addition & 0 deletions src/theme/BlogLayout/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
flex-direction: column;
gap: 24px;
overflow: hidden;
margin-bottom: 50px;
}

.toc {
Expand Down
14 changes: 9 additions & 5 deletions src/theme/BlogPostItem/Header/Info/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,29 @@ function Spacer() {
return <>{' · '}</>;
}

export default function BlogPostItemHeaderInfo({ className }: Props): JSX.Element {
export default function BlogPostItemHeaderInfo({ className }: Props) {
const { metadata } = useBlogPost();
const { date, readingTime } = metadata;

// Charles edited this to remove the time from generated "Build X with Y tutorials"
const isTutorial = metadata.frontMatter.slug?.startsWith('how-to-build-');

const dateTimeFormat = useDateTimeFormat({
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'UTC',
});

// Charles edited this to remove the time from generated "Build X with Y tutorials"
const isTutorial = metadata.frontMatter.slug?.startsWith('how-to-build-');

if (isTutorial) {
return null;
}

const formatDate = (blogDate: string) => dateTimeFormat.format(new Date(blogDate));

return (
<div className={clsx(styles.container, 'margin-vert--md', className)}>
{!isTutorial && <DateTime date={date} formattedDate={formatDate(date)} />}
<DateTime date={date} formattedDate={formatDate(date)} />
{readingTime !== undefined && (
<>
<Spacer />
Expand Down
7 changes: 6 additions & 1 deletion src/theme/BlogPostItem/Header/Title/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Props } from '@theme/BlogPostItem/Header/Title';
import { clsx } from 'clsx';
import { useCallback, useEffect } from 'react';

import TitleWithHighlights from '../TitleWithHighlights';
import TitleWithSelectionDropdown from '../TitleWithSelectionDropdown';

import styles from './styles.module.css';
Expand Down Expand Up @@ -71,7 +72,11 @@ const Content = ({ className }: Props): JSX.Element => {
className={clsx(styles.title, !isBlogPostPage && styles.listTitle, className)}
itemProp="headline"
>
{isBlogPostPage ? <TitleWithSelectionDropdown title={title} metadata={metadata} /> : title}
{isBlogPostPage ? (
<TitleWithSelectionDropdown metadata={metadata} />
) : (
<TitleWithHighlights metadata={metadata} />
)}
</TitleHeading>
</>
);
Expand Down
15 changes: 1 addition & 14 deletions src/theme/BlogPostItem/Header/Title/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,5 @@
font: var(--font-body-0);
font-weight: 500;
margin: 0;
}

.highlight {
color: var(--logto-link-color);
}

/**
Blog post title should be smaller on smaller devices
**/
@media (max-width: 576px) {
.listTitle {
font-size: 1.5rem;
line-height: 40px;
}
color: var(--logto-color-text);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.highlight {
color: var(--logto-link-color);
}
44 changes: 44 additions & 0 deletions src/theme/BlogPostItem/Header/TitleWithHighlights/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { type PropBlogPostMetadata } from '@docusaurus/plugin-content-blog';
import { condString } from '@silverhand/essentials';

import styles from './index.module.scss';

type Props = {
readonly metadata: PropBlogPostMetadata;
};

/**
* Escape potential parentheses in the SDK / connector name.
* The result will be used for the regex that splits the title into parts.
*/
const normalizeName = (name: string) => name.replaceAll('(', '\\(').replaceAll(')', '\\)');

const TitleWithHighlights = ({ metadata }: Props) => {
const { frontMatter, title } = metadata;
const sdkName = condString('sdk' in frontMatter && frontMatter.sdk);
const connectorName = condString('connector' in frontMatter && frontMatter.connector);

const titleParts = title
.split(new RegExp(`(${normalizeName(connectorName)}|${normalizeName(sdkName)})`, 'g'))
.filter(Boolean);

return titleParts.map((part) => {
if (part === sdkName) {
return (
<span key={`${frontMatter.slug}-${sdkName}`} className={styles.highlight}>
{part}
</span>
);
}
if (part === connectorName) {
return (
<span key={`${frontMatter.slug}-${connectorName}`} className={styles.highlight}>
{part}
</span>
);
}
return part;
});
};

export default TitleWithHighlights;
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,3 @@
user-select: none;
}
}

/* Hide dropdown anchors from title on smaller devices */
@media (max-width: 576px) {
.dropdownAnchor {
padding: 0;
outline: none;
cursor: default;

&::after {
display: none;
}

&.active {
outline: none;
}
}
}
29 changes: 20 additions & 9 deletions src/theme/BlogPostItem/Header/TitleWithSelectionDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Dropdown from '../SelectionDropdown';
import styles from './index.module.scss';

type BlogPostProps = {
readonly title: string;
readonly metadata: PropBlogPostMetadata;
};

Expand Down Expand Up @@ -53,7 +52,7 @@ const normalizeName = (name: string) =>
name.replaceAll('(', '\\(').replaceAll(')', '\\)').replaceAll('$', '\\$');

const TitleWithSelectionDropdown = (props: Props) => {
const isBlogPost = 'title' in props;
const isBlogPost = 'metadata' in props;
const { onSelectSdk, onSelectConnector } = props;
const listViewProps = conditional(!isBlogPost && props);
const blogPostProps = conditional(isBlogPost && props);
Expand Down Expand Up @@ -90,7 +89,7 @@ const TitleWithSelectionDropdown = (props: Props) => {
: getConnectorDisplayName(defaultConnector);

if (blogPostProps && (!sdkName || !connectorName)) {
return blogPostProps.title;
return blogPostProps.metadata.title;
}

const listViewTitle = translate({
Expand All @@ -100,12 +99,12 @@ const TitleWithSelectionDropdown = (props: Props) => {
.replace(sdkTemplateSlot, sdkName || sdkTemplateSlot)
.replace(connectorTemplateSlot, connectorName || connectorTemplateSlot);

const normalizedTitle = blogPostProps?.title ?? listViewTitle;
const normalizedTitle = blogPostProps?.metadata.title ?? listViewTitle;

const titleParts = normalizedTitle
.split(
new RegExp(
`(${normalizeName(sdkName || sdkTemplateSlot)}|${normalizeName(connectorName || connectorTemplateSlot)})`,
`(${normalizeName(connectorName || connectorTemplateSlot)}|${normalizeName(sdkName || sdkTemplateSlot)})`,
'g'
)
)
Expand Down Expand Up @@ -166,7 +165,7 @@ const TitleWithSelectionDropdown = (props: Props) => {
>
{part === sdkTemplateSlot ? (
<span className={styles.placeholder}>
<Translate id="theme.common.sdk.placeholder">Your SDK</Translate>
<Translate id="theme.common.sdk.placeholder">your SDK</Translate>
</span>
) : (
part
Expand Down Expand Up @@ -194,7 +193,7 @@ const TitleWithSelectionDropdown = (props: Props) => {
>
{part === connectorTemplateSlot ? (
<span className={styles.placeholder}>
<Translate id="theme.common.connector.placeholder">Your provider</Translate>
<Translate id="theme.common.connector.placeholder">your provider</Translate>
</span>
) : (
part
Expand All @@ -221,7 +220,13 @@ const TitleWithSelectionDropdown = (props: Props) => {
onClose={() => {
setIsDropdownOpen(undefined);
}}
onReset={cond(!isBlogPost && onSelectSdk)}
onReset={cond(
!isBlogPost &&
(() => {
onSelectSdk?.(undefined);
setIsDropdownOpen(undefined);
})
)}
/>
<Dropdown
anchorRef={connectorNameRef}
Expand All @@ -240,7 +245,13 @@ const TitleWithSelectionDropdown = (props: Props) => {
onClose={() => {
setIsDropdownOpen(undefined);
}}
onReset={cond(!isBlogPost && onSelectConnector)}
onReset={cond(
!isBlogPost &&
(() => {
onSelectConnector?.(undefined);
setIsDropdownOpen(undefined);
})
)}
/>
</>
);
Expand Down
28 changes: 27 additions & 1 deletion src/theme/BlogPostItem/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,31 @@
border-radius: 12px;
box-shadow: var(--logto-shadow-1);
padding: 20px;
width: 100%;
width: 100%;
transition: background-color var(--ifm-transition-fast) ease;

&:hover {
background-color: var(--logto-container-info-bg);
}
}

.logo {
display: flex;
align-items: center;
justify-content: center;
width: 60px;
height: 60px;
margin-inline-end: 12px;
border-radius: 10px;
background: var(--logto-container-neutral-bg);
flex-shrink: 0;

img {
width: 36px;
height: 36px;
}

+ .logo {
margin-inline-end: 28px;
}
}
Loading

0 comments on commit 92babfe

Please sign in to comment.