-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
* feat: add LibraryPreview component * feat: pass props to Meta component * feat: add LibraryPreviewPage * feat: add update-og-images script * feat: temporary disable og:image override
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {PutObjectCommand, S3} from '@aws-sdk/client-s3'; | ||
import * as dotenv from 'dotenv'; | ||
import {chromium} from 'playwright'; | ||
|
||
import {libs} from '../src/libs.mjs'; | ||
|
||
dotenv.config(); | ||
|
||
const s3Client = new S3({ | ||
endpoint: 'https://storage.yandexcloud.net/', | ||
credentials: { | ||
accessKeyId: process.env.S3_ACCESS_KEY_ID, | ||
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY, | ||
}, | ||
region: 'ru-central1-a', | ||
}); | ||
|
||
const BUCKET_NAME = 'gravity-assets'; | ||
|
||
try { | ||
const browser = await chromium.launch(); | ||
const context = await browser.newContext({ | ||
viewport: {width: 1200, height: 630}, | ||
}); | ||
const page = await context.newPage(); | ||
|
||
for (let i = 0; i < libs.length; i++) { | ||
const {id} = libs[i]; | ||
await page.goto(`https://gravity-ui.com/libraries/${id}/preview`, { | ||
waitUntil: 'networkidle', | ||
}); | ||
const buffer = await page.screenshot(); | ||
|
||
const uploadParams = { | ||
Bucket: BUCKET_NAME, | ||
Key: `og/${id}.jpg`, | ||
ContentType: 'image/jpeg', | ||
Body: buffer, | ||
}; | ||
|
||
try { | ||
await s3Client.send(new PutObjectCommand(uploadParams)); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
|
||
await browser.close(); | ||
} catch (err) { | ||
console.error(err); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import {PageConstructorProvider, Theme} from '@gravity-ui/page-constructor'; | ||
import {GetStaticPaths, GetStaticPathsResult, GetStaticProps} from 'next'; | ||
import Head from 'next/head'; | ||
import React from 'react'; | ||
import {useLocaleRedirect} from 'src/hooks/useLocaleRedirect'; | ||
|
||
import {LibraryPreview} from '../../../../components/LibraryPreview/LibraryPreview'; | ||
import {getI18nPaths, getI18nProps, getLibsList} from '../../../../utils'; | ||
|
||
const theme = Theme.Dark; | ||
|
||
const libs = getLibsList(); | ||
|
||
export const getStaticPaths: GetStaticPaths = async () => { | ||
const paths = getI18nPaths().reduce<GetStaticPathsResult['paths']>((acc, localeItem) => { | ||
acc.push( | ||
...libs.map((libItem) => ({ | ||
params: {locale: localeItem.params.locale, libId: libItem.config.id}, | ||
})), | ||
); | ||
return acc; | ||
}, []); | ||
|
||
return { | ||
paths, | ||
fallback: false, | ||
}; | ||
}; | ||
|
||
export const getStaticProps: GetStaticProps = async (context) => { | ||
return { | ||
props: { | ||
id: context.params?.libId, | ||
...(await getI18nProps(context, ['library', 'libraries-info'])), | ||
}, | ||
}; | ||
}; | ||
|
||
export const LibraryPreviewPage = ({id}: {id: string}) => { | ||
const lib = libs.find((item) => item.config.id === id)!; | ||
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / Verify Files
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
Check warning on line 40 in src/[locale]/libraries/[libId]/preview/index.tsx GitHub Actions / deploy (18.x)
|
||
useLocaleRedirect(); | ||
|
||
return ( | ||
<React.Fragment> | ||
<Head> | ||
<title>{lib?.config.title ?? ''} — og:image</title> | ||
</Head> | ||
<PageConstructorProvider theme={theme}> | ||
<LibraryPreview lib={lib} /> | ||
</PageConstructorProvider> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export default LibraryPreviewPage; |