lastEditTime 字段名调整;修改algolia逻辑

This commit is contained in:
tangly1024
2023-07-29 16:38:49 +08:00
parent c13eb5e65e
commit 7841b556d6
39 changed files with 148 additions and 80 deletions

View File

@@ -64,8 +64,8 @@ export async function getStaticProps({ params: { prefix, slug } }) {
if (!props?.posts?.blockMap) {
props.post.blockMap = await getPostBlocks(props.post.id, from)
}
// 生成全文索引
if (BLOG.ALGOLIA_APP_ID && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA) && process.env.npm_lifecycle_event === 'build') {
// 生成全文索引 && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA)
if (BLOG.ALGOLIA_APP_ID) {
uploadDataToAlgolia(props?.post)
}

View File

@@ -95,8 +95,10 @@ export async function getStaticPaths() {
}
}
export async function getStaticProps({ params: { prefix } }) {
let fullSlug = prefix
export async function getStaticProps(p) {
const { params } = p
console.log('getStaticProps', p)
let fullSlug = params.prefix
if (JSON.parse(BLOG.PSEUDO_STATIC)) {
if (!fullSlug.endsWith('.html')) {
fullSlug += '.html'
@@ -111,7 +113,7 @@ export async function getStaticProps({ params: { prefix } }) {
// 处理非列表内文章的内信息
if (!props?.post) {
const pageId = prefix.slice(-1)[0]
const pageId = params.PSEUDO_STATICprefix.slice(-1)[0]
if (pageId.length >= 32) {
const post = await getNotion(pageId)
props.post = post
@@ -129,8 +131,8 @@ export async function getStaticProps({ params: { prefix } }) {
props.post.blockMap = await getPostBlocks(props.post.id, from)
}
// 生成全文索引
if (BLOG.ALGOLIA_APP_ID && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA) && process.env.npm_lifecycle_event === 'build') {
// 生成全文索引 && process.env.npm_lifecycle_event === 'build' && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA)
if (BLOG.ALGOLIA_APP_ID) {
uploadDataToAlgolia(props?.post)
}

View File

@@ -6,7 +6,6 @@ import { generateRobotsTxt } from '@/lib/robots.txt'
import { useRouter } from 'next/router'
import { getLayoutByTheme } from '@/themes/theme'
import { generateAlgoliaSearch } from '@/lib/algolia'
/**
* 首页布局
@@ -64,9 +63,6 @@ export async function getStaticProps() {
}
// 生成全文索引 - 仅在 yarn build 时执行 && process.env.npm_lifecycle_event === 'build'
if (BLOG.ALGOLIA_APP_ID && JSON.parse(BLOG.ALGOLIA_RECREATE_DATA)) {
generateAlgoliaSearch({ allPages: props.allPages })
}
delete props.allPages

View File

@@ -42,7 +42,7 @@ export const getServerSideProps = async (ctx) => {
const slugWithoutLeadingSlash = post?.slug.startsWith('/') ? post?.slug?.slice(1) : post.slug
return {
loc: `${BLOG.LINK}/${slugWithoutLeadingSlash}`,
lastmod: new Date(post?.publishTime).toISOString().split('T')[0],
lastmod: new Date(post?.publishDay).toISOString().split('T')[0],
changefreq: 'daily',
priority: '0.7'
}