update packages and search fix
This commit is contained in:
1 parent
d8161be401
commit
a311ef72d3
8 files changed
+838
-2386
No files matched your search
@@ -38,13 +38,16 @@ const PostQuery = ({
|
|||||||
|
|
||||||
const [posts, setPosts] = useState([] as IPost[])
|
const [posts, setPosts] = useState([] as IPost[])
|
||||||
const [count, setCount] = useState(0)
|
const [count, setCount] = useState(0)
|
||||||
const [isLoading, setLoading] = useState(true)
|
const [isLoading, setLoading] = useState(router.asPath.includes('?'))
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (router.query.q) {
|
const u = new URL(location.href)
|
||||||
|
const q = u.searchParams.get('q')
|
||||||
|
|
||||||
|
if (q) {
|
||||||
const querystrings: string[] = []
|
const querystrings: string[] = []
|
||||||
for (const [k, v] of Object.entries({
|
for (const [k, v] of Object.entries({
|
||||||
q: router.query.q,
|
q,
|
||||||
page: router.query.page,
|
page: router.query.page,
|
||||||
tag: router.query.tag
|
tag: router.query.tag
|
||||||
})) {
|
})) {
|
||||||
@@ -58,20 +61,24 @@ const PostQuery = ({
|
|||||||
.then(({ result, count }) => {
|
.then(({ result, count }) => {
|
||||||
setPosts(result)
|
setPosts(result)
|
||||||
setCount(count)
|
setCount(count)
|
||||||
|
|
||||||
|
setLoading(false)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
setPosts(defaults.posts)
|
setPosts(defaults.posts)
|
||||||
setCount(defaults.count)
|
setCount(defaults.count)
|
||||||
}
|
|
||||||
|
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
}
|
||||||
}, [router.query.q, router.query.page, router.query.tag])
|
}, [router.query.q, router.query.page, router.query.tag])
|
||||||
|
|
||||||
const totalPages = Math.ceil(count / 5)
|
const totalPages = Math.ceil(count / 5)
|
||||||
|
|
||||||
return (
|
return isLoading ? (
|
||||||
|
<div>Loading...</div>
|
||||||
|
) : (
|
||||||
<article>
|
<article>
|
||||||
{isLoading ? null : posts.length ? (
|
{posts.length ? (
|
||||||
posts.map((p) => <PostTeaser post={p} key={p.path} />)
|
posts.map((p) => <PostTeaser post={p} key={p.path} />)
|
||||||
) : (
|
) : (
|
||||||
<p>No posts found.</p>
|
<p>No posts found.</p>
|
||||||
|
|||||||
@@ -9,5 +9,8 @@ module.exports = withSvgr({
|
|||||||
permanent: false
|
permanent: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
future: {
|
||||||
|
webpack5: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
+21
-21
@@ -10,39 +10,39 @@
|
|||||||
"prebuild": "yarn ts scripts/make.ts"
|
"prebuild": "yarn ts scripts/make.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-yaml": "^3.14.1",
|
"js-yaml": "^4.1.0",
|
||||||
"lokijs": "^1.5.11",
|
"lokijs": "^1.5.11",
|
||||||
"lunr": "^2.3.9",
|
"lunr": "^2.3.9",
|
||||||
"next": "10.0.3",
|
"next": "^10.1.3",
|
||||||
"react": "17.0.1",
|
"react": "^17.0.2",
|
||||||
"react-dom": "17.0.1",
|
"react-dom": "^17.0.2",
|
||||||
"zod": "^1.11.11"
|
"zod": "^1.11.13"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@patarapolw/scope-css": "^1.3.0",
|
"@patarapolw/scope-css": "^1.3.0",
|
||||||
"@types/cheerio": "^0.22.23",
|
"@types/cheerio": "^0.22.28",
|
||||||
"@types/ejs": "^3.0.5",
|
"@types/ejs": "^3.0.6",
|
||||||
"@types/fs-extra": "^9.0.5",
|
"@types/fs-extra": "^9.0.11",
|
||||||
"@types/js-yaml": "^3.12.5",
|
"@types/js-yaml": "^4.0.0",
|
||||||
"@types/lokijs": "^1.5.3",
|
"@types/lokijs": "^1.5.4",
|
||||||
"@types/lunr": "^2.3.3",
|
"@types/lunr": "^2.3.3",
|
||||||
"@types/node": "^14.14.14",
|
"@types/node": "^14.14.41",
|
||||||
"@types/react": "^17.0.0",
|
"@types/react": "^17.0.3",
|
||||||
"@types/react-dom": "^17.0.0",
|
"@types/react-dom": "^17.0.3",
|
||||||
"@types/rimraf": "^3.0.0",
|
"@types/rimraf": "^3.0.0",
|
||||||
"@types/showdown": "^1.9.3",
|
"@types/showdown": "^1.9.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.10.0",
|
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
||||||
"@typescript-eslint/parser": "^4.10.0",
|
"@typescript-eslint/parser": "^4.22.0",
|
||||||
"cheerio": "^1.0.0-rc.3",
|
"cheerio": "^1.0.0-rc.3",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"ejs": "^3.1.5",
|
"ejs": "^3.1.6",
|
||||||
"eslint": "^7.12.1",
|
"eslint": "^7.24.0",
|
||||||
"eslint-config-standard": "^16.0.2",
|
"eslint-config-standard": "^16.0.2",
|
||||||
"eslint-plugin-import": "^2.22.1",
|
"eslint-plugin-import": "^2.22.1",
|
||||||
"eslint-plugin-node": "^11.1.0",
|
"eslint-plugin-node": "^11.1.0",
|
||||||
"eslint-plugin-promise": "^4.2.1",
|
"eslint-plugin-promise": "^5.1.0",
|
||||||
"eslint-plugin-react": "^7.21.5",
|
"eslint-plugin-react": "^7.23.2",
|
||||||
"fs-extra": "^9.0.1",
|
"fs-extra": "^9.1.0",
|
||||||
"import-sort-parser-typescript": "^6.0.0",
|
"import-sort-parser-typescript": "^6.0.0",
|
||||||
"next-svgr": "^0.0.2",
|
"next-svgr": "^0.0.2",
|
||||||
"nodejieba": "^2.5.1",
|
"nodejieba": "^2.5.1",
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"showdown": "^1.9.1",
|
"showdown": "^1.9.1",
|
||||||
"ts-node": "^9.1.1",
|
"ts-node": "^9.1.1",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.2.4"
|
||||||
},
|
},
|
||||||
"importSort": {
|
"importSort": {
|
||||||
".ts, .tsx, .config.ts": {
|
".ts, .tsx, .config.ts": {
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ export const getStaticProps: GetStaticProps = async (ctx) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props: dbPost.findOne({
|
props: dbPost.findOne({
|
||||||
path: (ctx.params.path as string[]).join('/')
|
path: (ctx.params.path as string[]).map(decodeURIComponent).join('/')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,26 +22,19 @@ const TagPagePaged = ({
|
|||||||
|
|
||||||
export default TagPagePaged
|
export default TagPagePaged
|
||||||
|
|
||||||
export const getStaticProps: GetStaticProps = async (ctx) => {
|
|
||||||
return {
|
|
||||||
props: await doSearch({
|
|
||||||
page: parseInt(ctx.params.page as string),
|
|
||||||
tag: ctx.params.tag as string
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getStaticPaths: GetStaticPaths = async () => {
|
export const getStaticPaths: GetStaticPaths = async () => {
|
||||||
await initDatabase()
|
await initDatabase()
|
||||||
const tMap = new Map<string, number>()
|
const tMap = new Map<string, number>()
|
||||||
|
|
||||||
dbPost.find({
|
dbPost
|
||||||
date: { $lt: new Date().getTime() }
|
.find({
|
||||||
}).map(({ tag = [] }) => {
|
date: { $lt: new Date().getTime() }
|
||||||
return tag.map((t) => {
|
})
|
||||||
return tMap.set(t, (tMap.get(t) || 0) + 1)
|
.map(({ tag = [] }) => {
|
||||||
|
return tag.map((t) => {
|
||||||
|
return tMap.set(t, (tMap.get(t) || 0) + 1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
paths: Array.from(tMap).flatMap(([t, n]) =>
|
paths: Array.from(tMap).flatMap(([t, n]) =>
|
||||||
@@ -49,7 +42,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
|||||||
.fill(null)
|
.fill(null)
|
||||||
.map((_, i) => ({
|
.map((_, i) => ({
|
||||||
params: {
|
params: {
|
||||||
tag: t,
|
tag: encodeURIComponent(t),
|
||||||
page: (i + 2).toString()
|
page: (i + 2).toString()
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
@@ -57,3 +50,12 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
|||||||
fallback: false
|
fallback: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getStaticProps: GetStaticProps = async (ctx) => {
|
||||||
|
return {
|
||||||
|
props: await doSearch({
|
||||||
|
page: parseInt(ctx.params.page as string),
|
||||||
|
tag: decodeURIComponent(ctx.params.tag as string)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
|||||||
return {
|
return {
|
||||||
paths: Array.from(tMap).map(([t]) => ({
|
paths: Array.from(tMap).map(([t]) => ({
|
||||||
params: {
|
params: {
|
||||||
tag: t
|
tag: encodeURIComponent(t)
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
fallback: false
|
fallback: false
|
||||||
@@ -39,7 +39,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
|
|||||||
export const getStaticProps: GetStaticProps = async (ctx) => {
|
export const getStaticProps: GetStaticProps = async (ctx) => {
|
||||||
return {
|
return {
|
||||||
props: await doSearch({
|
props: await doSearch({
|
||||||
tag: ctx.params.tag as string
|
tag: decodeURIComponent(ctx.params.tag as string)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ export async function doSearch ({
|
|||||||
const offset = (page - 1) * perPage
|
const offset = (page - 1) * perPage
|
||||||
|
|
||||||
let cond = dbPost.chain().find({
|
let cond = dbPost.chain().find({
|
||||||
date: { $exists: true } as any
|
date: { $exists: !(tag || q) } as any
|
||||||
})
|
})
|
||||||
|
|
||||||
if (q) {
|
if (q) {
|
||||||
|
|||||||
+778
-2338
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user