Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs-infra] Use edge function for card generation #41188

Merged
merged 34 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e11d71a
Make edge function work
alexfauquette Feb 19, 2024
7012f88
blog template
alexfauquette Feb 23, 2024
e2785b6
git api url
alexfauquette Feb 23, 2024
c437d42
test
alexfauquette Feb 27, 2024
4f341fd
fix
alexfauquette Feb 27, 2024
017c373
update
alexfauquette Feb 27, 2024
99d4b20
Merge remote-tracking branch 'upstream/master' into og-image
alexfauquette Feb 28, 2024
658d968
add small design tweaks
danilo-leal Mar 5, 2024
7901c63
tweak scope identifier text element
danilo-leal Mar 5, 2024
ae78278
Merge remote-tracking branch 'upstream/master' into og-image
alexfauquette Mar 6, 2024
b44ce6f
Merge branch 'og-image' of github.com:alexfauquette/material-ui into …
alexfauquette Mar 6, 2024
91b25a1
feedbacks
alexfauquette Mar 6, 2024
f5bdae3
fix
alexfauquette Mar 6, 2024
5f5e342
lint fix
alexfauquette Mar 6, 2024
14c47c0
fix missing product
alexfauquette Mar 11, 2024
fcbcfa0
add cache
alexfauquette Mar 11, 2024
04ea208
feedbacks
alexfauquette Mar 22, 2024
9d00180
small feedback
alexfauquette Mar 22, 2024
b4e1a65
Merge remote-tracking branch 'upstream/master' into og-image
alexfauquette Mar 22, 2024
fb84396
remove debug
alexfauquette Mar 22, 2024
8fcc08e
Fix typo
oliviertassinari Mar 26, 2024
1629679
move headers to manual card
alexfauquette Mar 29, 2024
ab4d35d
always use large card for blog post
alexfauquette Mar 29, 2024
d0203cc
Add description
alexfauquette Mar 29, 2024
bdc0b9a
Merge branch 'og-image' of github.com:alexfauquette/material-ui into …
alexfauquette Mar 29, 2024
4b2f937
add IBM font
alexfauquette Mar 29, 2024
269a340
Merge remote-tracking branch 'upstream/master' into og-image
alexfauquette Mar 29, 2024
b20e681
Update netlify/edge-functions/og-image.tsx
alexfauquette Apr 2, 2024
50f3802
modify font-size
alexfauquette Apr 3, 2024
44b92b8
refine the card generation docs
alexfauquette Apr 3, 2024
c6c0c6e
fix typos
alexfauquette Apr 3, 2024
32caa7f
add in the nav bar
alexfauquette Apr 3, 2024
0e9d920
tweak documentation
danilo-leal Apr 3, 2024
a570b9a
fine-tune the OG card design
danilo-leal Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/pages/experiments/blog/blog-custom-card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
import TopLayoutBlog from 'docs/src/modules/components/TopLayoutBlog';
import { docs } from './blog-custom-card.md?@mui/markdown';

export default function Page() {
return <TopLayoutBlog docs={docs} />;
}
30 changes: 30 additions & 0 deletions docs/pages/experiments/blog/blog-custom-card.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Blog post title
description: Our internationally distributed startup gathered on a remote island to get to know each other better. Here's what happened!
date: 2022-07-28T00:00:00.000Z
authors: ['alexfauquette']
tags: ['Company']
card: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this? It would make sense for me to not throw is cardTitle is defined to take over.

Suggested change
card: false

I would also rename the other pages that use this so it's clear, something like this

Suggested change
card: false
manualCard: true

cardTitle: blog with\n*custom* card
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart

---

## Description

### Image

<img alt="Satellite image of Tenerife" src="/static/blog/2022-tenerife-retreat/tenerife.jpeg" width="2560" height="1920" loading="lazy" />
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

<p class="blog-description">An image description <a href="https://en.wikipedia.org/wiki/Tenerife">with a link</a>.</p>

