fix(ci): resolve tsc errors blocking QA stage (importMap and check-forms)
Some checks failed
Build & Deploy / 🔍 Prepare (push) Failing after 21s
Build & Deploy / 🧪 QA (push) Has been skipped
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s
Some checks failed
Build & Deploy / 🔍 Prepare (push) Failing after 21s
Build & Deploy / 🧪 QA (push) Has been skipped
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 1s
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { handleServerFunctions as payloadHandleServerFunctions } from "@payloadcms/next/layouts";
|
import { handleServerFunctions as payloadHandleServerFunctions } from "@payloadcms/next/layouts";
|
||||||
import config from "@payload-config";
|
import config from "@payload-config";
|
||||||
|
// @ts-expect-error - Payload generates this file during the build process
|
||||||
import { importMap } from "./admin/importMap";
|
import { importMap } from "./admin/importMap";
|
||||||
|
|
||||||
export const handleServerFunctions = async (args: any) => {
|
export const handleServerFunctions = async (args: any) => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { Metadata } from "next";
|
|||||||
|
|
||||||
import configPromise from "@payload-config";
|
import configPromise from "@payload-config";
|
||||||
import { RootPage, generatePageMetadata } from "@payloadcms/next/views";
|
import { RootPage, generatePageMetadata } from "@payloadcms/next/views";
|
||||||
|
// @ts-expect-error - Payload generates this file during the build process
|
||||||
import { importMap } from "../importMap";
|
import { importMap } from "../importMap";
|
||||||
|
|
||||||
type Args = {
|
type Args = {
|
||||||
|
|||||||
@@ -1,111 +1 @@
|
|||||||
import { OptimizeButton as OptimizeButton_a629b3460534b7aa208597fdc5e30aec } from "@/src/payload/components/OptimizeButton";
|
export const importMap = {};
|
||||||
import { GenerateSlugButton as GenerateSlugButton_63aadb132a046b3f001fac7a715e5717 } from "@/src/payload/components/FieldGenerators/GenerateSlugButton";
|
|
||||||
import { default as default_76cec558bd86098fa1dab70b12eb818f } from "@/src/payload/components/TagSelector";
|
|
||||||
import { GenerateThumbnailButton as GenerateThumbnailButton_39d416c162062cbe7173a99e3239786e } from "@/src/payload/components/FieldGenerators/GenerateThumbnailButton";
|
|
||||||
import { RscEntryLexicalCell as RscEntryLexicalCell_44fe37237e0ebf4470c9990d8cb7b07e } from "@payloadcms/richtext-lexical/rsc";
|
|
||||||
import { RscEntryLexicalField as RscEntryLexicalField_44fe37237e0ebf4470c9990d8cb7b07e } from "@payloadcms/richtext-lexical/rsc";
|
|
||||||
import { LexicalDiffComponent as LexicalDiffComponent_44fe37237e0ebf4470c9990d8cb7b07e } from "@payloadcms/richtext-lexical/rsc";
|
|
||||||
import { BlocksFeatureClient as BlocksFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { AiFieldButton as AiFieldButton_da42292f87769a8025025b774910be6d } from "@/src/payload/components/FieldGenerators/AiFieldButton";
|
|
||||||
import { InlineToolbarFeatureClient as InlineToolbarFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { HorizontalRuleFeatureClient as HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { UploadFeatureClient as UploadFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { BlockquoteFeatureClient as BlockquoteFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { RelationshipFeatureClient as RelationshipFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { LinkFeatureClient as LinkFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { ChecklistFeatureClient as ChecklistFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { OrderedListFeatureClient as OrderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { UnorderedListFeatureClient as UnorderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { IndentFeatureClient as IndentFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { AlignFeatureClient as AlignFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { HeadingFeatureClient as HeadingFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { ParagraphFeatureClient as ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { InlineCodeFeatureClient as InlineCodeFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { SuperscriptFeatureClient as SuperscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { SubscriptFeatureClient as SubscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { StrikethroughFeatureClient as StrikethroughFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { UnderlineFeatureClient as UnderlineFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { BoldFeatureClient as BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { ItalicFeatureClient as ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864 } from "@payloadcms/richtext-lexical/client";
|
|
||||||
import { default as default_2ebf44fdf8ebc607cf0de30cff485248 } from "@/src/payload/components/ColorPicker";
|
|
||||||
import { default as default_a1c6da8fb7dd9846a8b07123ff256d09 } from "@/src/payload/components/IconSelector";
|
|
||||||
import { ConvertInquiryButton as ConvertInquiryButton_09fd670bce023a947ab66e4eebea5168 } from "@/src/payload/components/ConvertInquiryButton";
|
|
||||||
import { AiAnalyzeButton as AiAnalyzeButton_51a6009c2b12d068d736ffd2b8182c71 } from "@/src/payload/components/AiAnalyzeButton";
|
|
||||||
import { GanttChartView as GanttChartView_0162b82db971e8f1e27fbdd0aaa2f1f4 } from "@/src/payload/views/GanttChart";
|
|
||||||
import { S3ClientUploadHandler as S3ClientUploadHandler_f97aa6c64367fa259c5bc0567239ef24 } from "@payloadcms/storage-s3/client";
|
|
||||||
import { CollectionCards as CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1 } from "@payloadcms/next/rsc";
|
|
||||||
|
|
||||||
export const importMap = {
|
|
||||||
"@/src/payload/components/OptimizeButton#OptimizeButton":
|
|
||||||
OptimizeButton_a629b3460534b7aa208597fdc5e30aec,
|
|
||||||
"@/src/payload/components/FieldGenerators/GenerateSlugButton#GenerateSlugButton":
|
|
||||||
GenerateSlugButton_63aadb132a046b3f001fac7a715e5717,
|
|
||||||
"@/src/payload/components/TagSelector#default":
|
|
||||||
default_76cec558bd86098fa1dab70b12eb818f,
|
|
||||||
"@/src/payload/components/FieldGenerators/GenerateThumbnailButton#GenerateThumbnailButton":
|
|
||||||
GenerateThumbnailButton_39d416c162062cbe7173a99e3239786e,
|
|
||||||
"@payloadcms/richtext-lexical/rsc#RscEntryLexicalCell":
|
|
||||||
RscEntryLexicalCell_44fe37237e0ebf4470c9990d8cb7b07e,
|
|
||||||
"@payloadcms/richtext-lexical/rsc#RscEntryLexicalField":
|
|
||||||
RscEntryLexicalField_44fe37237e0ebf4470c9990d8cb7b07e,
|
|
||||||
"@payloadcms/richtext-lexical/rsc#LexicalDiffComponent":
|
|
||||||
LexicalDiffComponent_44fe37237e0ebf4470c9990d8cb7b07e,
|
|
||||||
"@payloadcms/richtext-lexical/client#BlocksFeatureClient":
|
|
||||||
BlocksFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@/src/payload/components/FieldGenerators/AiFieldButton#AiFieldButton":
|
|
||||||
AiFieldButton_da42292f87769a8025025b774910be6d,
|
|
||||||
"@payloadcms/richtext-lexical/client#InlineToolbarFeatureClient":
|
|
||||||
InlineToolbarFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#HorizontalRuleFeatureClient":
|
|
||||||
HorizontalRuleFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#UploadFeatureClient":
|
|
||||||
UploadFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#BlockquoteFeatureClient":
|
|
||||||
BlockquoteFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#RelationshipFeatureClient":
|
|
||||||
RelationshipFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#LinkFeatureClient":
|
|
||||||
LinkFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#ChecklistFeatureClient":
|
|
||||||
ChecklistFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#OrderedListFeatureClient":
|
|
||||||
OrderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#UnorderedListFeatureClient":
|
|
||||||
UnorderedListFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#IndentFeatureClient":
|
|
||||||
IndentFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#AlignFeatureClient":
|
|
||||||
AlignFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#HeadingFeatureClient":
|
|
||||||
HeadingFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#ParagraphFeatureClient":
|
|
||||||
ParagraphFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#InlineCodeFeatureClient":
|
|
||||||
InlineCodeFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#SuperscriptFeatureClient":
|
|
||||||
SuperscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#SubscriptFeatureClient":
|
|
||||||
SubscriptFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#StrikethroughFeatureClient":
|
|
||||||
StrikethroughFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#UnderlineFeatureClient":
|
|
||||||
UnderlineFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#BoldFeatureClient":
|
|
||||||
BoldFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@payloadcms/richtext-lexical/client#ItalicFeatureClient":
|
|
||||||
ItalicFeatureClient_e70f5e05f09f93e00b997edb1ef0c864,
|
|
||||||
"@/src/payload/components/ColorPicker#default":
|
|
||||||
default_2ebf44fdf8ebc607cf0de30cff485248,
|
|
||||||
"@/src/payload/components/IconSelector#default":
|
|
||||||
default_a1c6da8fb7dd9846a8b07123ff256d09,
|
|
||||||
"@/src/payload/components/ConvertInquiryButton#ConvertInquiryButton":
|
|
||||||
ConvertInquiryButton_09fd670bce023a947ab66e4eebea5168,
|
|
||||||
"@/src/payload/components/AiAnalyzeButton#AiAnalyzeButton":
|
|
||||||
AiAnalyzeButton_51a6009c2b12d068d736ffd2b8182c71,
|
|
||||||
"@/src/payload/views/GanttChart#GanttChartView":
|
|
||||||
GanttChartView_0162b82db971e8f1e27fbdd0aaa2f1f4,
|
|
||||||
"@payloadcms/storage-s3/client#S3ClientUploadHandler":
|
|
||||||
S3ClientUploadHandler_f97aa6c64367fa259c5bc0567239ef24,
|
|
||||||
"@payloadcms/next/rsc#CollectionCards":
|
|
||||||
CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { RootLayout } from "@payloadcms/next/layouts";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { handleServerFunctions } from "./actions";
|
import { handleServerFunctions } from "./actions";
|
||||||
|
// @ts-expect-error - Payload generates this file during the build process
|
||||||
import { importMap } from "./admin/importMap";
|
import { importMap } from "./admin/importMap";
|
||||||
|
|
||||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ async function main() {
|
|||||||
|
|
||||||
// Enable console logging from the page for debugging
|
// Enable console logging from the page for debugging
|
||||||
page.on("console", (msg) => console.log(` [PAGE] ${msg.text()}`));
|
page.on("console", (msg) => console.log(` [PAGE] ${msg.text()}`));
|
||||||
page.on("pageerror", (err) => console.error(` [PAGE ERROR] ${err.message}`));
|
page.on("pageerror", (err: Error) =>
|
||||||
|
console.error(` [PAGE ERROR] ${err.message}`),
|
||||||
|
);
|
||||||
page.on("requestfailed", (req) =>
|
page.on("requestfailed", (req) =>
|
||||||
console.error(
|
console.error(
|
||||||
` [REQUEST FAILED] ${req.url()} - ${req.failure()?.errorText}`,
|
` [REQUEST FAILED] ${req.url()} - ${req.failure()?.errorText}`,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { getPayload } from "payload";
|
|||||||
import configPromise from "../payload.config";
|
import configPromise from "../payload.config";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { parseMarkdownToLexical } from "../src/payload/utils/lexicalParser";
|
import { parseMarkdownToLexical } from "@mintel/payload-ai";
|
||||||
|
|
||||||
function parseMatter(content: string) {
|
function parseMatter(content: string) {
|
||||||
const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
||||||
|
|||||||
@@ -2,121 +2,129 @@ import { getPayload } from "payload";
|
|||||||
import configPromise from "../payload.config";
|
import configPromise from "../payload.config";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { parseMarkdownToLexical } from "../src/payload/utils/lexicalParser";
|
import { parseMarkdownToLexical } from "@mintel/payload-ai";
|
||||||
|
|
||||||
function extractFrontmatter(content: string) {
|
function extractFrontmatter(content: string) {
|
||||||
const fmMatch = content.match(/^---\s*\n([\s\S]*?)\n---/);
|
const fmMatch = content.match(/^---\s*\n([\s\S]*?)\n---/);
|
||||||
if (!fmMatch) return {};
|
if (!fmMatch) return {};
|
||||||
const fm = fmMatch[1];
|
const fm = fmMatch[1];
|
||||||
const titleMatch = fm.match(/title:\s*"?([^"\n]+)"?/);
|
const titleMatch = fm.match(/title:\s*"?([^"\n]+)"?/);
|
||||||
const descMatch = fm.match(/description:\s*"?([^"\n]+)"?/);
|
const descMatch = fm.match(/description:\s*"?([^"\n]+)"?/);
|
||||||
const tagsMatch = fm.match(/tags:\s*\[(.*?)\]/);
|
const tagsMatch = fm.match(/tags:\s*\[(.*?)\]/);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: titleMatch ? titleMatch[1] : "Untitled Draft",
|
title: titleMatch ? titleMatch[1] : "Untitled Draft",
|
||||||
description: descMatch ? descMatch[1] : "No description",
|
description: descMatch ? descMatch[1] : "No description",
|
||||||
tags: tagsMatch ? tagsMatch[1].split(",").map(s => s.trim().replace(/"/g, "")) : []
|
tags: tagsMatch
|
||||||
};
|
? tagsMatch[1].split(",").map((s) => s.trim().replace(/"/g, ""))
|
||||||
|
: [],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const payload = await getPayload({ config: configPromise });
|
const payload = await getPayload({ config: configPromise });
|
||||||
console.log("Payload initialized.");
|
console.log("Payload initialized.");
|
||||||
|
|
||||||
const draftsDir = path.resolve(process.cwd(), "content/drafts");
|
const draftsDir = path.resolve(process.cwd(), "content/drafts");
|
||||||
const publicBlogDir = path.resolve(process.cwd(), "public/blog");
|
const publicBlogDir = path.resolve(process.cwd(), "public/blog");
|
||||||
|
|
||||||
if (!fs.existsSync(draftsDir)) {
|
if (!fs.existsSync(draftsDir)) {
|
||||||
console.log(`Drafts directory not found at ${draftsDir}`);
|
console.log(`Drafts directory not found at ${draftsDir}`);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
|
||||||
|
|
||||||
const files = fs.readdirSync(draftsDir).filter(f => f.endsWith(".md"));
|
|
||||||
let count = 0;
|
|
||||||
|
|
||||||
for (const file of files) {
|
|
||||||
console.log(`Processing ${file}...`);
|
|
||||||
const filePath = path.join(draftsDir, file);
|
|
||||||
const content = fs.readFileSync(filePath, "utf8");
|
|
||||||
|
|
||||||
const fm = extractFrontmatter(content);
|
|
||||||
const lexicalNodes = parseMarkdownToLexical(content);
|
|
||||||
const lexicalContent = {
|
|
||||||
root: {
|
|
||||||
type: "root",
|
|
||||||
format: "" as const,
|
|
||||||
indent: 0,
|
|
||||||
version: 1,
|
|
||||||
direction: "ltr" as const,
|
|
||||||
children: lexicalNodes
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Upload thumbnail if exists
|
|
||||||
let featuredImageId = null;
|
|
||||||
const thumbPath = path.join(publicBlogDir, `${file}.png`);
|
|
||||||
if (fs.existsSync(thumbPath)) {
|
|
||||||
console.log(`Uploading thumbnail ${file}.png...`);
|
|
||||||
const fileData = fs.readFileSync(thumbPath);
|
|
||||||
const stat = fs.statSync(thumbPath);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const newMedia = await payload.create({
|
|
||||||
collection: "media",
|
|
||||||
data: {
|
|
||||||
alt: `Thumbnail for ${fm.title}`,
|
|
||||||
},
|
|
||||||
file: {
|
|
||||||
data: fileData,
|
|
||||||
name: `optimized-${file}.png`,
|
|
||||||
mimetype: "image/png",
|
|
||||||
size: stat.size,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
featuredImageId = newMedia.id;
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Failed to upload thumbnail", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const tagsArray = fm.tags.map(tag => ({ tag }));
|
|
||||||
|
|
||||||
const slug = fm.title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "").substring(0, 60);
|
|
||||||
|
|
||||||
// Check if already exists
|
|
||||||
const existing = await payload.find({
|
|
||||||
collection: "posts",
|
|
||||||
where: { slug: { equals: slug } },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existing.totalDocs === 0) {
|
|
||||||
await payload.create({
|
|
||||||
collection: "posts",
|
|
||||||
data: {
|
|
||||||
title: fm.title,
|
|
||||||
slug: slug,
|
|
||||||
description: fm.description,
|
|
||||||
date: new Date().toISOString(),
|
|
||||||
tags: tagsArray,
|
|
||||||
featuredImage: featuredImageId,
|
|
||||||
content: lexicalContent,
|
|
||||||
_status: "published"
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.log(`Created CMS entry for ${file}.`);
|
|
||||||
count++;
|
|
||||||
} else {
|
|
||||||
console.log(`Post with slug ${slug} already exists. Skipping.`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Migration successful! Added ${count} new optimized posts to the database.`);
|
|
||||||
process.exit(0);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Migration failed:", e);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const files = fs.readdirSync(draftsDir).filter((f) => f.endsWith(".md"));
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
console.log(`Processing ${file}...`);
|
||||||
|
const filePath = path.join(draftsDir, file);
|
||||||
|
const content = fs.readFileSync(filePath, "utf8");
|
||||||
|
|
||||||
|
const fm = extractFrontmatter(content);
|
||||||
|
const lexicalNodes = parseMarkdownToLexical(content);
|
||||||
|
const lexicalContent = {
|
||||||
|
root: {
|
||||||
|
type: "root",
|
||||||
|
format: "" as const,
|
||||||
|
indent: 0,
|
||||||
|
version: 1,
|
||||||
|
direction: "ltr" as const,
|
||||||
|
children: lexicalNodes,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Upload thumbnail if exists
|
||||||
|
let featuredImageId = null;
|
||||||
|
const thumbPath = path.join(publicBlogDir, `${file}.png`);
|
||||||
|
if (fs.existsSync(thumbPath)) {
|
||||||
|
console.log(`Uploading thumbnail ${file}.png...`);
|
||||||
|
const fileData = fs.readFileSync(thumbPath);
|
||||||
|
const stat = fs.statSync(thumbPath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newMedia = await payload.create({
|
||||||
|
collection: "media",
|
||||||
|
data: {
|
||||||
|
alt: `Thumbnail for ${fm.title}`,
|
||||||
|
},
|
||||||
|
file: {
|
||||||
|
data: fileData,
|
||||||
|
name: `optimized-${file}.png`,
|
||||||
|
mimetype: "image/png",
|
||||||
|
size: stat.size,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
featuredImageId = newMedia.id;
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Failed to upload thumbnail", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tagsArray = fm.tags.map((tag) => ({ tag }));
|
||||||
|
|
||||||
|
const slug = fm.title
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]+/g, "-")
|
||||||
|
.replace(/(^-|-$)/g, "")
|
||||||
|
.substring(0, 60);
|
||||||
|
|
||||||
|
// Check if already exists
|
||||||
|
const existing = await payload.find({
|
||||||
|
collection: "posts",
|
||||||
|
where: { slug: { equals: slug } },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (existing.totalDocs === 0) {
|
||||||
|
await payload.create({
|
||||||
|
collection: "posts",
|
||||||
|
data: {
|
||||||
|
title: fm.title,
|
||||||
|
slug: slug,
|
||||||
|
description: fm.description,
|
||||||
|
date: new Date().toISOString(),
|
||||||
|
tags: tagsArray,
|
||||||
|
featuredImage: featuredImageId,
|
||||||
|
content: lexicalContent,
|
||||||
|
_status: "published",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
console.log(`Created CMS entry for ${file}.`);
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
console.log(`Post with slug ${slug} already exists. Skipping.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Migration successful! Added ${count} new optimized posts to the database.`,
|
||||||
|
);
|
||||||
|
process.exit(0);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Migration failed:", e);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|||||||
@@ -215,7 +215,6 @@ export const AgbsPDF = ({
|
|||||||
companyData={companyData}
|
companyData={companyData}
|
||||||
bankData={bankData}
|
bankData={bankData}
|
||||||
footerLogo={footerLogo}
|
footerLogo={footerLogo}
|
||||||
headerIcon={headerIcon}
|
|
||||||
showPageNumber={false}
|
showPageNumber={false}
|
||||||
>
|
>
|
||||||
{content}
|
{content}
|
||||||
|
|||||||
Reference in New Issue
Block a user