From dab32138b7271aecbb61e44ce0f695c29193f16d Mon Sep 17 00:00:00 2001 From: Niko Sams Date: Tue, 14 Jan 2025 15:03:43 +0100 Subject: [PATCH 1/3] Demo Site: don't exclude middleware for /api/... requests (#3086) --- demo/admin/src/App.tsx | 2 +- demo/site/src/app/{ => [domain]}/api/status/route.tsx | 0 demo/site/src/app/{api => }/site-preview/route.ts | 0 demo/site/src/middleware.ts | 7 +++---- demo/site/src/middleware/{blockPreview.ts => preview.ts} | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) rename demo/site/src/app/{ => [domain]}/api/status/route.tsx (100%) rename demo/site/src/app/{api => }/site-preview/route.ts (100%) rename demo/site/src/middleware/{blockPreview.ts => preview.ts} (72%) diff --git a/demo/admin/src/App.tsx b/demo/admin/src/App.tsx index ef14c34dc8..ecca497406 100644 --- a/demo/admin/src/App.tsx +++ b/demo/admin/src/App.tsx @@ -68,7 +68,7 @@ export function App() { siteConfig.scope.domain === "secondary" ? `${siteConfig.url}/block-preview` : `${siteConfig.url}/block-preview/${scope.domain}/${scope.language}`, - sitePreviewApiUrl: `${siteConfig.url}/api/site-preview`, + sitePreviewApiUrl: `${siteConfig.url}/site-preview`, }; }, }} diff --git a/demo/site/src/app/api/status/route.tsx b/demo/site/src/app/[domain]/api/status/route.tsx similarity index 100% rename from demo/site/src/app/api/status/route.tsx rename to demo/site/src/app/[domain]/api/status/route.tsx diff --git a/demo/site/src/app/api/site-preview/route.ts b/demo/site/src/app/site-preview/route.ts similarity index 100% rename from demo/site/src/app/api/site-preview/route.ts rename to demo/site/src/app/site-preview/route.ts diff --git a/demo/site/src/middleware.ts b/demo/site/src/middleware.ts index 58b34a15e3..b975b1c2a4 100644 --- a/demo/site/src/middleware.ts +++ b/demo/site/src/middleware.ts @@ -1,10 +1,10 @@ import { withAdminRedirectMiddleware } from "./middleware/adminRedirect"; -import { withBlockPreviewMiddleware } from "./middleware/blockPreview"; import { chain } from "./middleware/chain"; import { withCspHeadersMiddleware } from "./middleware/cspHeaders"; import { withDamRewriteMiddleware } from "./middleware/damRewrite"; import { withDomainRewriteMiddleware } from "./middleware/domainRewrite"; import { withPredefinedPagesMiddleware } from "./middleware/predefinedPages"; +import { withPreviewMiddleware } from "./middleware/preview"; import { withRedirectToMainHostMiddleware } from "./middleware/redirectToMainHost"; import { withSitePreviewMiddleware } from "./middleware/sitePreview"; @@ -14,7 +14,7 @@ export default chain([ withAdminRedirectMiddleware, withDamRewriteMiddleware, withCspHeadersMiddleware, // order matters: after redirects (that don't need csp headers), before everything else that needs csp headers - withBlockPreviewMiddleware, + withPreviewMiddleware, withPredefinedPagesMiddleware, withDomainRewriteMiddleware, // must be last (rewrites all urls) ]); @@ -23,14 +23,13 @@ export const config = { matcher: [ /* * Match all request paths except for the ones starting with: - * - api (API routes) * - _next/static (static files) * - _next/image (image optimization files) * - favicon.ico, favicon.svg, favicon.png * - manifest.json * - robots.txt */ - "/((?!api|_next/static|_next/image|favicon.ico|favicon.svg|favicon.png|manifest.json|robots.txt).*)", + "/((?!_next/static|_next/image|favicon.ico|favicon.svg|favicon.png|manifest.json|robots.txt).*)", ], // TODO find a better solution for this (https://nextjs.org/docs/messages/edge-dynamic-code-evaluation) unstable_allowDynamic: [ diff --git a/demo/site/src/middleware/blockPreview.ts b/demo/site/src/middleware/preview.ts similarity index 72% rename from demo/site/src/middleware/blockPreview.ts rename to demo/site/src/middleware/preview.ts index 4316843042..6ec45d2c69 100644 --- a/demo/site/src/middleware/blockPreview.ts +++ b/demo/site/src/middleware/preview.ts @@ -2,9 +2,9 @@ import { NextRequest, NextResponse } from "next/server"; import { CustomMiddleware } from "./chain"; -export function withBlockPreviewMiddleware(middleware: CustomMiddleware) { +export function withPreviewMiddleware(middleware: CustomMiddleware) { return async (request: NextRequest) => { - if (request.nextUrl.pathname.startsWith("/block-preview/")) { + if (request.nextUrl.pathname.startsWith("/block-preview/") || request.nextUrl.pathname.startsWith("/site-preview/")) { // don't apply any other middlewares return NextResponse.next(); } From 394d037fbcff433c827456ab727d9362ba8b0d9e Mon Sep 17 00:00:00 2001 From: Daniel Karnutsch Date: Tue, 14 Jan 2025 15:05:05 +0100 Subject: [PATCH 2/3] Docs: Console command best practices for command and argument casing (#2660) Co-authored-by: Johannes Obermair <48853629+johnnyomair@users.noreply.github.com> --- docs/docs/3-features-modules/5-console-commands/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/3-features-modules/5-console-commands/index.md b/docs/docs/3-features-modules/5-console-commands/index.md index 72cc5cdeda..7501d42e39 100644 --- a/docs/docs/3-features-modules/5-console-commands/index.md +++ b/docs/docs/3-features-modules/5-console-commands/index.md @@ -61,6 +61,7 @@ npm run console:prod demo-command ## Best practices +- Use kebab case for command names and arguments. - Dangerous commands (e.g. resetting the database) should check the `NODE_ENV` and only run locally. ```ts From 77ba36cb3d41ba5ecb9f0ae52d3148f2300ea8a2 Mon Sep 17 00:00:00 2001 From: fichtnerma <72387685+fichtnerma@users.noreply.github.com> Date: Tue, 14 Jan 2025 15:21:47 +0100 Subject: [PATCH 3/3] Support kB and MB when displaying the size of a file (#2823) --- demo/site/package.json | 1 + .../src/common/blocks/CallToActionBlock.tsx | 22 +++++++++++++------ demo/site/src/common/blocks/TextLinkBlock.tsx | 9 ++------ pnpm-lock.yaml | 8 +++++++ 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/demo/site/package.json b/demo/site/package.json index 7329918529..1284bfa300 100644 --- a/demo/site/package.json +++ b/demo/site/package.json @@ -34,6 +34,7 @@ "@opentelemetry/sdk-node": "^0.53.0", "cache-manager": "^5.5.3", "express": "^4.0.0", + "filesize": "^10.1.6", "fs-extra": "^9.0.0", "graphql": "^15.0.0", "graphql-tag": "^2.12.6", diff --git a/demo/site/src/common/blocks/CallToActionBlock.tsx b/demo/site/src/common/blocks/CallToActionBlock.tsx index c5a3c75d92..729eeb8805 100644 --- a/demo/site/src/common/blocks/CallToActionBlock.tsx +++ b/demo/site/src/common/blocks/CallToActionBlock.tsx @@ -1,6 +1,7 @@ "use client"; import { PropsWithData, withPreview } from "@comet/cms-site"; import { CallToActionBlockData } from "@src/blocks.generated"; +import { filesize } from "filesize"; import { Button, ButtonVariant } from "../components/Button"; import { HiddenIfInvalidLink } from "../helpers/HiddenIfInvalidLink"; @@ -13,12 +14,19 @@ const buttonVariantMap: Record }; export const CallToActionBlock = withPreview( - ({ data: { textLink, variant } }: PropsWithData) => ( - - - - ), + ({ data: { textLink, variant } }: PropsWithData) => { + const linkBlock = textLink.link.block; + let buttonText = textLink.text; + if (linkBlock && linkBlock.type === "damFileDownload" && "file" in linkBlock.props && linkBlock.props.file) { + buttonText = `${buttonText} (${filesize(linkBlock?.props.file?.size)})`; + } + return ( + + + + ); + }, { label: "Call To Action" }, ); diff --git a/demo/site/src/common/blocks/TextLinkBlock.tsx b/demo/site/src/common/blocks/TextLinkBlock.tsx index e7fff8e330..598748f07f 100644 --- a/demo/site/src/common/blocks/TextLinkBlock.tsx +++ b/demo/site/src/common/blocks/TextLinkBlock.tsx @@ -1,6 +1,7 @@ "use client"; import { PropsWithData, withPreview } from "@comet/cms-site"; import { TextLinkBlockData } from "@src/blocks.generated"; +import { filesize } from "filesize"; import styled from "styled-components"; import { LinkBlock } from "./LinkBlock"; @@ -8,13 +9,7 @@ import { LinkBlock } from "./LinkBlock"; export const TextLinkBlock = withPreview( ({ data: { link, text } }: PropsWithData) => { if (link.block && link.block.type === "damFileDownload" && "file" in link.block.props && link.block.props.file) { - return ( - - <> - {text} ({Math.round(link.block.props.file.size / 1024)} KB) - - - ); + return {`${text} (${filesize(link.block.props.file.size)})`}; } return {text}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c85ceb8d00..41cff3228b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -679,6 +679,9 @@ importers: express: specifier: ^4.0.0 version: 4.18.2 + filesize: + specifier: ^10.1.6 + version: 10.1.6 fs-extra: specifier: ^9.0.0 version: 9.1.0 @@ -22415,6 +22418,11 @@ packages: minimatch: 5.1.6 dev: true + /filesize@10.1.6: + resolution: {integrity: sha512-sJslQKU2uM33qH5nqewAwVB2QgR6w1aMNsYUp3aN5rMRyXEwJGmZvaWzeJFNTOXWlHQyBFCWrdj3fV/fsTOX8w==} + engines: {node: '>= 10.4.0'} + dev: false + /filesize@8.0.7: resolution: {integrity: sha512-pjmC+bkIF8XI7fWaH8KxHcZL3DPybs1roSKP4rKDvy20tAWwIObE4+JIseG2byfGKhud5ZnM4YSGKBz7Sh0ndQ==} engines: {node: '>= 0.4.0'}