More text below.

### Code

```jsx
// add margin: 8px 0px;
<Slider sx={{ my: 1 }} />
```

<p class="blog-description"><a href="https://codesandbox.io/p/sandbox/nostalgic-williams-zmo5r?file=/src/App.js">CodeSandbox</a></p>

More text below.
6 changes: 5 additions & 1 deletion docs/src/modules/components/AppLayoutDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,27 @@ export default function AppLayoutDocs(props) {

const { canonicalAs } = pathnameToLanguage(router.asPath);
let productName = 'MUI';
let teamName = 'Core';
if (canonicalAs.startsWith('/material-ui/')) {
productName = 'Material UI';
} else if (canonicalAs.startsWith('/base-ui/')) {
productName = 'Base UI';
} else if (canonicalAs.startsWith('/x/')) {
productName = 'MUI X';
teamName = 'X';
} else if (canonicalAs.startsWith('/system/')) {
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
productName = 'MUI System';
} else if (canonicalAs.startsWith('/toolpad/')) {
productName = 'MUI Toolpad';
teamName = 'Toolpad';
} else if (canonicalAs.startsWith('/joy-ui/')) {
productName = 'Joy UI';
}

const Layout = disableLayout ? React.Fragment : AppFrame;
const layoutProps = disableLayout ? {} : { BannerComponent };

const card = `https://deploy-preview-41188--material-ui-apps.netlify.app/og-docs?product=${teamName}&folder=${productName}&page=${title}`;
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
return (
<Layout {...layoutProps}>
<GlobalStyles
Expand All @@ -151,7 +155,7 @@ export default function AppLayoutDocs(props) {
title={`${title} - ${productName}`}
description={description}
largeCard={false}
card="https://mui.com/static/logo.png"
card={card}
/>
<Main disableToc={disableToc}>
{/*
Expand Down
1 change: 1 addition & 0 deletions docs/src/modules/components/Head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRouter } from 'next/router';
import { LANGUAGES_SSR } from 'docs/config';
import { useUserLanguage, useTranslate } from 'docs/src/modules/utils/i18n';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import getProductInfoFromUrl from '../utils/getProductInfoFromUrl';

// #major-version-switch
const HOST = 'https://mui.com';
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/TopLayoutBlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default function TopLayoutBlog(props) {
const card =
headers.card === 'true'
? `https://mui.com/static/blog/${slug}/card.png`
: 'https://mui.com/static/logo.png';
: `https://deploy-preview-41188--material-ui-apps.netlify.app/og-blog/?title=${headers.cardTitle || finalTitle}&authors=${headers.authors.join(',')}`;

if (process.env.NODE_ENV !== 'production') {
if (headers.card === undefined) {
Expand Down
134 changes: 134 additions & 0 deletions netlify/edge-functions/docs-image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import React from 'https://esm.sh/react@18.2.0';
import { ImageResponse } from 'https://deno.land/x/og_edge/mod.ts';

export default async function handler(req: Request) {
const params = new URL(req.url).searchParams;

const product = params.get('product');
const folder = params.get('folder');
const page = params.get('page');

return new ImageResponse(
(
<div
style={{
width: 1280,
height: 640,
background: 'linear-gradient(180deg, #FFFFFF 0%, #F0F7FF 75.52%)',
overflow: 'hidden',
position: 'relative',
display: 'flex',
}}
>
<div
style={{
height: 40,
position: 'absolute',
left: 100,
top: 100,
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}}
>
<svg
width="43.75"
height="40"
viewBox="0 0 36 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M30.3428 21.9762C30.6524 21.7985 30.8437 21.4692 30.8448 21.1122L30.8632 15.3247C30.8643 14.9678 31.0556 14.6385 31.365 14.4607L34.5019 12.6587C35.1685 12.2757 36 12.7569 36 13.5258V24.0472C36 24.4052 35.8086 24.736 35.4981 24.9143L23.659 31.7145C23.3512 31.8913 22.9726 31.8917 22.6645 31.7154L13.3735 26.401C13.0621 26.2229 12.87 25.8917 12.87 25.533V20.2283C12.87 20.2219 12.8769 20.2179 12.8825 20.221C12.8881 20.2241 12.895 20.2201 12.895 20.2137V20.2078C12.895 20.2036 12.8973 20.1997 12.9009 20.1976L20.5527 15.8015C20.5596 15.7976 20.5568 15.787 20.5488 15.787C20.5445 15.787 20.541 15.7835 20.541 15.7792L20.556 10.578C20.5582 9.80731 19.7246 9.32389 19.0568 9.70861L13.3692 12.9854C13.0602 13.1634 12.6798 13.1634 12.3708 12.9854L6.66621 9.69876C5.99955 9.31466 5.167 9.79584 5.167 10.5652V19.9657C5.167 20.7335 4.33746 21.2149 3.67081 20.8339L0.504798 19.0245C0.192724 18.8461 0.000379125 18.514 0.000993035 18.1546L0.0290552 1.72421C0.0303669 0.956158 0.86112 0.476237 1.52713 0.858783L12.3719 7.08791C12.6803 7.26507 13.0597 7.26507 13.3681 7.08791L24.2099 0.860475C24.8766 0.477551 25.708 0.958799 25.708 1.72761V18.1619C25.708 18.5196 25.517 18.85 25.207 19.0285L19.5286 22.2984C18.8587 22.6842 18.8611 23.6516 19.5329 24.0341L22.6651 25.8171C22.973 25.9924 23.3506 25.9917 23.6578 25.8153L30.3428 21.9762ZM31 7.23381C31 8.0111 31.848 8.49122 32.5145 8.0913L35.5145 6.2913C35.8157 6.11058 36 5.78507 36 5.43381V1.76619C36 0.988896 35.152 0.508783 34.4855 0.908698L31.4855 2.7087C31.1843 2.88942 31 3.21493 31 3.56619V7.23381Z"
fill="#007FFF"
/>
</svg>
<div
style={{
height: 40,
width: 2,
backgroundColor: '#DAE2ED',
margin: '0 24px',
}}
/>
<p
style={{
fontFamily: 'General Sans',
fontSize: '20px',
fontWeight: 700,
lineHeight: '36px',
letterSpacing: '0.14em',
color: '#007FFF',
}}
>
{product}
</p>
</div>
<div
style={{
fontFamily: 'General Sans',
fontStyle: 'normal',
fontWeight: 600,
fontSize: '68px',
lineHeight: '82px',
color: '#0B0D0E',
marginLeft: 100,
marginRight: 100,
marginTop: 300,
width: '100%',
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-start',
}}
>
<div style={{ width: '100%', textAlign: 'center', color: '#007FFF' }}>{folder}</div>
<div
style={{
width: '100%',
textAlign: 'center',

fontFamily: 'General Sans',
fontStyle: 'normal',
fontWeight: 500,
}}
>
{page}
</div>
</div>
</div>
),
{
width: 1280,
height: 640,
fonts: [
{
name: 'General Sans',
data: await fetch('https://fonts.cdnfonts.com/s/85793/GeneralSans-Medium.woff').then(
(a) => a.arrayBuffer(),
),
weight: 1000,
style: 'normal',
},
{
name: 'General Sans',
data: await fetch('https://fonts.cdnfonts.com/s/85793/GeneralSans-Semibold.woff').then(
(a) => a.arrayBuffer(),
),
weight: 600,
style: 'normal',
},
{
name: 'General Sans',
data: await fetch('https://fonts.cdnfonts.com/s/85793/GeneralSans-Bold.woff').then((a) =>
a.arrayBuffer(),
),
weight: 700,
style: 'normal',
},
],
},
);
}
export const config = { path: '/og-docs' };
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading