fix: single file import
This commit is contained in:
parent
96e7fa4a07
commit
ec9958a537
|
|
@ -21,7 +21,7 @@
|
|||
"blog": "博客",
|
||||
"Owner": "所有者",
|
||||
"Transaction Hash": "交易哈希",
|
||||
"IPFS Address": "IPF 地址",
|
||||
"IPFS Address": "IPFS 地址",
|
||||
"Creation": "创建",
|
||||
"Last Update": "最后更新",
|
||||
"Create Character": "创建角色",
|
||||
|
|
|
|||
|
|
@ -101,5 +101,6 @@
|
|||
"hsinyau",
|
||||
"rootless",
|
||||
"haydenull",
|
||||
"walk2future"
|
||||
"walk2future",
|
||||
"cryptonerdcn"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import { renderPageContent } from "~/markdown"
|
|||
import { Tooltip } from "../ui/Tooltip"
|
||||
import { APP_NAME } from "~/lib/env"
|
||||
import { Trans, useTranslation } from "next-i18next"
|
||||
import { readFiles } from "~/lib/read-files"
|
||||
|
||||
export const PagesManager: React.FC<{
|
||||
isPost: boolean
|
||||
|
|
@ -242,45 +243,28 @@ export const PagesManager: React.FC<{
|
|||
input.type = "file"
|
||||
input.accept = ".md"
|
||||
input.addEventListener("change", async (e: any) => {
|
||||
const file = e.target?.files?.[0]
|
||||
const reader = new FileReader()
|
||||
reader.readAsText(file, "UTF-8")
|
||||
reader.onload = (evt) => {
|
||||
if (evt.target?.result) {
|
||||
const pageContent = renderPageContent(evt.target.result as string)
|
||||
|
||||
const id = nanoid()
|
||||
const key = `draft-${subdomain}-local-${id}`
|
||||
const tags =
|
||||
pageContent.frontMatter.tags || pageContent.frontMatter.categories
|
||||
setStorage(key, {
|
||||
date: +new Date(),
|
||||
values: {
|
||||
content: evt.target.result,
|
||||
published: false,
|
||||
publishedAt: (
|
||||
pageContent.frontMatter.date ||
|
||||
file.lastModified ||
|
||||
new Date()
|
||||
).toISOString(),
|
||||
slug:
|
||||
pageContent.frontMatter.permalink ||
|
||||
file.name.split(".").slice(0, -1).join("."),
|
||||
tags: tags?.join?.(", ") || tags,
|
||||
title: pageContent.frontMatter.title,
|
||||
},
|
||||
isPost: isPost,
|
||||
})
|
||||
queryClient.invalidateQueries(["getPagesBySite", subdomain])
|
||||
router.push(
|
||||
`/dashboard/${subdomain}/editor?id=local-${id}&type=${
|
||||
isPost ? "post" : "page"
|
||||
}`,
|
||||
)
|
||||
}
|
||||
}
|
||||
reader.onerror = (evt) => {
|
||||
toast.error("Error reading file")
|
||||
const file = (await readFiles(e.target?.files))?.[0]
|
||||
if (file) {
|
||||
const id = nanoid()
|
||||
const key = `draft-${subdomain}-local-${id}`
|
||||
setStorage(key, {
|
||||
date: +new Date(),
|
||||
values: {
|
||||
content: file.content,
|
||||
published: false,
|
||||
publishedAt: file.date_published,
|
||||
slug: file.slug,
|
||||
tags: file.tags?.join?.(", "),
|
||||
title: file.title,
|
||||
},
|
||||
isPost: isPost,
|
||||
})
|
||||
queryClient.invalidateQueries(["getPagesBySite", subdomain])
|
||||
router.push(
|
||||
`/dashboard/${subdomain}/editor?id=local-${id}&type=${
|
||||
isPost ? "post" : "page"
|
||||
}`,
|
||||
)
|
||||
}
|
||||
})
|
||||
input.click()
|
||||
|
|
|
|||
|
|
@ -77,13 +77,15 @@ export const renderPageContent = (
|
|||
.use(remarkFrontmatter, ["yaml"])
|
||||
.use(() => (tree) => {
|
||||
const yaml = tree.children.find((node) => node.type === "yaml")
|
||||
try {
|
||||
env.frontMatter = jsYaml.load((yaml as any)?.value) as Record<
|
||||
string,
|
||||
any
|
||||
>
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
if ((yaml as any)?.value) {
|
||||
try {
|
||||
env.frontMatter = jsYaml.load((yaml as any)?.value) as Record<
|
||||
string,
|
||||
any
|
||||
>
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
.use(() => (tree) => {
|
||||
|
|
|
|||
|
|
@ -161,7 +161,9 @@ const expandPage = async (page: Note, useStat?: boolean) => {
|
|||
}
|
||||
}
|
||||
page.cover = rendered.cover
|
||||
page.metadata!.frontMatter = rendered.frontMatter
|
||||
if (page.metadata) {
|
||||
page.metadata.frontMatter = rendered.frontMatter
|
||||
}
|
||||
}
|
||||
page.slug = encodeURIComponent(
|
||||
page.attributes?.find((a) => a.trait_type === "xlog_slug")?.value ||
|
||||
|
|
|
|||
Loading…
Reference in New Issue