make sure it can build
This commit is contained in:
1 parent
f527b810b6
commit
25585aa3da
3 files changed
+9
-22
No files matched your search
@@ -1,9 +1,9 @@
|
|||||||
import { THEME } from '~/assets/global'
|
import { THEME } from '~/assets/global'
|
||||||
import { formatDate } from '~/assets/util'
|
import { formatDate } from '~/assets/util'
|
||||||
import { IPostTeaser } from '~/server/db'
|
import { IPost } from '~/server/db'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
|
||||||
const PostTeaser = ({ post }: { post: IPostTeaser }) => {
|
const PostTeaser = ({ post }: { post: IPost }) => {
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<h2>
|
<h2>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
/* eslint-disable import/no-mutable-exports */
|
/* eslint-disable import/no-mutable-exports */
|
||||||
|
|
||||||
import idxJson from '~/build/idx.json'
|
|
||||||
import Loki, { Collection } from 'lokijs'
|
import Loki, { Collection } from 'lokijs'
|
||||||
import lunr from 'lunr'
|
import lunr from 'lunr'
|
||||||
import * as z from 'zod'
|
import * as z from 'zod'
|
||||||
@@ -42,22 +41,7 @@ export const zPost = z
|
|||||||
})
|
})
|
||||||
.merge(zMatterSerialized)
|
.merge(zMatterSerialized)
|
||||||
|
|
||||||
export type IPost = z.infer<typeof zPost> & {
|
export type IPost = z.infer<typeof zPost>
|
||||||
path: string
|
|
||||||
title: string
|
|
||||||
content: string
|
|
||||||
excerptHtml: string
|
|
||||||
contentHtml: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type IPostTeaser = {
|
|
||||||
path: string
|
|
||||||
date?: number
|
|
||||||
title: string
|
|
||||||
image?: string
|
|
||||||
content: string
|
|
||||||
excerptHtml: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IPostSearch {
|
export interface IPostSearch {
|
||||||
path: string
|
path: string
|
||||||
@@ -76,13 +60,15 @@ export let dbPost: Collection<IPost>
|
|||||||
|
|
||||||
export let idx: lunr.Index
|
export let idx: lunr.Index
|
||||||
|
|
||||||
|
export async function initLunr () {
|
||||||
|
return idx || lunr.Index.load(require('../build/idx.json'))
|
||||||
|
}
|
||||||
|
|
||||||
export async function initDatabase () {
|
export async function initDatabase () {
|
||||||
if (db) {
|
if (db) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
idx = lunr.Index.load(idxJson)
|
|
||||||
|
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
db = new Loki(buildPath('data.loki'), {
|
db = new Loki(buildPath('data.loki'), {
|
||||||
autoload: true,
|
autoload: true,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { dbPost, idx, initDatabase } from './db'
|
import { dbPost, idx, initDatabase, initLunr } from './db'
|
||||||
|
|
||||||
export async function doSearch ({
|
export async function doSearch ({
|
||||||
q,
|
q,
|
||||||
@@ -10,6 +10,7 @@ export async function doSearch ({
|
|||||||
page?: number
|
page?: number
|
||||||
}) {
|
}) {
|
||||||
await initDatabase()
|
await initDatabase()
|
||||||
|
await initLunr()
|
||||||
|
|
||||||
const perPage = 5
|
const perPage = 5
|
||||||
const offset = (page - 1) * perPage
|
const offset = (page - 1) * perPage
|
||||||
|
|||||||
Reference in new issue
Block a user