Skip to content

Commit

Permalink
Merge pull request #4 from helios2003/fix/dynamic-og
Browse files Browse the repository at this point in the history
Testing the Image Generator service on Netlify
  • Loading branch information
helios2003 authored Sep 6, 2024
2 parents 1267586 + a4b3581 commit 9826f88
Show file tree
Hide file tree
Showing 29 changed files with 1,080 additions and 321 deletions.
5 changes: 0 additions & 5 deletions .changeset/few-parrots-shout.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/giant-bulldogs-pretend.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/rare-donuts-vanish.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/silly-jobs-do.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/young-hounds-occur.md

This file was deleted.

49 changes: 19 additions & 30 deletions apps/design-system/src/components/DropdownMenu.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
import { DropdownMenu } from '@asyncapi/studio-ui'
import React from 'react';
import { Meta } from '@storybook/react';
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, DropdownMenuItem, DropdownMenuSeparator } from '@asyncapi/studio-ui'

export default {
const meta: Meta = {
component: DropdownMenu,
parameters: {
layout: 'fullscreen',
backgrounds: {
default: 'dark'
}
},
}
}

const items = [
{
title: 'Import from URL',
onSelect: () => console.log('Import from URL')
},
{
title: 'Import from file',
onSelect: () => console.log('Import from file')
},
{
title: 'Import from Base64',
onSelect: () => console.log('Import from Base64')
},
{
type: 'separator'
},
{
title: 'Generate code/docs',
onSelect: () => console.log('Generate code/docs')
},
]
export default meta


export const Default = {
args: {
trigger: <button className="text-black bg-white rounded mx-3 my-3 px-3">Click me!</button>,
items,
side: 'bottom',
align: 'start'
}
render: () => (<DropdownMenu>
<DropdownMenuTrigger asChild>
<button className="text-black bg-white rounded mx-3 my-3 px-3">Click me!</button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem onSelect={(e) => console.log(e.target)}>Import from URL</DropdownMenuItem>
<DropdownMenuItem onSelect={(e) => console.log(e.target)}>Import from file</DropdownMenuItem>
<DropdownMenuItem onSelect={(e) => console.log(e.target)}>Import from Base64</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onSelect={(e) => console.log(e.target)}>Generate code/docs</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>)
}
36 changes: 28 additions & 8 deletions apps/design-system/src/styles/tailwind.output.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com
! tailwindcss v3.4.3 | MIT License | https://tailwindcss.com
*/

/*
Expand Down Expand Up @@ -32,9 +32,11 @@
4. Use the user's configured `sans` font-family by default.
5. Use the user's configured `sans` font-feature-settings by default.
6. Use the user's configured `sans` font-variation-settings by default.
7. Disable tap highlights on iOS
*/

