refactor: replace pinyin with pinyin-pro
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { getDefaultSlug } from "~/lib/default-slug"
|
||||
import { NextServerResponse, getQuery } from "~/lib/server-helper"
|
||||
|
||||
export async function GET(req: Request) {
|
||||
@@ -17,5 +18,22 @@ export async function GET(req: Request) {
|
||||
})
|
||||
).json()
|
||||
|
||||
if (result.data?.projectFeed?.posts?.length) {
|
||||
result.data.projectFeed.posts = result.data.projectFeed.posts.map(
|
||||
(post: any) => {
|
||||
return {
|
||||
title: post.title,
|
||||
date_published: new Date(
|
||||
post.publishedAtTimestamp * 1000,
|
||||
).toISOString(),
|
||||
slug: getDefaultSlug(post.title, post.digest),
|
||||
tags: ["Mirror.xyz"],
|
||||
content: post.body,
|
||||
external_urls: [`https://mirror.xyz/${address}/${post.digest}`],
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return new NextServerResponse().status(200).json(result)
|
||||
}
|
||||
|
||||
+11
-11
@@ -1,17 +1,17 @@
|
||||
// import pinyin from "pinyin"
|
||||
// TODO
|
||||
import { pinyin } from "pinyin-pro"
|
||||
|
||||
export const getDefaultSlug = (title: string, id?: string) => {
|
||||
let generated =
|
||||
// pinyin(title as string, {
|
||||
// style: pinyin.STYLE_NORMAL,
|
||||
// compact: true,
|
||||
// })?.[0]
|
||||
// ?.map((word) => word.trim())
|
||||
// ?.filter((word) => word)
|
||||
// ?.join("-")
|
||||
// ?.replace(/\s+/g, "-") ||
|
||||
// id?.replace(`local-`, "") ||
|
||||
pinyin(title, {
|
||||
toneType: "none",
|
||||
type: "array",
|
||||
nonZh: "consecutive",
|
||||
})
|
||||
?.map((word) => word.trim())
|
||||
?.filter((word) => word)
|
||||
?.join("-")
|
||||
?.replace(/\s+/g, "-") ||
|
||||
id?.replace(`local-`, "") ||
|
||||
""
|
||||
generated = generated.replace(/[^a-zA-Z0-9\s-_]/g, "")
|
||||
|
||||
|
||||
+1
-14
@@ -373,8 +373,6 @@ export function useGetSummary(input: { cid?: string; lang?: string }) {
|
||||
|
||||
export function useGetMirrorXyz(input: { address?: string }) {
|
||||
return useQuery(["getMirror", input.address], async () => {
|
||||
const { getDefaultSlug } = await import("~/lib/default-slug")
|
||||
|
||||
if (!input.address) {
|
||||
return null
|
||||
}
|
||||
@@ -387,18 +385,7 @@ export function useGetMirrorXyz(input: { address?: string }) {
|
||||
)
|
||||
).json()
|
||||
|
||||
return response?.data?.projectFeed?.posts?.map((post: any) => {
|
||||
return {
|
||||
title: post.title,
|
||||
date_published: new Date(
|
||||
post.publishedAtTimestamp * 1000,
|
||||
).toISOString(),
|
||||
slug: getDefaultSlug(post.title, post.digest),
|
||||
tags: ["Mirror.xyz"],
|
||||
content: post.body,
|
||||
external_urls: [`https://mirror.xyz/${input.address}/${post.digest}`],
|
||||
}
|
||||
}) as {
|
||||
return response?.data as {
|
||||
title: string
|
||||
type: string
|
||||
size: number
|
||||
|
||||
Reference in New Issue
Block a user