mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-18 05:01:21 +08:00
website: add search data. #105
This commit is contained in:
@ -5,6 +5,8 @@ import { create } from './create.mjs';
|
||||
|
||||
export const OUTOUT = path.resolve(process.cwd(), 'dist');
|
||||
export const DOCS = path.resolve(process.cwd(), 'docs');
|
||||
/** 搜索数据路径 */
|
||||
export const SEARCH_DATA = path.resolve(OUTOUT, 'data.json');
|
||||
|
||||
export async function createHTML(files = [], num = 0) {
|
||||
const dataFile = files[num];
|
||||
@ -25,8 +27,7 @@ export async function createHTML(files = [], num = 0) {
|
||||
.replace(/.md$/, '.html');
|
||||
|
||||
await fs.ensureDir(path.dirname(outputHTMLPath));
|
||||
|
||||
const html = create(mdstr.toString(), {
|
||||
const options = {
|
||||
filename: path.basename(outputHTMLPath, '.html'),
|
||||
isHome: /README.md$/.test(path.relative(process.cwd(), dataFile.path)),
|
||||
githubURL,
|
||||
@ -35,7 +36,14 @@ export async function createHTML(files = [], num = 0) {
|
||||
path.relative(path.dirname(outputHTMLPath), path.resolve(OUTOUT, 'style/style.css')),
|
||||
path.relative(path.dirname(outputHTMLPath), path.resolve(OUTOUT, 'style/katex.css')),
|
||||
],
|
||||
});
|
||||
};
|
||||
const { html, data } = create(mdstr.toString(), options);
|
||||
if (!options.isHome) {
|
||||
const searchData = await fs.readJSON(SEARCH_DATA);
|
||||
data.path = path.relative(OUTOUT, outputHTMLPath);
|
||||
searchData[options.filename] = data;
|
||||
await fs.writeJSON(SEARCH_DATA, searchData, { spaces: 2 });
|
||||
}
|
||||
await fs.writeFile(outputHTMLPath, html);
|
||||
console.log(`♻️ \x1b[32;1m ${path.relative(OUTOUT, outputHTMLPath)} \x1b[0m`);
|
||||
createHTML(files, num);
|
||||
@ -45,6 +53,7 @@ export async function run() {
|
||||
await fs.ensureDir(OUTOUT);
|
||||
await fs.emptyDir(OUTOUT);
|
||||
await fs.ensureDir(path.resolve(OUTOUT, 'style'));
|
||||
await fs.writeFile(SEARCH_DATA, '{}');
|
||||
await fs.copy(path.resolve(process.cwd(), 'scripts/style'), path.resolve(OUTOUT, 'style'));
|
||||
const files = await recursiveReaddirFiles(process.cwd(), {
|
||||
ignored: /\/(node_modules|\.git)/,
|
||||
|
Reference in New Issue
Block a user