update packages and search fix

This commit is contained in:
polv committed 2021-04-17 23:02:59 +07:00
1 parent d8161be401
commit a311ef72d3
8 files changed
+838 -2386

No files matched your search

+1 -1
View File
@@ -108,7 +108,7 @@ export const getStaticProps: GetStaticProps = async (ctx) => {
return {
props: dbPost.findOne({
path: (ctx.params.path as string[]).join('/')
path: (ctx.params.path as string[]).map(decodeURIComponent).join('/')
})
}
}
+18 -16
View File
@@ -22,26 +22,19 @@ const 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 () => {
await initDatabase()
const tMap = new Map<string, number>()
dbPost.find({
date: { $lt: new Date().getTime() }
}).map(({ tag = [] }) => {
return tag.map((t) => {
return tMap.set(t, (tMap.get(t) || 0) + 1)
dbPost
.find({
date: { $lt: new Date().getTime() }
})
.map(({ tag = [] }) => {
return tag.map((t) => {
return tMap.set(t, (tMap.get(t) || 0) + 1)
})
})
})
return {
paths: Array.from(tMap).flatMap(([t, n]) =>
@@ -49,7 +42,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
.fill(null)
.map((_, i) => ({
params: {
tag: t,
tag: encodeURIComponent(t),
page: (i + 2).toString()
}
}))
@@ -57,3 +50,12 @@ export const getStaticPaths: GetStaticPaths = async () => {
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)
})
}
}
+2 -2
View File
@@ -29,7 +29,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
return {
paths: Array.from(tMap).map(([t]) => ({
params: {
tag: t
tag: encodeURIComponent(t)
}
})),
fallback: false
@@ -39,7 +39,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
export const getStaticProps: GetStaticProps = async (ctx) => {
return {
props: await doSearch({
tag: ctx.params.tag as string
tag: decodeURIComponent(ctx.params.tag as string)
})
}
}