This commit is contained in:
Jordi Enric
2024-03-28 18:27:03 +01:00
parent b59f33d808
commit 7a33a884f4
14 changed files with 211 additions and 31 deletions
@@ -1,3 +1,4 @@
/* eslint-disable @next/next/no-img-element */
import React, { useState } from "react";
import { Input } from "../ui/input";
import { Button } from "../ui/button";
@@ -9,6 +10,8 @@ import DateTimePicker from "react-datetime-picker";
import "react-datetime-picker/dist/DateTimePicker.css";
import "react-calendar/dist/Calendar.css";
import "react-clock/dist/Clock.css";
import Image from "next/image";
import { CopyCell } from "../copy-cell";
type MetadataItem = {
key: string;
@@ -19,6 +22,8 @@ type Props = {
metadata?: MetadataItem[];
selectedTags: string[];
published_at?: string;
blogEmoji?: string;
blogTitle?: string;
onChange: ({
metadata,
tags,
@@ -79,6 +84,8 @@ const EditorSettings = (props: Props) => {
props.onChange({ metadata, tags });
};
const ogImageUrl = `/api/og?title=${props.title}&emoji=${props.blogEmoji}&url=${props.blogTitle}`;
return (
<div className="[&_h2]:font-mono [&_h2]:text-sm [&_h2]:font-medium">
<section className="mt-2">
@@ -215,16 +222,27 @@ const EditorSettings = (props: Props) => {
<section className="mt-8">
<h2>Open graph image</h2>
<img
<Image
className="mt-4 max-w-full rounded-md border"
src={`/api/og?title=${props.title}`}
src={ogImageUrl}
alt=""
width={600}
height={300}
/>
<p className="mt-2 rounded-md border bg-zinc-100 p-1 font-mono text-xs text-zinc-700">
{process.env.NEXT_PUBLIC_BASE_URL}/api/og?title={props.title}
</p>
<div className="mt-2 flex justify-end">
<Button
variant="ghost"
onClick={() => {
navigator.clipboard.writeText(
process.env.NEXT_PUBLIC_BASE_URL + ogImageUrl
);
toast("Copied image URL to clipboard");
}}
>
Copy image URL
</Button>
{/* <CopyCell text={process.env.NEXT_PUBLIC_BASE_URL + ogImageUrl} /> */}
</div>
</section>
</div>
);
@@ -372,6 +372,8 @@ export const ZendoEditor = (props: Props) => {
title={title}
metadata={metadata as any}
selectedTags={tags}
blogEmoji={blogQuery.data?.emoji}
blogTitle={blogQuery.data?.title}
published_at={publishedAt}
onChange={(data) => {
setMetadata(data.metadata);
+1 -1
View File
@@ -11,7 +11,7 @@ export const CopyCell = (props: Props) => {
return (
<div className="flex items-center justify-between rounded-md border bg-zinc-100 px-2 py-1 font-mono text-sm text-zinc-600">
<div className="px-2">{props.text}</div>
<div className="truncate px-2">{props.text}</div>
<Button
onClick={() => {
navigator.clipboard.writeText(props.text);
+10 -1
View File
@@ -29,7 +29,16 @@ const ibmPlexMono = IBM_Plex_Mono({
// Main Component
function MyApp({ Component, pageProps }: AppProps) {
const { pathname, isReady } = useRouter();
const [queryClient] = useState(() => new QueryClient());
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
},
},
})
);
return (
<div className={`${ibmPlexMono.variable} ${inter.variable}`}>
@@ -15,17 +15,17 @@ export default async function handler(
}
const { data, error } = await db
.from("posts_with_blog_and_subscription_status")
.from("posts_with_blog_and_subscription_status_v2")
.select(
`title, ${
withContent ? "content, " : ""
} cover_image, metadata,updated_at,slug,tags`
} cover_image, metadata,updated_at,slug,tags,published_at`
)
.eq("blog_id", blogId)
.eq("published", true)
.eq("deleted", false)
.eq("subscription_status", "active")
.order("created_at", { ascending: false });
.order("published_at", { ascending: false });
if (error) {
console.error(error);
+1 -1
View File
@@ -61,7 +61,7 @@ export default function Dashboard() {
>
<div className="flex items-center gap-4">
<div>
<div className="flex h-12 w-12 items-center justify-center rounded-full bg-orange-100 text-3xl transition-all group-hover:scale-110">
<div className="flex h-12 w-12 items-center justify-center rounded-full border bg-zinc-50 text-3xl transition-all group-hover:scale-110">
{blog.emoji}
</div>
</div>
+8 -5
View File
@@ -14,13 +14,16 @@ export default async function Home({
return (
<main className="">
<img
className="mx-auto max-w-4xl border"
src={post.cover_image}
alt={post.title}
/>
{post.cover_image && (
<img
className="mx-auto max-w-4xl border"
src={post.cover_image}
alt={post.title}
/>
)}
<div className="prose mx-auto max-w-xl p-4">
<h1 className="">{post.title}</h1>
<pre>{JSON.stringify(post.content)}</pre>
</div>
</main>
);
+8 -2
View File
@@ -8,7 +8,11 @@ export default async function Home() {
const formatDate = (date: string) => {
const d = new Date(date);
return d.toLocaleDateString();
return d.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
});
};
return (
@@ -19,7 +23,9 @@ export default async function Home() {
href={`/blog/${post.slug}`}
key={post.slug}
>
<span className="text-slate-400">{formatDate(post.created_at)}</span>
<span className="text-slate-400">
{formatDate(post.published_at)}
</span>
<span>{post.title}</span>
</Link>
))}
+8 -1
View File
@@ -1,8 +1,15 @@
import { createClient } from "zenblog";
export const getBlog = () => {
const blogId = process.env.ZENBLOG_DEMO_BLOG_ID;
console.log("BLOG ID_______", blogId);
if (!blogId) {
throw new Error("No blog ID provided");
}
const blog = createClient({
blogId: "53a970ef-cc74-40ac-ac53-c322cd4848cb",
blogId,
debug: true,
_url: process.env.NEXT_PUBLIC_API_URL + "/public",
});
+135
View File
@@ -16292,6 +16292,141 @@
"packages/zenblog": {
"version": "0.1.3",
"license": "MIT"
},
"node_modules/@next/swc-darwin-arm64": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.4.tgz",
"integrity": "sha512-mF05E/5uPthWzyYDyptcwHptucf/jj09i2SXBPwNzbgBNc+XnwzrL0U6BmPjQeOL+FiB+iG1gwBeq7mlDjSRPg==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-darwin-x64": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.0.4.tgz",
"integrity": "sha512-IZQ3C7Bx0k2rYtrZZxKKiusMTM9WWcK5ajyhOZkYYTCc8xytmwSzR1skU7qLgVT/EY9xtXDG0WhY6fyujnI3rw==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-arm64-gnu": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.0.4.tgz",
"integrity": "sha512-VwwZKrBQo/MGb1VOrxJ6LrKvbpo7UbROuyMRvQKTFKhNaXjUmKTu7wxVkIuCARAfiI8JpaWAnKR+D6tzpCcM4w==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-arm64-musl": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.0.4.tgz",
"integrity": "sha512-8QftwPEW37XxXoAwsn+nXlodKWHfpMaSvt81W43Wh8dv0gkheD+30ezWMcFGHLI71KiWmHK5PSQbTQGUiidvLQ==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-x64-gnu": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.4.tgz",
"integrity": "sha512-/s/Pme3VKfZAfISlYVq2hzFS8AcAIOTnoKupc/j4WlvF6GQ0VouS2Q2KEgPuO1eMBwakWPB1aYFIA4VNVh667A==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-x64-musl": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.4.tgz",
"integrity": "sha512-m8z/6Fyal4L9Bnlxde5g2Mfa1Z7dasMQyhEhskDATpqr+Y0mjOBZcXQ7G5U+vgL22cI4T7MfvgtrM2jdopqWaw==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-win32-arm64-msvc": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.0.4.tgz",
"integrity": "sha512-7Wv4PRiWIAWbm5XrGz3D8HUkCVDMMz9igffZG4NB1p4u1KoItwx9qjATHz88kwCEal/HXmbShucaslXCQXUM5w==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-win32-ia32-msvc": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.0.4.tgz",
"integrity": "sha512-zLeNEAPULsl0phfGb4kdzF/cAVIfaC7hY+kt0/d+y9mzcZHsMS3hAS829WbJ31DkSlVKQeHEjZHIdhN+Pg7Gyg==",
"cpu": [
"ia32"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-win32-x64-msvc": {
"version": "14.0.4",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.4.tgz",
"integrity": "sha512-yEh2+R8qDlDCjxVpzOTEpBLQTEFAcP2A8fUFLaWNap9GitYKkKv1//y2S6XY6zsR4rCOPRpU7plYDR+az2n30A==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
}
}
}
+5 -5
View File
@@ -2,7 +2,11 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.createClient = void 0;
function logError(...args) {
console.error("[🍊] ", ...args);
console.error("[zenblog error] ", ...args);
}
function throwError(msg, ...args) {
logError(msg, ...args);
throw new Error("[zenblog error] " + msg);
}
function createDebugger(debug) {
return (...args) => {
@@ -21,10 +25,6 @@ function getConfig(url) {
api: "https://www.zenblog.com/api/public",
};
}
function throwError(msg, ...args) {
logError(msg, ...args);
throw new Error("[🚨] " + msg);
}
function createClient({ blogId, _url, debug }) {
const config = getConfig(_url);
const log = createDebugger(debug || false);
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"index.js","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AkB;qBACnC;oBACD,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,SAAS;iBAChC,CAAC,CAAC;gBACH,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;gBAG3B,OAAO,KAAoB,CAAC,CAAC,kBAAkB;YACjD,CAAC;YACD,SAAS,EAAE,KAAK,WACd,IAAY,EACZ,IAAc;gBAEd,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,QAAQ,IAAI,EAAE,EAAE;oBACxC,MAAM,EAAE,KAAK;oBACb,OAAO,EAAE;wBACP,cAAc,EAAE,kBAAkB;qBACnC;oBACD,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,SAAS;iBAChC,CAAC,CAAC;gBAEH,GAAG,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;gBAE7B,OAAO,IAA2B,CAAC,CAAC,kBAAkB;YACxD,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AA7ED,oCA6EC"}
+6 -6
View File
@@ -1,5 +1,10 @@
function logError(...args: any[]) {
console.error("[🍊] ", ...args);
console.error("[zenblog error] ", ...args);
}
function throwError(msg: string, ...args: any[]) {
logError(msg, ...args);
throw new Error("[zenblog error] " + msg);
}
function createDebugger(debug: boolean) {
@@ -21,11 +26,6 @@ function getConfig(url?: string): { api: string } {
};
}
function throwError(msg: string, ...args: any[]) {
logError(msg, ...args);
throw new Error("[🚨] " + msg);
}
export type Post = {
slug: string;
title: string;