mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 08:41:37 +00:00
fix: search index name error
This commit is contained in:
@ -139,7 +139,7 @@ const HeadBar = () => {
|
||||
{mounted ? (
|
||||
<DocSearch
|
||||
appId={process.env.NEXT_PUBLIC_ALGOLIA_APP_ID ?? ''}
|
||||
indexName="RUA"
|
||||
indexName="rua"
|
||||
apiKey={
|
||||
process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_ADMIN_KEY ?? ''
|
||||
}
|
||||
|
@ -2,19 +2,17 @@ import { algoliasearch } from 'algoliasearch';
|
||||
/**
|
||||
* Generate algolia records.
|
||||
* @params -t for test.
|
||||
* @params -g add gitsts to records.
|
||||
*/
|
||||
/* @ts-check */
|
||||
import { config } from 'dotenv';
|
||||
// import { liteClient } from 'algoliasearch/lite';
|
||||
import generateGists from './gists/index.mjs';
|
||||
// import generateGists from './gists/index.mjs';
|
||||
import { config } from 'dotenv';
|
||||
import postLists from './posts/index.mjs';
|
||||
|
||||
async function generateRecords(gists) {
|
||||
const records = await postLists();
|
||||
return gists ? records.concat(await generateGists()) : records;
|
||||
async function generateRecords() {
|
||||
return postLists();
|
||||
}
|
||||
async function pushAlgolia(gists) {
|
||||
async function pushAlgolia() {
|
||||
if (
|
||||
!process.env.NEXT_PUBLIC_ALGOLIA_APP_ID &&
|
||||
!process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_ADMIN_KEY
|
||||
@ -23,7 +21,7 @@ async function pushAlgolia(gists) {
|
||||
}
|
||||
|
||||
try {
|
||||
const records = await generateRecords(gists);
|
||||
const records = await generateRecords();
|
||||
|
||||
const client = algoliasearch(
|
||||
process.env.NEXT_PUBLIC_ALGOLIA_APP_ID,
|
||||
@ -31,7 +29,7 @@ async function pushAlgolia(gists) {
|
||||
);
|
||||
|
||||
const response = await client.clearObjects({ indexName: 'rua' });
|
||||
console.log('Clean rua index success');
|
||||
console.log('Clean rua index success', response);
|
||||
const algoliaResponse = await client.saveObjects({
|
||||
indexName: 'rua',
|
||||
objects: records,
|
||||
@ -46,8 +44,8 @@ async function pushAlgolia(gists) {
|
||||
}
|
||||
}
|
||||
|
||||
async function test(gists) {
|
||||
const records = await generateRecords(gists);
|
||||
async function test() {
|
||||
const records = await generateRecords();
|
||||
console.log(records);
|
||||
}
|
||||
|
||||
@ -57,9 +55,8 @@ function main() {
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const isTest = args.some((arg) => arg === '-t');
|
||||
const gists = args.some((arg) => arg === '-g');
|
||||
|
||||
isTest ? test(gists) : pushAlgolia(gists);
|
||||
isTest ? test() : pushAlgolia();
|
||||
}
|
||||
|
||||
main();
|
||||
|
@ -1,6 +1,7 @@
|
||||
import path from 'path';
|
||||
/* @ts-check */
|
||||
import fs from 'fs/promises';
|
||||
import matter from 'gray-matter';
|
||||
|
||||
const dataPath = 'content/posts';
|
||||
|
||||
@ -15,8 +16,9 @@ const postLists = async () => {
|
||||
const myPosts = [];
|
||||
|
||||
const getFiles = async (f) => {
|
||||
const content = await fs.readFile(path.join(dataPath, f), 'utf-8');
|
||||
// const { content: meta, content } = matter(markdownWithMeta);
|
||||
const markdownWithMeta = await fs.readFile(path.join(dataPath, f), 'utf-8');
|
||||
const { content, data: meta } = matter(markdownWithMeta);
|
||||
// console.log('meta', meta);
|
||||
|
||||
const slug = f.replace(/\.mdx$/, '');
|
||||
const regex = /^#{2,3}(?!#)(.*)/gm;
|
||||
@ -40,6 +42,7 @@ const postLists = async () => {
|
||||
type: `lvl${level}`,
|
||||
objectID: url,
|
||||
url,
|
||||
tag: meta.tags,
|
||||
};
|
||||
|
||||
switch (level) {
|
||||
|
Reference in New Issue
Block a user