Merge branch 'dev' into feat/mermaid
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
||||
|
||||
name: Node.js Build CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
|
||||
pull_request:
|
||||
branches: [main, dev]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [18.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Cache pnpm modules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-pnpm-modules
|
||||
with:
|
||||
path: ~/.pnpm-store
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
with:
|
||||
version: 8.x
|
||||
run_install: false
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
pnpm i
|
||||
- name: Test
|
||||
run: |
|
||||
pnpm run test-unit
|
||||
+2
-1
@@ -10,5 +10,6 @@
|
||||
43625, 42787, 43258, 33462, 47109, 46939, 45701, 33233, 37346, 40671, 51552,
|
||||
51585, 48937, 51379, 51460, 51084, 51509, 51478, 51639, 48910, 51139, 39329,
|
||||
51683, 51077, 51374, 49120, 47356, 17096, 50708, 51430, 51935, 51756, 6558,
|
||||
49392, 52186, 52055, 52282, 52270, 5825, 51351, 52233, 51308, 52388, 52280
|
||||
49392, 52186, 52055, 52282, 52270, 5825, 51351, 52233, 51308, 52388, 52280,
|
||||
52718, 52951, 52103, 52314, 52336, 52816, 52766, 52760, 660, 52728, 52683
|
||||
]
|
||||
|
||||
+19
-2
@@ -3,6 +3,9 @@
|
||||
"name": "xLog",
|
||||
"description": "Let's talk about xLog, whether to praise or criticize it.",
|
||||
"notes": [
|
||||
"45089-31",
|
||||
"52683-1",
|
||||
"51829-2",
|
||||
"10-50",
|
||||
"30-24",
|
||||
"30-25",
|
||||
@@ -58,13 +61,18 @@
|
||||
"52314-1",
|
||||
"52336-2",
|
||||
"51478-10",
|
||||
"33470-7"
|
||||
"33470-7",
|
||||
"52806-2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ChatGPT",
|
||||
"description": "The world is undergoing a fusion, and we are in the center of it.",
|
||||
"notes": [
|
||||
"51191-15",
|
||||
"50161-58",
|
||||
"53014-1",
|
||||
"53014-2",
|
||||
"30-84",
|
||||
"77-41",
|
||||
"723-96",
|
||||
@@ -137,13 +145,22 @@
|
||||
"52242-16",
|
||||
"51084-7",
|
||||
"50708-12",
|
||||
"52387-2"
|
||||
"52387-2",
|
||||
"52718-9",
|
||||
"52188-2",
|
||||
"32085-52",
|
||||
"17096-6",
|
||||
"52800-1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Life Journal",
|
||||
"description": "Discover new perspectives and insights in others' weekly, monthly, or yearly journal.",
|
||||
"notes": [
|
||||
"51937-1",
|
||||
"51191-15",
|
||||
"49120-369",
|
||||
"52242-19",
|
||||
"10-291",
|
||||
"10-49",
|
||||
"10-82",
|
||||
|
||||
+32
-31
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"build": "next build",
|
||||
"dev": "next -p 2222",
|
||||
"test-unit": "vitest run",
|
||||
"test-unit": "vitest",
|
||||
"test-e2e": "playwright test",
|
||||
"start": "node server.js",
|
||||
"uno-generate": "unocss \"src/**/*.{ts,tsx}\" -o src/generated/uno.css",
|
||||
@@ -28,29 +28,29 @@
|
||||
"@codemirror/lang-markdown": "6.1.0",
|
||||
"@codemirror/language": "6.6.0",
|
||||
"@codemirror/state": "6.2.0",
|
||||
"@codemirror/view": "6.9.3",
|
||||
"@crossbell/connect-kit": "0.0.59",
|
||||
"@crossbell/contract": "0.0.59",
|
||||
"@crossbell/indexer": "0.0.59",
|
||||
"@crossbell/notification": "0.0.59",
|
||||
"@crossbell/ui": "0.0.59",
|
||||
"@crossbell/util-hooks": "0.0.59",
|
||||
"@dqbd/tiktoken": "^1.0.3",
|
||||
"@codemirror/view": "6.9.4",
|
||||
"@crossbell/connect-kit": "0.0.63",
|
||||
"@crossbell/contract": "0.0.63",
|
||||
"@crossbell/indexer": "0.0.63",
|
||||
"@crossbell/notification": "0.0.63",
|
||||
"@crossbell/ui": "0.0.63",
|
||||
"@crossbell/util-hooks": "0.0.63",
|
||||
"@dqbd/tiktoken": "^1.0.4",
|
||||
"@emoji-mart/data": "1.1.2",
|
||||
"@emoji-mart/react": "1.1.1",
|
||||
"@floating-ui/react": "^0.22.3",
|
||||
"@floating-ui/react": "^0.23.0",
|
||||
"@headlessui/react": "1.7.13",
|
||||
"@heroicons/react": "2.0.17",
|
||||
"@iconify-json/mingcute": "^1.1.5",
|
||||
"@mantine/core": "^6.0.6",
|
||||
"@monaco-editor/react": "4.4.6",
|
||||
"@mantine/core": "^6.0.7",
|
||||
"@monaco-editor/react": "4.5.0",
|
||||
"@prisma/client": "^4.12.0",
|
||||
"@tanstack/react-query": "4.28.0",
|
||||
"@tanstack/react-query-devtools": "4.29.0",
|
||||
"@tanstack/react-query-persist-client": "4.28.0",
|
||||
"@uiw/codemirror-extensions-events": "4.19.11",
|
||||
"@uiw/react-codemirror": "4.19.11",
|
||||
"@urql/core": "4.0.3",
|
||||
"@tanstack/react-query": "4.29.1",
|
||||
"@tanstack/react-query-devtools": "4.29.1",
|
||||
"@tanstack/react-query-persist-client": "4.29.1",
|
||||
"@uiw/codemirror-extensions-events": "4.19.16",
|
||||
"@uiw/react-codemirror": "4.19.16",
|
||||
"@urql/core": "4.0.4",
|
||||
"axios": "1.3.5",
|
||||
"canvas-confetti": "^1.6.0",
|
||||
"chroma-js": "^2.4.2",
|
||||
@@ -67,7 +67,7 @@
|
||||
"ioredis": "5.3.1",
|
||||
"js-yaml": "4.1.0",
|
||||
"jsonfeed-to-rss": "^3.0.6",
|
||||
"langchain": "^0.0.49",
|
||||
"langchain": "^0.0.53",
|
||||
"lottie-react": "^2.4.0",
|
||||
"mdast-util-to-string": "3.2.0",
|
||||
"mdast-util-toc": "6.1.1",
|
||||
@@ -83,7 +83,7 @@
|
||||
"react-hot-toast": "2.4.0",
|
||||
"react-i18next": "^12.2.0",
|
||||
"react-infinite-scroller": "1.2.6",
|
||||
"react-parallax-tilt": "^1.7.125",
|
||||
"react-parallax-tilt": "^1.7.127",
|
||||
"react-scroll": "1.8.9",
|
||||
"react-sortablejs": "6.1.4",
|
||||
"refractor": "4.8.1",
|
||||
@@ -116,11 +116,11 @@
|
||||
"unist-util-visit": "4.1.2",
|
||||
"use-onclickoutside": "0.4.1",
|
||||
"uuid": "9.0.0",
|
||||
"wagmi": "0.12.9"
|
||||
"wagmi": "0.12.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@next/bundle-analyzer": "13.3.0",
|
||||
"@playwright/test": "1.32.2",
|
||||
"@playwright/test": "1.32.3",
|
||||
"@types/canvas-confetti": "^1.6.0",
|
||||
"@types/chroma-js": "^2.4.0",
|
||||
"@types/cookie": "0.5.1",
|
||||
@@ -129,32 +129,33 @@
|
||||
"@types/mjml": "4.7.1",
|
||||
"@types/node": "18.15.11",
|
||||
"@types/prismjs": "1.26.0",
|
||||
"@types/react": "18.0.33",
|
||||
"@types/react": "18.0.34",
|
||||
"@types/react-dom": "18.0.11",
|
||||
"@types/react-infinite-scroller": "1.2.3",
|
||||
"@types/react-scroll": "1.8.6",
|
||||
"@types/sortablejs": "1.15.1",
|
||||
"@types/ua-parser-js": "0.7.36",
|
||||
"@types/uuid": "9.0.1",
|
||||
"@unocss/cli": "0.50.6",
|
||||
"@unocss/preset-icons": "0.50.6",
|
||||
"@unocss/cli": "0.51.4",
|
||||
"@unocss/preset-icons": "0.51.4",
|
||||
"@vitejs/plugin-react": "3.1.0",
|
||||
"autoprefixer": "10.4.14",
|
||||
"babel-loader": "^9.1.2",
|
||||
"cross-spawn": "7.0.3",
|
||||
"esbuild": "0.17.15",
|
||||
"esbuild": "0.17.16",
|
||||
"esbuild-register": "3.4.2",
|
||||
"eslint": "8.37.0",
|
||||
"eslint": "8.38.0",
|
||||
"eslint-config-next": "13.3.0",
|
||||
"husky": "8.0.3",
|
||||
"lint-staged": "13.2.0",
|
||||
"lint-staged": "13.2.1",
|
||||
"next-pwa": "^5.6.0",
|
||||
"postcss-import": "15.1.0",
|
||||
"prettier": "2.8.7",
|
||||
"prisma": "^4.12.0",
|
||||
"tailwindcss": "3.3.1",
|
||||
"typescript": "5.0.3",
|
||||
"unocss": "0.50.6",
|
||||
"vitest": "0.29.8"
|
||||
"typescript": "5.0.4",
|
||||
"unocss": "0.51.4",
|
||||
"vitest": "0.30.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=15"
|
||||
|
||||
Generated
+1048
-1079
File diff suppressed because it is too large
Load Diff
@@ -6,5 +6,5 @@
|
||||
"load more": "まだ{{count}}件の{{name}}があります。",
|
||||
"signed and stored on the blockchain": "{{name}}は、創作者によって署名され、ブロックチェーンに安全に保存されています。",
|
||||
"Write a comment on the blockchain": "ブロックチェーンでコメントする",
|
||||
"powered by": "このサイトは <name/> によって作動します"
|
||||
"powered by": "<span>このサイトは </span><name/><span> によって作動します</span>"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"load more": "還有{{count}}篇{{name}},點選載入更多文章",
|
||||
"signed and stored on the blockchain": "此{{name}}已由它的創作者簽名並安全儲存在區塊鏈上。",
|
||||
"Write a comment on the blockchain": "在區塊鏈上留言。",
|
||||
"powered by": "由 <name/> 提供支援",
|
||||
"powered by": "<span>由 </span><name/><span> 提供支援</span>",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public. The expected online address is:": "此地址處於本地編輯預覽模式,尚未公開。預期的上線地址是:",
|
||||
"View on xChar": "在 xChar 上檢視",
|
||||
"View on xFeed": "在 xFeed 上檢視",
|
||||
|
||||
@@ -75,5 +75,7 @@
|
||||
"Successfully followed": "嘿!你已经准备好<2>在这里跟上你关注的博主的最新动态</2>了。",
|
||||
"Enable AI Filtering": "启用 AI 过滤",
|
||||
"Filter out possible low-quality content based on AI ratings.": "基于 AI 评分过滤可能质量不佳的内容。",
|
||||
"Refreshing": "刷新中"
|
||||
"Refreshing": "刷新中",
|
||||
"Search for your interest": "搜索你感兴趣的内容",
|
||||
"results": "条结果"
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
"load more": "还有 {{count}} 篇{{name}},点击加载更多",
|
||||
"signed and stored on the blockchain": "此{{name}}已经由它的创作者签名并安全地存储在区块链上。",
|
||||
"Write a comment on the blockchain": "在区块链上写下你的评论",
|
||||
"powered by": "由 <name/> 提供支持",
|
||||
"powered by": "<span>由 </span><name/><span> 提供支持</span>",
|
||||
"This address is in local editing preview mode and cannot be viewed by the public. The expected online address is:":
|
||||
"此地址处于本地编辑预览模式,无法被公众查看。预期的在线地址是:",
|
||||
"View on xChar": "在 xChar 上查看",
|
||||
@@ -14,5 +14,6 @@
|
||||
"View on Hoot It": "在 Hoot It 上查看",
|
||||
"View on Crossbell Scan": "在 Crossbell Scan 上查看",
|
||||
"Subscribe to JSON Feed": "订阅 JSON Feed",
|
||||
"Subscribe to RSS": "订阅 RSS"
|
||||
"Subscribe to RSS": "订阅 RSS",
|
||||
"Search on this site": "在本站搜索"
|
||||
}
|
||||
@@ -42,22 +42,24 @@ export const CommentInput: React.FC<{
|
||||
})
|
||||
|
||||
const handleSubmit = form.handleSubmit(async (values) => {
|
||||
if (pageId && values.content) {
|
||||
if (pageId) {
|
||||
if (comment) {
|
||||
updateComment.mutate({
|
||||
pageId,
|
||||
content: values.content,
|
||||
externalUrl: window.location.href,
|
||||
originalId,
|
||||
characterId: comment.characterId,
|
||||
noteId: comment.noteId,
|
||||
})
|
||||
if (values.content) {
|
||||
updateComment.mutate({
|
||||
pageId,
|
||||
content: values.content,
|
||||
externalUrl: window.location.href,
|
||||
originalId,
|
||||
characterId: comment.characterId,
|
||||
noteId: comment.noteId,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
commentPage.mutate({
|
||||
pageId,
|
||||
pageId: pageId,
|
||||
content: values.content,
|
||||
externalUrl: window.location.href,
|
||||
originalId,
|
||||
originalId: originalId,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useRouter } from "next/router"
|
||||
import { useTranslation } from "next-i18next"
|
||||
import { cn } from "~/lib/utils"
|
||||
|
||||
export const SearchInput: React.FC<{
|
||||
value?: string
|
||||
noBorder?: boolean
|
||||
onSubmit?: (value?: string) => void
|
||||
}> = ({ value, noBorder, onSubmit }) => {
|
||||
const router = useRouter()
|
||||
const { t } = useTranslation(["common", "site"])
|
||||
|
||||
const form = useForm({
|
||||
defaultValues: {
|
||||
content: value || "",
|
||||
},
|
||||
})
|
||||
|
||||
const handleSubmit = form.handleSubmit(async (values) => {
|
||||
router.push(`/search?q=${values.content}`)
|
||||
onSubmit?.(values.content)
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="xlog-comment-input flex">
|
||||
<form className="w-full relative" onSubmit={handleSubmit}>
|
||||
<div
|
||||
className="absolute left-0 top-1/2 -translate-y-1/2 text-2xl text-zinc-500 h-11 w-14 flex items-center justify-center cursor-pointer"
|
||||
onClick={handleSubmit}
|
||||
>
|
||||
<i className="i-mingcute:search-line block" />
|
||||
</div>
|
||||
<input
|
||||
id="content"
|
||||
className={cn(
|
||||
"w-full pl-12 pr-5 h-11 outline-none",
|
||||
!noBorder &&
|
||||
"border rounded-full hover:shadow-md focus:shadow-md transition-shadow",
|
||||
)}
|
||||
placeholder={t("Search for your interest") || ""}
|
||||
{...form.register("content", {})}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -140,7 +140,8 @@ const Post = ({
|
||||
export const MainFeed: React.FC<{
|
||||
type?: FeedType
|
||||
noteIds?: string[]
|
||||
}> = ({ type, noteIds }) => {
|
||||
keyword?: string
|
||||
}> = ({ type, noteIds, keyword }) => {
|
||||
const { t } = useTranslation(["common", "site"])
|
||||
|
||||
const currentCharacterId = useAccountState(
|
||||
@@ -154,6 +155,7 @@ export const MainFeed: React.FC<{
|
||||
characterId: currentCharacterId,
|
||||
noteIds: noteIds,
|
||||
daysInterval: hotInterval,
|
||||
keyword: keyword,
|
||||
})
|
||||
|
||||
const hasFiltering = type === "latest"
|
||||
@@ -244,7 +246,7 @@ export const MainFeed: React.FC<{
|
||||
) : !feed.data?.pages[0]?.count ? (
|
||||
<EmptyState />
|
||||
) : (
|
||||
<div className="xlog-posts space-y-8">
|
||||
<div className="xlog-posts space-y-8 overflow-x-hidden">
|
||||
{feed.data?.pages.map((posts) =>
|
||||
posts?.list.map((post) => {
|
||||
return (
|
||||
|
||||
@@ -11,8 +11,9 @@ import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
|
||||
import { useAccountSites, useSubscribeToSites } from "~/queries/site"
|
||||
import { useTranslation } from "next-i18next"
|
||||
import topics from "../../../data/topics.json"
|
||||
import { SearchInput } from "~/components/common/SearchInput"
|
||||
|
||||
export function MainSidebar() {
|
||||
export function MainSidebar({ hideSearch }: { hideSearch?: boolean }) {
|
||||
const showcaseSites = useGetSites(showcase)
|
||||
const { t } = useTranslation("index")
|
||||
|
||||
@@ -36,9 +37,10 @@ export function MainSidebar() {
|
||||
const [showcaseMore, setShowcaseMore] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="w-80 pl-10 pt-4 hidden sm:block">
|
||||
<div className="w-80 pl-10 hidden sm:block space-y-10">
|
||||
{!hideSearch && <SearchInput />}
|
||||
<div className="text-center">
|
||||
<div className="mb-10 text-zinc-700 space-y-3">
|
||||
<div className="text-zinc-700 space-y-3">
|
||||
<p className="font-bold text-lg">{t("Hot Topics")}</p>
|
||||
<ul className="overflow-y-clip relative text-left space-y-2">
|
||||
{topics.map((topic: any) => (
|
||||
@@ -58,7 +60,7 @@ export function MainSidebar() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<div className="mb-10 text-zinc-700 space-y-3">
|
||||
<div className="text-zinc-700 space-y-3">
|
||||
<p className="font-bold text-lg">{t("Suggested creators for you")}</p>
|
||||
<Button
|
||||
onClick={followAll}
|
||||
|
||||
@@ -34,16 +34,17 @@ export const SiteFooter: React.FC<{
|
||||
<footer className="text-zinc-500 border-t">
|
||||
<div className="max-w-screen-md mx-auto px-5 py-10 text-xs flex justify-between">
|
||||
<div className="font-medium text-base">
|
||||
©{" "}
|
||||
<span>© </span>
|
||||
<UniLink href="/" className="hover:text-accent">
|
||||
{site?.name}
|
||||
</UniLink>{" "}
|
||||
·{" "}
|
||||
<span>{site?.name}</span>
|
||||
</UniLink>
|
||||
<span> · </span>
|
||||
<Trans
|
||||
i18nKey="powered by"
|
||||
defaults={"Powered by <name/>"}
|
||||
defaults={"<span>Powered by </span><name/>"}
|
||||
components={{
|
||||
name: <LogoWithLink />,
|
||||
span: <span />,
|
||||
}}
|
||||
ns="site"
|
||||
/>
|
||||
|
||||
@@ -20,6 +20,8 @@ import { Menu } from "~/components/ui/Menu"
|
||||
import { useTranslation } from "next-i18next"
|
||||
import { Tooltip } from "~/components/ui/Tooltip"
|
||||
import { PatronButton } from "~/components/common/PatronButton"
|
||||
import { Modal } from "~/components/ui/Modal"
|
||||
import { SearchInput } from "~/components/common/SearchInput"
|
||||
|
||||
type HeaderLinkType = {
|
||||
icon?: React.ReactNode
|
||||
@@ -113,8 +115,20 @@ export const SiteHeader: React.FC<{
|
||||
url: `/feed/xml`,
|
||||
out: true,
|
||||
},
|
||||
{
|
||||
text: "Search on this site",
|
||||
icon: (
|
||||
<span className="text-stone-400">
|
||||
<i className="i-mingcute:search-line block" />
|
||||
</span>
|
||||
),
|
||||
onClick: () => setSearchOpen(true),
|
||||
out: true,
|
||||
},
|
||||
]
|
||||
|
||||
const [searchOpen, setSearchOpen] = useState(false)
|
||||
|
||||
const avatarRef = useRef<HTMLImageElement>(null)
|
||||
const bannerRef = useRef<HTMLImageElement | HTMLVideoElement>(null)
|
||||
|
||||
@@ -239,9 +253,10 @@ export const SiteHeader: React.FC<{
|
||||
<UniLink
|
||||
key={item.text}
|
||||
href={item.url}
|
||||
onClick={item.onClick}
|
||||
className="h-10 flex w-full space-x-2 items-center px-3 hover:bg-hover"
|
||||
>
|
||||
<span className="fill-gray-500 flex w-4 h-4">
|
||||
<span className="fill-gray-500 flex items-center w-4 h-4 text-base leading-none">
|
||||
{item.icon}
|
||||
</span>
|
||||
<span>{t(item.text)}</span>
|
||||
@@ -253,30 +268,35 @@ export const SiteHeader: React.FC<{
|
||||
/>
|
||||
</div>
|
||||
<div className="xlog-site-more-out hidden sm:block">
|
||||
{moreMenuItems.map((item) => {
|
||||
if (item.out) {
|
||||
return (
|
||||
<Tooltip
|
||||
label={t(item.text)}
|
||||
key={item.text}
|
||||
placement="bottom"
|
||||
>
|
||||
<Button
|
||||
variant="text"
|
||||
aria-label={item.text}
|
||||
className="-mx-2"
|
||||
onClick={() => window.open(item.url, "_blank")}
|
||||
<div className="-mx-2 flex">
|
||||
{moreMenuItems.map((item) => {
|
||||
if (item.out) {
|
||||
return (
|
||||
<Tooltip
|
||||
label={t(item.text)}
|
||||
key={item.text}
|
||||
placement="bottom"
|
||||
>
|
||||
<span className="fill-gray-500 flex w-6 h-6">
|
||||
{item.icon}
|
||||
</span>
|
||||
</Button>
|
||||
</Tooltip>
|
||||
)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
})}
|
||||
<Button
|
||||
variant="text"
|
||||
aria-label={item.text}
|
||||
onClick={() =>
|
||||
item.url
|
||||
? window.open(item.url, "_blank")
|
||||
: item.onClick?.()
|
||||
}
|
||||
>
|
||||
<span className="fill-gray-500 flex w-6 h-6 text-2xl">
|
||||
{item.icon}
|
||||
</span>
|
||||
</Button>
|
||||
</Tooltip>
|
||||
)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="xlog-site-follow-button">
|
||||
<FollowingButton site={site} />
|
||||
@@ -311,6 +331,11 @@ export const SiteHeader: React.FC<{
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Modal open={searchOpen} setOpen={setSearchOpen}>
|
||||
<div className="p-3">
|
||||
<SearchInput noBorder={true} onSubmit={() => setSearchOpen(false)} />
|
||||
</div>
|
||||
</Modal>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import Link from "next/link"
|
||||
import { useDate } from "~/hooks/useDate"
|
||||
import { ExpandedNote, Notes } from "~/lib/types"
|
||||
import { EmptyState } from "../ui/EmptyState"
|
||||
import { useRouter } from "next/router"
|
||||
import { Image } from "~/components/ui/Image"
|
||||
import { Button } from "~/components/ui/Button"
|
||||
import { useTranslation } from "next-i18next"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
export const SiteSearch: React.FC<{
|
||||
postPages?: {
|
||||
list: ExpandedNote[]
|
||||
count: number
|
||||
cursor: string | null
|
||||
}[]
|
||||
fetchNextPage: () => void
|
||||
hasNextPage?: boolean
|
||||
isFetchingNextPage?: boolean
|
||||
}> = ({ postPages, fetchNextPage, hasNextPage, isFetchingNextPage }) => {
|
||||
const router = useRouter()
|
||||
const { t } = useTranslation(["common", "site"])
|
||||
const date = useDate()
|
||||
|
||||
const [isMounted, setIsMounted] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
setIsMounted(true)
|
||||
}, [])
|
||||
|
||||
if (!postPages?.length) return null
|
||||
|
||||
let currentLength = 0
|
||||
|
||||
return (
|
||||
<>
|
||||
{!postPages[0].count && <EmptyState />}
|
||||
{!!postPages[0].count && (
|
||||
<div className="xlog-posts space-y-8">
|
||||
{postPages.map((posts) =>
|
||||
posts.list.map((post) => {
|
||||
currentLength++
|
||||
return (
|
||||
<Link
|
||||
key={post.noteId}
|
||||
href={`/${post.metadata.content.slug}`}
|
||||
className="xlog-post sm:hover:bg-hover bg-white transition-all px-5 py-7 -mx-5 first:-mt-5 sm:rounded-xl flex flex-col sm:flex-row items-center"
|
||||
>
|
||||
<div className="flex-1 flex justify-center flex-col w-full min-w-0">
|
||||
<h3 className="xlog-post-title text-2xl font-bold text-zinc-700">
|
||||
{post.metadata.content.title}
|
||||
</h3>
|
||||
<div className="xlog-post-meta text-sm text-zinc-400 mt-1 space-x-4 flex items-center mr-8">
|
||||
<time
|
||||
dateTime={date.formatToISO(
|
||||
post.metadata.content.date_published ||
|
||||
post.createdAt,
|
||||
)}
|
||||
className="xlog-post-date whitespace-nowrap"
|
||||
>
|
||||
{date.formatDate(
|
||||
post.metadata.content.date_published ||
|
||||
post.createdAt,
|
||||
undefined,
|
||||
isMounted ? undefined : "America/Los_Angeles",
|
||||
)}
|
||||
</time>
|
||||
{!!post.metadata.content.tags?.filter(
|
||||
(tag) => tag !== "post" && tag !== "page",
|
||||
).length && (
|
||||
<span className="xlog-post-tags space-x-1 truncate min-w-0">
|
||||
{post.metadata.content.tags
|
||||
?.filter((tag) => tag !== "post" && tag !== "page")
|
||||
.map((tag) => (
|
||||
<span
|
||||
className="hover:text-zinc-600"
|
||||
key={tag}
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
router.push(`/tag/${tag}`)
|
||||
}}
|
||||
>
|
||||
#{tag}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
<span className="xlog-post-views inline-flex items-center">
|
||||
<i className="i-mingcute:eye-line mr-[2px]" />
|
||||
<span>{post.metadata.content.views}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className="xlog-post-excerpt mt-3 text-zinc-500 line-clamp-2"
|
||||
style={{
|
||||
wordBreak: "break-word",
|
||||
}}
|
||||
>
|
||||
{post.metadata.content.summary}
|
||||
{post.metadata.content.summary && "..."}
|
||||
</div>
|
||||
</div>
|
||||
{post.metadata.content.cover && (
|
||||
<div className="xlog-post-cover flex items-center relative w-full sm:w-24 h-40 sm:h-24 mt-2 sm:ml-4 sm:mt-0">
|
||||
<Image
|
||||
className="object-cover rounded"
|
||||
alt="cover"
|
||||
fill={true}
|
||||
src={post.metadata.content.cover}
|
||||
></Image>
|
||||
</div>
|
||||
)}
|
||||
</Link>
|
||||
)
|
||||
}),
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{hasNextPage && (
|
||||
<Button
|
||||
className="mt-8 w-full bg-zinc-50 text-sm"
|
||||
variant="text"
|
||||
onClick={fetchNextPage}
|
||||
isLoading={isFetchingNextPage}
|
||||
aria-label="load more"
|
||||
>
|
||||
{t("load more", {
|
||||
ns: "site",
|
||||
name: t(
|
||||
"post" + (postPages[0].count - currentLength > 1 ? "s" : ""),
|
||||
),
|
||||
count: postPages[0].count - currentLength,
|
||||
})}
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import getConfig from "next/config"
|
||||
|
||||
const config = getConfig()
|
||||
const config = getConfig() || {}
|
||||
|
||||
export const REDIS_URL = config.ENV_REDIS_URL || process.env.REDIS_URL
|
||||
export const REDIS_EXPIRE =
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
import { Note, Profile } from "~/lib/types"
|
||||
import { nanoid } from "nanoid"
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
import { SITE_URL, SCORE_API_DOMAIN } from "~/lib/env"
|
||||
import { toCid } from "~/lib/ipfs-parser"
|
||||
import { ExpandedNote } from "~/lib/types"
|
||||
|
||||
export const expandUnidataNote = async (page: Note, useStat?: boolean) => {
|
||||
if (page.body?.content && page.body?.mime_type === "text/markdown") {
|
||||
const { renderPageContent } = await import("~/markdown")
|
||||
const rendered = renderPageContent(page.body.content, true)
|
||||
page.body = {
|
||||
content: page.body.content,
|
||||
mime_type: "text/markdown",
|
||||
}
|
||||
if (!page.summary) {
|
||||
page.summary = {
|
||||
content: rendered.excerpt,
|
||||
mime_type: "text/html",
|
||||
}
|
||||
}
|
||||
page.cover = rendered.cover
|
||||
if (page.metadata) {
|
||||
page.metadata.frontMatter = rendered.frontMatter
|
||||
}
|
||||
}
|
||||
page.slug = encodeURIComponent(
|
||||
page.attributes?.find((a) => a.trait_type === "xlog_slug")?.value ||
|
||||
page.metadata?.raw?._xlog_slug ||
|
||||
page.metadata?.raw?._crosslog_slug ||
|
||||
"",
|
||||
)
|
||||
delete page.metadata?.raw
|
||||
|
||||
if (useStat) {
|
||||
const stat = await (
|
||||
await fetch(
|
||||
`https://indexer.crossbell.io/v1/stat/notes/${page.id.replace(
|
||||
"-",
|
||||
"/",
|
||||
)}`,
|
||||
)
|
||||
).json()
|
||||
page.views = stat.viewDetailCount
|
||||
}
|
||||
|
||||
return page
|
||||
}
|
||||
|
||||
export const expandUnidataProfile = (site: Profile) => {
|
||||
site.navigation = JSON.parse(
|
||||
site.metadata?.raw?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_navigation",
|
||||
)?.value || "null",
|
||||
) ||
|
||||
site.metadata?.raw?.["_xlog_navigation"] ||
|
||||
site.metadata?.raw?.["_crosslog_navigation"] || [
|
||||
{ id: nanoid(), label: "Archives", url: "/archives" },
|
||||
]
|
||||
site.css =
|
||||
site.metadata?.raw?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_css",
|
||||
)?.value ||
|
||||
site.metadata?.raw?.["_xlog_css"] ||
|
||||
site.metadata?.raw?.["_crosslog_css"] ||
|
||||
""
|
||||
site.ga =
|
||||
site.metadata?.raw?.attributes?.find((a: any) => a.trait_type === "xlog_ga")
|
||||
?.value || ""
|
||||
site.custom_domain =
|
||||
site.metadata?.raw?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value || ""
|
||||
site.name = site.name || site.username
|
||||
site.description = site.bio
|
||||
|
||||
if (site.avatars) {
|
||||
site.avatars = site.avatars.map((avatar) => toGateway(avatar))
|
||||
}
|
||||
if (site.banners) {
|
||||
site.banners.map((banner) => {
|
||||
banner.address = toGateway(banner.address)
|
||||
return banner
|
||||
})
|
||||
}
|
||||
delete site.metadata?.raw
|
||||
|
||||
return site
|
||||
}
|
||||
|
||||
export const expandCrossbellNote = async (
|
||||
page: ExpandedNote,
|
||||
useStat?: boolean,
|
||||
useScore?: boolean,
|
||||
) => {
|
||||
if (page.metadata?.content) {
|
||||
if (page.metadata?.content?.content) {
|
||||
const { renderPageContent } = await import("~/markdown")
|
||||
const rendered = renderPageContent(page.metadata.content.content, true)
|
||||
if (!page.metadata.content.summary) {
|
||||
page.metadata.content.summary = rendered.excerpt
|
||||
}
|
||||
page.metadata.content.cover = rendered.cover
|
||||
if (page.metadata) {
|
||||
page.metadata.content.frontMatter = rendered.frontMatter
|
||||
}
|
||||
}
|
||||
page.metadata.content.slug = encodeURIComponent(
|
||||
page.metadata.content.attributes?.find(
|
||||
(a) => a.trait_type === "xlog_slug",
|
||||
)?.value || "",
|
||||
)
|
||||
|
||||
if (useStat) {
|
||||
const stat = await (
|
||||
await fetch(
|
||||
`https://indexer.crossbell.io/v1/stat/notes/${page.characterId}/${page.noteId}`,
|
||||
)
|
||||
).json()
|
||||
page.metadata.content.views = stat.viewDetailCount
|
||||
}
|
||||
|
||||
if (useScore) {
|
||||
try {
|
||||
const score = (
|
||||
await (
|
||||
await fetch(
|
||||
`${SCORE_API_DOMAIN || SITE_URL}/api/score?cid=${toCid(
|
||||
page.metadata?.uri || "",
|
||||
)}`,
|
||||
)
|
||||
).json()
|
||||
).data
|
||||
page.metadata.content.score = score
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return page
|
||||
}
|
||||
@@ -12,6 +12,7 @@ const slugReservedWords = [
|
||||
"sw.js",
|
||||
"manifest.json",
|
||||
"atom.xml",
|
||||
"search",
|
||||
]
|
||||
|
||||
export const checkSlugReservedWords = (word: string) => {
|
||||
|
||||
+33
-10
@@ -3,8 +3,9 @@ import { renderPageContent } from "./index"
|
||||
|
||||
describe("html", () => {
|
||||
test("simple", async () => {
|
||||
const { contentHTML, excerpt } = await renderPageContent(`
|
||||
# Hello
|
||||
const { contentHTML, excerpt } = await renderPageContent(
|
||||
`
|
||||
# Hello
|
||||
|
||||
This is the **excerpt**
|
||||
|
||||
@@ -30,30 +31,52 @@ describe("html", () => {
|
||||
\`\`\`
|
||||
<script>alert('xss')</script>
|
||||
\`\`\`
|
||||
`)
|
||||
`,
|
||||
true,
|
||||
)
|
||||
|
||||
expect(contentHTML).not.toMatch(/<script>/)
|
||||
expect(excerpt).toEqual(`This is the excerpt`)
|
||||
expect(excerpt).toMatchInlineSnapshot(`
|
||||
"This is the excerpt Hello Blockquote foo
|
||||
|
||||
task list done
|
||||
my caption
|
||||
Copy
|
||||
function foo() {}
|
||||
|
||||
<script>alert('xss')</script>
|
||||
|
||||
C…"
|
||||
`)
|
||||
})
|
||||
|
||||
test("wrap table", async () => {
|
||||
const { contentHTML } = await renderPageContent(`
|
||||
|a|b|
|
||||
const { contentHTML } = await renderPageContent(
|
||||
`|a|b|
|
||||
|---|---|
|
||||
|c|d|
|
||||
`)
|
||||
expect(contentHTML).toMatch(`<div class="table-wrapper">`)
|
||||
`,
|
||||
true,
|
||||
)
|
||||
expect(contentHTML.trim()).toMatchInlineSnapshot(
|
||||
'"<div class=\\"table-wrapper\\"><table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>c</td><td>d</td></tr></tbody></table></div>"',
|
||||
)
|
||||
})
|
||||
|
||||
test("callout", async () => {
|
||||
const { contentHTML } = await renderPageContent(`
|
||||
const { contentHTML } = await renderPageContent(
|
||||
`
|
||||
> TIP:
|
||||
>
|
||||
> Some tip!
|
||||
|
||||
> WARN:
|
||||
>
|
||||
> Some warning!
|
||||
`)
|
||||
`,
|
||||
true,
|
||||
)
|
||||
|
||||
expect(contentHTML).toMatchInlineSnapshot(`
|
||||
"<blockquote class=\\"callout callout-tip\\">
|
||||
<p>Some tip!</p>
|
||||
|
||||
+31
-60
@@ -1,64 +1,10 @@
|
||||
import { ExpandedNote } from "~/lib/types"
|
||||
import { indexer } from "@crossbell/indexer"
|
||||
import { toCid } from "~/lib/ipfs-parser"
|
||||
import { createClient, cacheExchange, fetchExchange } from "@urql/core"
|
||||
import { SITE_URL, SCORE_API_DOMAIN } from "~/lib/env"
|
||||
import dayjs from "dayjs"
|
||||
import { expandCrossbellNote } from "~/lib/expand-unit"
|
||||
|
||||
const expandPage = async (
|
||||
page: ExpandedNote,
|
||||
useStat?: boolean,
|
||||
useScore?: boolean,
|
||||
) => {
|
||||
if (page.metadata?.content) {
|
||||
if (page.metadata?.content?.content) {
|
||||
const { renderPageContent } = await import("~/markdown")
|
||||
const rendered = renderPageContent(page.metadata.content.content, true)
|
||||
if (!page.metadata.content.summary) {
|
||||
page.metadata.content.summary = rendered.excerpt
|
||||
}
|
||||
page.metadata.content.cover = rendered.cover
|
||||
if (page.metadata) {
|
||||
page.metadata.content.frontMatter = rendered.frontMatter
|
||||
}
|
||||
}
|
||||
page.metadata.content.slug = encodeURIComponent(
|
||||
page.metadata.content.attributes?.find(
|
||||
(a) => a.trait_type === "xlog_slug",
|
||||
)?.value || "",
|
||||
)
|
||||
|
||||
if (useStat) {
|
||||
const stat = await (
|
||||
await fetch(
|
||||
`https://indexer.crossbell.io/v1/stat/notes/${page.characterId}/${page.noteId}`,
|
||||
)
|
||||
).json()
|
||||
page.metadata.content.views = stat.viewDetailCount
|
||||
}
|
||||
|
||||
if (useScore) {
|
||||
try {
|
||||
const score = (
|
||||
await (
|
||||
await fetch(
|
||||
`${SCORE_API_DOMAIN || SITE_URL}/api/score?cid=${toCid(
|
||||
page.metadata?.uri || "",
|
||||
)}`,
|
||||
)
|
||||
).json()
|
||||
).data
|
||||
page.metadata.content.score = score
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return page
|
||||
}
|
||||
|
||||
export type FeedType = "latest" | "following" | "topic" | "hot"
|
||||
export type FeedType = "latest" | "following" | "topic" | "hot" | "search"
|
||||
|
||||
export async function getFeed({
|
||||
type,
|
||||
@@ -67,6 +13,7 @@ export async function getFeed({
|
||||
characterId,
|
||||
noteIds,
|
||||
daysInterval,
|
||||
keyword,
|
||||
}: {
|
||||
type?: FeedType
|
||||
cursor?: string
|
||||
@@ -74,7 +21,11 @@ export async function getFeed({
|
||||
characterId?: number
|
||||
noteIds?: string[]
|
||||
daysInterval?: number
|
||||
keyword?: string
|
||||
}) {
|
||||
if (type === "search" && !keyword) {
|
||||
type = "latest"
|
||||
}
|
||||
switch (type) {
|
||||
case "latest": {
|
||||
const result = await indexer.getNotes({
|
||||
@@ -87,7 +38,7 @@ export async function getFeed({
|
||||
|
||||
const list = await Promise.all(
|
||||
result.list.map(async (page: any) => {
|
||||
return await expandPage(page, false, true)
|
||||
return await expandCrossbellNote(page, false, true)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -115,7 +66,7 @@ export async function getFeed({
|
||||
|
||||
const list = await Promise.all(
|
||||
result.list.map(async (page: any) => {
|
||||
return await expandPage(page)
|
||||
return await expandCrossbellNote(page)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -181,7 +132,7 @@ export async function getFeed({
|
||||
|
||||
const list = await Promise.all(
|
||||
result?.data?.notes.map(async (page: any) => {
|
||||
return await expandPage(page)
|
||||
return await expandCrossbellNote(page)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -245,7 +196,7 @@ export async function getFeed({
|
||||
page.stat.viewDetailCount / Math.max(Math.log10(secondAgo), 1)
|
||||
}
|
||||
|
||||
return await expandPage(page)
|
||||
return await expandCrossbellNote(page)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -265,5 +216,25 @@ export async function getFeed({
|
||||
count: list?.length || 0,
|
||||
}
|
||||
}
|
||||
case "search": {
|
||||
const result = await indexer.searchNotes(keyword!, {
|
||||
sources: ["xlog"],
|
||||
tags: ["post"],
|
||||
limit: limit,
|
||||
cursor,
|
||||
})
|
||||
|
||||
const list = await Promise.all(
|
||||
result.list.map(async (page: any) => {
|
||||
return await expandCrossbellNote(page)
|
||||
}),
|
||||
)
|
||||
|
||||
return {
|
||||
list,
|
||||
cursor: result.cursor,
|
||||
count: result.count,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
-52
@@ -1,20 +1,15 @@
|
||||
import { notFound } from "~/lib/server-side-props"
|
||||
import { PageVisibilityEnum, Notes, Note } from "~/lib/types"
|
||||
import { PageVisibilityEnum, Notes, Note, ExpandedNote } from "~/lib/types"
|
||||
import unidata from "~/queries/unidata.server"
|
||||
import { indexer } from "@crossbell/indexer"
|
||||
import {
|
||||
NoteEntity,
|
||||
CharacterEntity,
|
||||
ListResponse,
|
||||
NoteMetadata,
|
||||
} from "crossbell.js"
|
||||
import { NoteMetadata } from "crossbell.js"
|
||||
import { getStorage, getKeys } from "~/lib/storage"
|
||||
import axios from "axios"
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
import type Unidata from "unidata.js"
|
||||
import type { Contract } from "crossbell.js"
|
||||
import { checkSlugReservedWords } from "~/lib/slug-reserved-words"
|
||||
import { GeneralAccount } from "@crossbell/connect-kit"
|
||||
import { expandUnidataNote, expandCrossbellNote } from "~/lib/expand-unit"
|
||||
|
||||
export async function checkPageSlug(
|
||||
input: {
|
||||
@@ -146,48 +141,6 @@ export async function postNotes(
|
||||
)
|
||||
}
|
||||
|
||||
const expandPage = async (page: Note, useStat?: boolean) => {
|
||||
if (page.body?.content && page.body?.mime_type === "text/markdown") {
|
||||
const { renderPageContent } = await import("~/markdown")
|
||||
const rendered = renderPageContent(page.body.content, true)
|
||||
page.body = {
|
||||
content: page.body.content,
|
||||
mime_type: "text/markdown",
|
||||
}
|
||||
if (!page.summary) {
|
||||
page.summary = {
|
||||
content: rendered.excerpt,
|
||||
mime_type: "text/html",
|
||||
}
|
||||
}
|
||||
page.cover = rendered.cover
|
||||
if (page.metadata) {
|
||||
page.metadata.frontMatter = rendered.frontMatter
|
||||
}
|
||||
}
|
||||
page.slug = encodeURIComponent(
|
||||
page.attributes?.find((a) => a.trait_type === "xlog_slug")?.value ||
|
||||
page.metadata?.raw?._xlog_slug ||
|
||||
page.metadata?.raw?._crosslog_slug ||
|
||||
"",
|
||||
)
|
||||
delete page.metadata?.raw
|
||||
|
||||
if (useStat) {
|
||||
const stat = await (
|
||||
await fetch(
|
||||
`https://indexer.crossbell.io/v1/stat/notes/${page.id.replace(
|
||||
"-",
|
||||
"/",
|
||||
)}`,
|
||||
)
|
||||
).json()
|
||||
page.views = stat.viewDetailCount
|
||||
}
|
||||
|
||||
return page
|
||||
}
|
||||
|
||||
const getLocalPages = (input: { site: string; isPost?: boolean }) => {
|
||||
const pages: Note[] = []
|
||||
getKeys(`draft-${input.site}-`).forEach((key) => {
|
||||
@@ -329,7 +282,7 @@ export async function getPagesBySite(
|
||||
|
||||
await Promise.all(
|
||||
pages?.list.map(async (page) => {
|
||||
await expandPage(page, input.useStat)
|
||||
await expandUnidataNote(page, input.useStat)
|
||||
|
||||
if (!input.keepBody) {
|
||||
delete page.body
|
||||
@@ -343,6 +296,31 @@ export async function getPagesBySite(
|
||||
return pages
|
||||
}
|
||||
|
||||
export async function getSearchPagesBySite(input: {
|
||||
characterId?: string
|
||||
keyword?: string
|
||||
cursor?: string
|
||||
}) {
|
||||
const result = await indexer.searchNotes(input.keyword || "", {
|
||||
cursor: input.cursor,
|
||||
characterId: input.characterId,
|
||||
tags: ["post"],
|
||||
sources: ["xlog"],
|
||||
})
|
||||
|
||||
const list: ExpandedNote[] = await Promise.all(
|
||||
result.list.map(async (page: any) => {
|
||||
return await expandCrossbellNote(page, true)
|
||||
}),
|
||||
)
|
||||
|
||||
return {
|
||||
list,
|
||||
cursor: result.cursor,
|
||||
count: result.count,
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPage<TRender extends boolean = false>(
|
||||
input: {
|
||||
/** page slug or id, `site` is needed when `page` is a slug */
|
||||
@@ -413,7 +391,7 @@ export async function getPage<TRender extends boolean = false>(
|
||||
}
|
||||
|
||||
if (page) {
|
||||
await expandPage(page, input.useStat)
|
||||
await expandUnidataNote(page, input.useStat)
|
||||
}
|
||||
|
||||
return page
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { SiteNavigationItem, Profile } from "~/lib/types"
|
||||
import { nanoid } from "nanoid"
|
||||
import unidata from "~/queries/unidata.server"
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
import type Unidata from "unidata.js"
|
||||
import type { Profiles as UniProfiles } from "unidata.js"
|
||||
import { createClient, cacheExchange, fetchExchange } from "@urql/core"
|
||||
@@ -9,52 +8,12 @@ import { Indexer } from "crossbell.js"
|
||||
import { CharacterOperatorPermission } from "crossbell.js"
|
||||
import type { useContract } from "@crossbell/contract"
|
||||
import dayjs from "dayjs"
|
||||
import { expandUnidataProfile } from "~/lib/expand-unit"
|
||||
|
||||
type Contract = ReturnType<typeof useContract>
|
||||
|
||||
const indexer = new Indexer()
|
||||
|
||||
const expandSite = (site: Profile) => {
|
||||
site.navigation = JSON.parse(
|
||||
site.metadata?.raw?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_navigation",
|
||||
)?.value || "null",
|
||||
) ||
|
||||
site.metadata?.raw?.["_xlog_navigation"] ||
|
||||
site.metadata?.raw?.["_crosslog_navigation"] || [
|
||||
{ id: nanoid(), label: "Archives", url: "/archives" },
|
||||
]
|
||||
site.css =
|
||||
site.metadata?.raw?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_css",
|
||||
)?.value ||
|
||||
site.metadata?.raw?.["_xlog_css"] ||
|
||||
site.metadata?.raw?.["_crosslog_css"] ||
|
||||
""
|
||||
site.ga =
|
||||
site.metadata?.raw?.attributes?.find((a: any) => a.trait_type === "xlog_ga")
|
||||
?.value || ""
|
||||
site.custom_domain =
|
||||
site.metadata?.raw?.attributes?.find(
|
||||
(a: any) => a.trait_type === "xlog_custom_domain",
|
||||
)?.value || ""
|
||||
site.name = site.name || site.username
|
||||
site.description = site.bio
|
||||
|
||||
if (site.avatars) {
|
||||
site.avatars = site.avatars.map((avatar) => toGateway(avatar))
|
||||
}
|
||||
if (site.banners) {
|
||||
site.banners.map((banner) => {
|
||||
banner.address = toGateway(banner.address)
|
||||
return banner
|
||||
})
|
||||
}
|
||||
delete site.metadata?.raw
|
||||
|
||||
return site
|
||||
}
|
||||
|
||||
export type GetUserSitesParams =
|
||||
| {
|
||||
address: string
|
||||
@@ -95,7 +54,7 @@ export const getUserSites = async (params: GetUserSitesParams) => {
|
||||
|
||||
const sites: Profile[] =
|
||||
profiles?.list?.map((profile) => {
|
||||
expandSite(profile)
|
||||
expandUnidataProfile(profile)
|
||||
return profile
|
||||
}) ?? []
|
||||
|
||||
@@ -125,7 +84,7 @@ export const getSite = async (input: string, customUnidata?: Unidata) => {
|
||||
|
||||
const site: Profile = profiles.list[0]
|
||||
if (site) {
|
||||
expandSite(site)
|
||||
expandUnidataProfile(site)
|
||||
}
|
||||
|
||||
return site
|
||||
|
||||
+3
-2
@@ -19,6 +19,7 @@ import { APP_NAME, IPFS_GATEWAY } from "~/lib/env"
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
import { createIDBPersister } from "~/lib/persister.client"
|
||||
import { urlComposer } from "~/lib/url-composer"
|
||||
import { AppPropsWithLayout } from "types/next"
|
||||
|
||||
Network.setIpfsGateway(IPFS_GATEWAY)
|
||||
|
||||
@@ -34,8 +35,8 @@ const queryClient = new QueryClient({
|
||||
|
||||
const persister = createIDBPersister()
|
||||
|
||||
function MyApp({ Component, pageProps }: any) {
|
||||
const getLayout = Component.getLayout ?? ((page: any) => page)
|
||||
function MyApp({ Component, pageProps }: AppPropsWithLayout) {
|
||||
const getLayout = Component.getLayout ?? ((page) => page)
|
||||
|
||||
return (
|
||||
<WagmiConfig client={wagmiClient}>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { GetServerSideProps } from "next"
|
||||
import { SiteSearch } from "~/components/site/SiteSearch"
|
||||
import { SiteLayout } from "~/components/site/SiteLayout"
|
||||
import { getServerSideProps as getLayoutServerSideProps } from "~/components/site/SiteLayout.server"
|
||||
import { QueryClient } from "@tanstack/react-query"
|
||||
import { useGetSearchPagesBySite } from "~/queries/page"
|
||||
import type { ReactElement } from "react"
|
||||
import { useGetSite } from "~/queries/site"
|
||||
import { useRouter } from "next/router"
|
||||
import { SearchInput } from "~/components/common/SearchInput"
|
||||
import { useTranslation } from "next-i18next"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const queryClient = new QueryClient()
|
||||
const domainOrSubdomain = ctx.params!.site as string
|
||||
const { props: layoutProps } = await getLayoutServerSideProps(
|
||||
ctx,
|
||||
queryClient,
|
||||
{
|
||||
skipPages: true,
|
||||
},
|
||||
)
|
||||
|
||||
return {
|
||||
props: {
|
||||
...layoutProps,
|
||||
domainOrSubdomain,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function SiteSearchPage({ domainOrSubdomain }: { domainOrSubdomain: string }) {
|
||||
const site = useGetSite(domainOrSubdomain)
|
||||
const router = useRouter()
|
||||
const keyword = router.query.q as string
|
||||
const { t } = useTranslation(["common"])
|
||||
|
||||
const posts = useGetSearchPagesBySite({
|
||||
characterId: site.data?.metadata?.proof,
|
||||
keyword,
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="sm:-mx-5">
|
||||
<SearchInput value={keyword} />
|
||||
</div>
|
||||
<h2 className="mb-8 mt-5 text-zinc-500">
|
||||
{posts.data?.pages?.[0].count || "0"} {t("results")}
|
||||
</h2>
|
||||
{posts.isLoading ? (
|
||||
<>{t("Loading")}...</>
|
||||
) : (
|
||||
<SiteSearch
|
||||
postPages={posts.data?.pages}
|
||||
fetchNextPage={posts.fetchNextPage}
|
||||
hasNextPage={posts.hasNextPage}
|
||||
isFetchingNextPage={posts.isFetchingNextPage}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
SiteSearchPage.getLayout = (page: ReactElement) => {
|
||||
return (
|
||||
<SiteLayout useStat={true} type="index">
|
||||
{page}
|
||||
</SiteLayout>
|
||||
)
|
||||
}
|
||||
|
||||
export default SiteSearchPage
|
||||
@@ -0,0 +1,54 @@
|
||||
import { GetServerSideProps } from "next"
|
||||
import { ReactElement, useState } from "react"
|
||||
import { MainLayout } from "~/components/main/MainLayout"
|
||||
import { dehydrate, QueryClient } from "@tanstack/react-query"
|
||||
import { prefetchGetSites } from "~/queries/site.server"
|
||||
import showcase from "../../data/showcase.json"
|
||||
import topics from "../../data/topics.json"
|
||||
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
|
||||
import { languageDetector } from "~/lib/language-detector"
|
||||
import { MainFeed } from "~/components/main/MainFeed"
|
||||
import { MainSidebar } from "~/components/main/MainSidebar"
|
||||
import { useRouter } from "next/router"
|
||||
import { SearchInput } from "~/components/common/SearchInput"
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
||||
const queryClient = new QueryClient()
|
||||
await prefetchGetSites(showcase, queryClient)
|
||||
|
||||
return {
|
||||
props: {
|
||||
...(await serverSideTranslations(languageDetector(ctx), [
|
||||
"common",
|
||||
"index",
|
||||
"dashboard",
|
||||
])),
|
||||
dehydratedState: dehydrate(queryClient),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function Search() {
|
||||
const router = useRouter()
|
||||
const keyword = router.query.q as string
|
||||
|
||||
return (
|
||||
<section className="pt-24">
|
||||
<div className="max-w-screen-lg px-5 mx-auto flex">
|
||||
<div className="flex-1 min-w-[300px]">
|
||||
<SearchInput value={keyword} />
|
||||
<div className="mt-10">
|
||||
<MainFeed type="search" keyword={keyword} />
|
||||
</div>
|
||||
</div>
|
||||
<MainSidebar hideSearch={true} />
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
Search.getLayout = (page: ReactElement) => {
|
||||
return <MainLayout>{page}</MainLayout>
|
||||
}
|
||||
|
||||
export default Search
|
||||
@@ -8,6 +8,7 @@ export const useGetFeed = (data?: {
|
||||
limit?: number
|
||||
noteIds?: string[]
|
||||
daysInterval?: number
|
||||
keyword?: string
|
||||
}) => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ["getFeed", data],
|
||||
|
||||
@@ -62,6 +62,21 @@ export const useGetPagesBySite = (
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetSearchPagesBySite = (
|
||||
input: Parameters<typeof pageModel.getSearchPagesBySite>[0],
|
||||
) => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ["getSearchPagesBySite", input.characterId, input],
|
||||
queryFn: async ({ pageParam }) => {
|
||||
return pageModel.getSearchPagesBySite({
|
||||
...input,
|
||||
cursor: pageParam,
|
||||
})
|
||||
},
|
||||
getNextPageParam: (lastPage) => lastPage.cursor || undefined,
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetPage = (input: Parameters<typeof pageModel.getPage>[0]) => {
|
||||
const unidata = useUnidata()
|
||||
return useQuery(["getPage", input.page || input.pageId, input], async () => {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { DehydratedState } from "@tanstack/react-query"
|
||||
import { NextPage } from "next"
|
||||
import { AppProps } from "next/app"
|
||||
import { ReactElement, ReactNode } from "react"
|
||||
|
||||
export type AppPropsWithLayout = AppProps<{
|
||||
dehydratedState: DehydratedState
|
||||
}> & {
|
||||
Component: NextPageWithLayout
|
||||
}
|
||||
|
||||
export type NextPageWithLayout<
|
||||
P = { dehydratedState: DehydratedState },
|
||||
IP = P,
|
||||
> = NextPage<P, IP> & {
|
||||
getLayout?: (page: ReactElement) => ReactNode
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import path from "path"
|
||||
import { defineConfig } from "vitest/config"
|
||||
import react from "@vitejs/plugin-react"
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
@@ -7,6 +8,7 @@ export default defineConfig({
|
||||
"~": path.resolve("./src"),
|
||||
},
|
||||
},
|
||||
plugins: [react()],
|
||||
test: {
|
||||
include: ["src/**/*.test.ts"],
|
||||
deps: {
|
||||
|
||||
Reference in New Issue
Block a user