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