html {
html,
:host {
line-height: 1.5;
/* 1 */
-webkit-text-size-adjust: 100%;
Expand All @@ -48,6 +50,8 @@ html {
/* 5 */
font-variation-settings: normal;
/* 6 */
-webkit-tap-highlight-color: transparent;
/* 7 */
}

/*
Expand Down Expand Up @@ -119,8 +123,10 @@ strong {
}

/*
1. Use the user's configured `mono` font family by default.
2. Correct the odd `em` font sizing in all browsers.
1. Use the user's configured `mono` font-family by default.
2. Use the user's configured `mono` font-feature-settings by default.
3. Use the user's configured `mono` font-variation-settings by default.
4. Correct the odd `em` font sizing in all browsers.
*/

code,
Expand All @@ -129,8 +135,12 @@ samp,
pre {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
/* 1 */
font-size: 1em;
font-feature-settings: normal;
/* 2 */
font-variation-settings: normal;
/* 3 */
font-size: 1em;
/* 4 */
}

/*
Expand Down Expand Up @@ -199,6 +209,8 @@ textarea {
/* 1 */
line-height: inherit;
/* 1 */
letter-spacing: inherit;
/* 1 */
color: inherit;
/* 1 */
margin: 0;
Expand All @@ -222,9 +234,9 @@ select {
*/

button,
[type='button'],
[type='reset'],
[type='submit'] {
input:where([type='button']),
input:where([type='reset']),
input:where([type='submit']) {
-webkit-appearance: button;
/* 1 */
background-color: transparent;
Expand Down Expand Up @@ -473,6 +485,10 @@ video {
--tw-backdrop-opacity: ;
--tw-backdrop-saturate: ;
--tw-backdrop-sepia: ;
--tw-contain-size: ;
--tw-contain-layout: ;
--tw-contain-paint: ;
--tw-contain-style: ;
}

::backdrop {
Expand Down Expand Up @@ -523,6 +539,10 @@ video {
--tw-backdrop-opacity: ;
--tw-backdrop-saturate: ;
--tw-backdrop-sepia: ;
--tw-contain-size: ;
--tw-contain-layout: ;
--tw-contain-paint: ;
--tw-contain-style: ;
}

.m-3 {
Expand Down
19 changes: 19 additions & 0 deletions apps/studio-next/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# studio-next

## 0.1.3

### Patch Changes

- 943fec1: fix: report correct `range` values in error diagnostics for YAML files

## 0.1.2

### Patch Changes

- c3248c8: fix: fix the validation error for payload of type `date` (https://github.com/asyncapi/parser-js/issues/980)

## 0.1.1

### Patch Changes

- a4b7fd1: Use Next.js framework
27 changes: 15 additions & 12 deletions apps/studio-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "studio-next",
"version": "0.1.0",
"version": "0.1.3",
"private": true,
"scripts": {
"dev": "next dev -p 3001",
Expand All @@ -12,35 +12,38 @@
"@asyncapi/avro-schema-parser": "^3.0.19",
"@asyncapi/converter": "^1.4.16",
"@asyncapi/openapi-schema-parser": "^3.0.18",
"@asyncapi/parser": "^3.0.11",
"@asyncapi/parser": "^3.2.2",
"@asyncapi/protobuf-schema-parser": "^3.2.8",
"@asyncapi/react-component": "^1.2.2",
"@asyncapi/specs": "^6.5.4",
"@codemirror/view": "^6.26.3",
"@ebay/nice-modal-react": "^1.2.10",
"@headlessui/react": "^1.7.4",
"@hookstate/core": "^4.0.0-rc21",
"@monaco-editor/react": "^4.4.6",
"@tippyjs/react": "^4.2.6",
"js-base64": "^3.7.3",
"js-file-download": "^0.4.12",
"js-yaml": "^4.1.0",
"monaco-editor": "0.34.1",
"monaco-yaml": "4.0.2",
"react-hot-toast": "2.4.0",
"react-icons": "^4.6.0",
"reactflow": "^11.2.0",
"@stoplight/yaml": "^4.3.0",
"@codemirror/view": "^6.26.3",
"@tippyjs/react": "^4.2.6",
"@types/node": "20.4.6",
"@types/react": "18.2.18",
"@types/react-dom": "18.2.7",
"autoprefixer": "10.4.14",
"axios": "^1.7.3",
"codemirror": "^6.0.1",
"crawler-user-agents": "^1.0.142",
"eslint-config-next": "13.4.12",
"js-base64": "^3.7.3",
"js-file-download": "^0.4.12",
"js-yaml": "^4.1.0",
"monaco-editor": "0.34.1",
"monaco-yaml": "4.0.2",
"next": "14.2.3",
"postcss": "8.4.31",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hot-toast": "2.4.0",
"react-icons": "^4.6.0",
"reactflow": "^11.2.0",
"sharp": "^0.33.5",
"tailwindcss": "3.3.3",
"tippy.js": "^6.3.7",
"typescript": "5.1.6",
Expand Down
104 changes: 104 additions & 0 deletions apps/studio-next/src/app/api/crawler/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { NextRequest, NextResponse } from "next/server";
import parseURL from "@/helpers/parser";
import { DocumentInfo } from "@/types";
import axios from "axios";
import { metadata } from "@/app/page";

export async function GET(request: NextRequest) {
const Base64searchParams = request.nextUrl.searchParams.get('base64');
const URLsearchParams = request.nextUrl.searchParams.get('url');

try {
if (!Base64searchParams && !URLsearchParams) return new NextResponse(null, { status: 200 });
let info: DocumentInfo | null = null;

if (Base64searchParams) {
// directly run the parsing function
info = await parseURL(Base64searchParams);
}
if (URLsearchParams) {
// fetch the document information from the URL
try {
const response = await axios.get(URLsearchParams);
if (response.status === 200) {
info = await parseURL(response.data);
} else {
return new NextResponse("Not a valid URL", { status: 500 });
}
} catch (error) {
return new NextResponse("Not a valid URL", { status: 500 });
}
}

if (!info) {
const ogImage = "https://raw.githubusercontent.com/asyncapi/studio/master/apps/studio-next/public/img/meta-studio-og-image.jpeg";

const crawlerInfo = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>"${metadata.openGraph?.title}"</title>
<meta property="og:title" content="${metadata.openGraph?.title}" />
<meta property="og:description" content="${metadata.openGraph?.description}" />
<meta property="og:url" content="${metadata.openGraph?.url}" />
<meta property="og:image" content="${ogImage}" />
`
return new NextResponse(crawlerInfo, {
headers: {
'Content-Type': 'text/html',
},
})
}

let ogImageParams = new URLSearchParams();

if (info.title) {
ogImageParams.append('title', info.title.toString());
}
if (info.description) {
ogImageParams.append('description', info.description.toString());
}
if (info.numServers) {
ogImageParams.append('numServers', info.numServers.toString());
}
if (info.numChannels) {
ogImageParams.append('numChannels', info.numChannels.toString());
}
if (info.numOperations) {
ogImageParams.append('numOperations', info.numOperations.toString());
}
if (info.numMessages) {
ogImageParams.append('numMessages', info.numMessages.toString());
}

const ogImageurl = `https://ogp-studio.vercel.app/api/og?${ogImageParams.toString()}`;

const crawlerInfo = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${info.title}</title>
${info.title ? `<meta property="og:title" content="${info.title}" />` : ''}
${info.description ? `<meta property="og:description" content="${info.description}" />` : ''}
<meta property="og:image" content=${ogImageurl} />
</head>
</html>
`;
console.log(crawlerInfo);
return new NextResponse(crawlerInfo, {
status: 200,
headers: {
'Content-Type': 'text/html',
},
});
} catch (err) {
return new NextResponse("Not a valid URL", { status: 500 });
}
}

Loading

0 comments on commit 9826f88

Please sign in to comment.