Skip to content

Commit

Permalink
Merge main into next
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jan 14, 2025
2 parents eb63f40 + 77ba36c commit dc373bb
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 14 deletions.
2 changes: 1 addition & 1 deletion demo/admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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`,
};
},
}}
Expand Down
7 changes: 7 additions & 0 deletions demo/site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
"@opentelemetry/exporter-trace-otlp-http": "^0.53.0",
"@opentelemetry/instrumentation-runtime-node": "^0.11.0",
"@opentelemetry/sdk-node": "^0.53.0",
<<<<<<< HEAD
"cache-manager": "^5.7.6",
=======
"cache-manager": "^5.5.3",
"express": "^4.0.0",
"filesize": "^10.1.6",
"fs-extra": "^9.0.0",
>>>>>>> main
"graphql": "^15.0.0",
"ioredis": "^5.4.2",
"lru-cache": "^11.0.1",
Expand Down
File renamed without changes.
File renamed without changes.
22 changes: 15 additions & 7 deletions demo/site/src/common/blocks/CallToActionBlock.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,12 +14,19 @@ const buttonVariantMap: Record<CallToActionBlockData["variant"], ButtonVariant>
};

export const CallToActionBlock = withPreview(
({ data: { textLink, variant } }: PropsWithData<CallToActionBlockData>) => (
<HiddenIfInvalidLink link={textLink.link}>
<Button as={LinkBlock} data={textLink.link} variant={buttonVariantMap[variant]}>
{textLink.text}
</Button>
</HiddenIfInvalidLink>
),
({ data: { textLink, variant } }: PropsWithData<CallToActionBlockData>) => {
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 (
<HiddenIfInvalidLink link={textLink.link}>
<Button as={LinkBlock} data={textLink.link} variant={buttonVariantMap[variant]}>
{buttonText}
</Button>
</HiddenIfInvalidLink>
);
},
{ label: "Call To Action" },
);
25 changes: 25 additions & 0 deletions demo/site/src/common/blocks/TextLinkBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"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";

export const TextLinkBlock = withPreview(
({ data: { link, text } }: PropsWithData<TextLinkBlockData>) => {
if (link.block && link.block.type === "damFileDownload" && "file" in link.block.props && link.block.props.file) {
return <Link data={link}>{`${text} (${filesize(link.block.props.file.size)})`}</Link>;
}

return <Link data={link}>{text}</Link>;
},
{ label: "Link" },
);

const Link = styled(LinkBlock)`
color: ${({ theme }) => theme.palette.text.primary};
&:hover {
color: ${({ theme }) => theme.palette.primary.main};
}
`;
7 changes: 3 additions & 4 deletions demo/site/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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)
]);
Expand All @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions docs/docs/3-features-modules/5-console-commands/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc373bb

Please sign in to comment.