Skip to content

Commit

Permalink
Update website
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Nov 11, 2023
1 parent a5f534e commit f03f736
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
5 changes: 5 additions & 0 deletions website/app/[locale]/(root)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Locale } from 'websites/i18n.config'
import RootLayout from '../root.layout'
import i18n from 'websites/i18n.config.mjs';

export async function generateStaticParams() {
return i18n.locales.map((locale: any) => ({ locale }));
}

export default async function Layout(props: {
children: JSX.Element,
Expand Down
5 changes: 0 additions & 5 deletions website/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Viewport } from 'next';
import i18n from 'websites/i18n.config.mjs'

export const metadata = {
metadataBase: new URL(process.env.HOST as string),
Expand All @@ -17,10 +16,6 @@ export const viewport: Viewport = {
userScalable: true
}

export async function generateStaticParams() {
return i18n.locales.map((locale: any) => ({ locale }));
}

export default async function RootLayout({
children
}: {
Expand Down
12 changes: 2 additions & 10 deletions website/app/[locale]/play/Play.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import cloneDeep from 'clone-deep'
import { Logotype } from '~/components/Logotype';
import Header, { HeaderNav } from 'websites/components/Header'
import links from '~/links.mjs'
import dynamic from 'next/dynamic'
import i18n from 'websites/i18n.config.mjs'
import { mediaQueries } from '@master/css'
import config from '~/master.css'
Expand Down Expand Up @@ -87,20 +86,14 @@ export default function Play(props: any) {
const monacoRef = useRef<Monaco | null>(null)
const previewIframeRef = useRef<HTMLIFrameElement>(null)
const prevVersionRef = useRef(props.shareItem?.version ?? latestMasterCSSVersion)
const [layout, setLayout] = useState<string | null>(searchParams.get('layout'))
const [preview, setPreview] = useState<string | null>(searchParams.get('preview'))
const [layout, setLayout] = useState<string | null>(props.searchParams?.layout || searchParams.get('layout'))
const [preview, setPreview] = useState<string | null>(props.searchParams?.preview || searchParams.get('preview'))
const [shareId, setShareId] = useState(props.shareId ?? '')
const [sharing, setSharing] = useState(false)
const [version, setVersion] = useState(props.shareItem?.version ?? latestMasterCSSVersion)
const [generatedCSSText, setGeneratedCSSText] = useState('')
const template = useMemo(() => templates.find((eachTemplate) => eachTemplate.version === version), [version])
const [previewErrorEvent, setPreviewErrorEvent] = useState<any>()

useEffect(() => {
setLayout(searchParams.get('layout'))
setPreview(searchParams.get('preview'))
}, [searchParams, setLayout, setPreview]); // 空的依赖数组确保只在初始渲染时执行

const shareItem: PlayShare = useMemo(() => {
if (props.shareItem && props.shareItem.version === version) {
props.shareItem.files
Expand Down Expand Up @@ -575,7 +568,6 @@ export default function Play(props: any) {

const width = useMemo(() => (!layout || layout === '2') ? '50%' : '100%', [layout])
const height = useMemo(() => (!layout || layout === '2') ? '100%' : '50%', [layout])

return (
<div className="abs flex full flex:col">
<Header fixed={false} Logotype={Logotype}>
Expand Down
7 changes: 5 additions & 2 deletions website/app/[locale]/play/[shareId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { initializeFirestore } from 'firebase-admin/firestore'
import { notFound } from "next/navigation"
import { collectDictionary } from 'websites/dictionaries'

export const revalidate = 99999999999999

export default async function Page(props: any) {
const store = initializeFirestore(app)
const { shareId, locale } = props.params
const { shareId, locale, searchParams } = props.params
if (!shareId) {
notFound()
}
Expand All @@ -19,7 +21,8 @@ export default async function Page(props: any) {
<Play shareItem={shareItem}
shareId={shareId}
locale={locale}
dict={await collectDictionary(locale, ['Docs', 'Play', 'Updates', 'Components', 'Sharing ...', 'Share'])}
searchParams={searchParams}
dict={await collectDictionary(locale, ['Docs', 'Play', 'Roadmap', 'Blog', 'Components', 'Sharing ...', 'Share'])}
/>
)
} else {
Expand Down
23 changes: 20 additions & 3 deletions website/redirects.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import i18n from 'websites/i18n.config.mjs'

const redirects = [
{ source: `/${i18n.defaultLocale}/:path((?!.*opengraph-image).*)`, destination: "/:path*", permanent: true },
const i18nRedirects = [
{ source: "/docs", destination: "/docs/installation", permanent: false },
{ source: "/sandbox", destination: "/play", permanent: false },
{ source: "/sandbox/:path*", destination: "/play/:path*", permanent: false },
{ source: "/docs/guides", destination: "/docs/installation", permanent: false },
{ source: "/docs/language-service", destination: "/docs/language-service/vscode", permanent: false },
];
]
.map((eachRedirect) => {
return i18n.locales
.filter((locale) => locale !== 'en')
.map((locale) => {
return {
...eachRedirect,
source: `/${locale}${eachRedirect.source}`,
destination: `/${locale}${eachRedirect.destination}`,
}
})
.flat()
})
.flat()

const redirects = [
{ source: `/${i18n.defaultLocale}/:path((?!.*opengraph-image).*)`, destination: "/:path*", permanent: true },
...i18nRedirects
]

export default redirects

0 comments on commit f03f736

Please sign in to comment.