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

Tina preview plugin no encoding #442

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions components/posts/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import format from "date-fns/format";
import { TinaMarkdown } from "tinacms/dist/rich-text";
import { Prism } from "tinacms/dist/rich-text/prism";
import type { TinaMarkdownContent, Components } from "tinacms/dist/rich-text";
import { previewField } from "@tinacms/preview-helpers/dist/react";

const components: Components<{
BlockQuote: {
Expand Down Expand Up @@ -137,6 +138,7 @@ export const Post = (props) => {
<Container width="small" className={`flex-1 pb-2`} size="large">
<h2
data-tinafield="title"
data-vercel-edit-info={previewField(props, "title")}
className={`w-full relative mb-8 text-6xl font-extrabold tracking-normal text-center title-font`}
>
<span
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"@svgr/webpack": "^6.3.1",
"@tinacms/cli": "^1.5.2",
"@tinacms/cli": "^0.0.0-20230425001052",
"@types/js-cookie": "^3.0.0",
"@types/node": "^16.11.7",
"@types/react": "^17.0.35",
Expand All @@ -27,6 +27,7 @@
"dependencies": {
"@headlessui/react": "1.7.5",
"@tailwindcss/typography": "^0.5.8",
"@tinacms/preview-helpers": "^0.0.0-20230425001052",
"date-fns": "^2.23.0",
"next": "^12.3.1",
"react": "^17.0.2",
Expand All @@ -36,7 +37,7 @@
"styled-components": "^5.1.3",
"styled-jsx": "^3.2.5",
"tailwindcss": "^3.2.4",
"tinacms": "^1.4.3",
"tinacms": "^0.0.0-20230425001052",
"typescript": "^4.5.2"
},
"resolutions": {
Expand Down
8 changes: 7 additions & 1 deletion pages/[filename].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Blocks } from "../components/blocks-renderer";
import { useTina } from "tinacms/dist/react";
import { Layout } from "../components/layout";
import { client } from "../tina/__generated__/client";
import { expandWithMetadata } from "@tinacms/preview-helpers";
import { useEditOpen } from "@tinacms/preview-helpers/dist/react";

export default function HomePage(
props: AsyncReturnType<typeof getStaticProps>["props"]
Expand All @@ -11,6 +13,7 @@ export default function HomePage(
variables: props.variables,
data: props.data,
});
useEditOpen("/admin");
return (
<Layout rawData={data} data={data.global as any}>
<Blocks {...data.page} />
Expand All @@ -19,9 +22,12 @@ export default function HomePage(
}

export const getStaticProps = async ({ params }) => {
const tinaProps = await client.queries.contentQuery({
let tinaProps = await client.queries.contentQuery({
relativePath: `${params.filename}.md`,
});
if (process.env.VERCEL_ENV === "preview") {
tinaProps = await expandWithMetadata(tinaProps, client, true);
}
return {
props: {
data: tinaProps.data,
Expand Down
10 changes: 9 additions & 1 deletion pages/posts/[filename].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Post } from "../../components/posts/post";
import { client } from "../../tina/__generated__/client";
import { useTina } from "tinacms/dist/react";
import { Layout } from "../../components/layout";
import { expandWithMetadata } from "@tinacms/preview-helpers";
import { useEditOpen } from "@tinacms/preview-helpers/dist/react";

// Use the props returned by get static props
export default function BlogPostPage(
Expand All @@ -12,6 +14,8 @@ export default function BlogPostPage(
variables: props.variables,
data: props.data,
});
useEditOpen("/admin");

if (data && data.post) {
return (
<Layout rawData={data} data={data.global as any}>
Expand All @@ -27,9 +31,13 @@ export default function BlogPostPage(
}

export const getStaticProps = async ({ params }) => {
const tinaProps = await client.queries.blogPostQuery({
let tinaProps = await client.queries.blogPostQuery({
relativePath: `${params.filename}.mdx`,
});

if (process.env.VERCEL_ENV === "preview") {
tinaProps = await expandWithMetadata(tinaProps, client, true);
}
return {
props: {
...tinaProps,
Expand Down
2 changes: 1 addition & 1 deletion tina/tina-lock.json

Large diffs are not rendered by default.

Loading