minista 2.6.2 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,7 @@ https://minista.qranoko.jp
18
18
 
19
19
  ## About
20
20
 
21
- minista(ミニスタ)は、React の JSX で書けるスタティックサイトジェネレーターです。Next.js 風の快適な環境で開発しながら 100% 静的な出力を行えます。SaaS の web テンプレートコーディング業務を想定しているため、ビルド後のデータが綺麗(ヒューマンリーダブル)です。
21
+ minista(ミニスタ)は、React の JSX で書けるスタティックサイトジェネレーターです。Next.js 風の快適な環境で開発しながら 100% 静的に出力できます。SaaS の web テンプレートコーディング業務を想定しているため、ビルド後のデータが綺麗(ヒューマンリーダブル)です。
22
22
 
23
23
  ## How To Use
24
24
 
@@ -165,6 +165,24 @@ export default defineConfig({
165
165
  rehypePlugins: [], // https://mdxjs.com/packages/mdx/#optionsrehypeplugins
166
166
  },
167
167
  },
168
+ search: {
169
+ useJson: false, // boolean
170
+ cache: false, // boolean
171
+ outDir: "assets", // string
172
+ outName: "search", // string
173
+ include: ["**/*"], // string[]
174
+ exclude: ["404"], // string[]
175
+ trimTitle: "", // string
176
+ targetSelector: "[data-search]", // string
177
+ hit: {
178
+ minLength: 3, // number
179
+ number: false, // boolean
180
+ english: true, // boolean
181
+ hiragana: false, // boolean
182
+ katakana: true, // boolean
183
+ kanji: true, // boolean
184
+ },
185
+ },
168
186
  beautify: {
169
187
  useHtml: true, // boolean
170
188
  useAssets: false, // boolean
package/dist/build.d.ts CHANGED
@@ -10,18 +10,38 @@ export declare function buildTempPages(entryPoints: string[], buildOptions: {
10
10
  svgrOptions: SvgrOptions;
11
11
  cssOptions: CssOptions;
12
12
  }): Promise<void>;
13
- export declare function buildStaticPages(entryPoints: string[], tempRootFilePath: string, buildOptions: {
13
+ export declare function buildStaticPages({ entryPoints, tempRootFilePath, outBase, outDir, assetsTagStr, showLog, }: {
14
+ entryPoints: string[];
15
+ tempRootFilePath: string;
14
16
  outBase: string;
15
17
  outDir: string;
16
- }, assetsTagStr: string): Promise<void>;
18
+ assetsTagStr: string;
19
+ showLog: boolean;
20
+ }): Promise<void>;
17
21
  export declare function buildRootEsmContent(tempRootFilePath: string): Promise<{
18
22
  component: RootJsxContent;
19
23
  staticData: GlobalStaticData;
20
24
  }>;
21
25
  export declare function buildGlobalStaticData(getGlobalStaticData: GetGlobalStaticData): Promise<GlobalStaticData>;
22
- export declare function buildStaticPage(entryPoint: string, outFile: string, rootStaticContent: RootStaticContent, assetsTagStr: string, outDir: string): Promise<void>;
26
+ export declare function buildStaticPage({ entryPoint, outFile, rootStaticContent, assetsTagStr, outDir, showLog, }: {
27
+ entryPoint: string;
28
+ outFile: string;
29
+ rootStaticContent: RootStaticContent;
30
+ assetsTagStr: string;
31
+ outDir: string;
32
+ showLog: boolean;
33
+ }): Promise<void>;
23
34
  export declare function buildStaticData(getStaticData: GetStaticData): Promise<StaticData>;
24
- export declare function buildHtmlPage(pageJsxContent: PageJsxContent, staticDataItem: StaticDataItem, routePath: string, rootStaticContent: RootStaticContent, assetsTagStr: string, frontmatter: any, outDir: string): Promise<void>;
35
+ export declare function buildHtmlPage({ pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagStr, frontmatter, outDir, showLog, }: {
36
+ pageJsxContent: PageJsxContent;
37
+ staticDataItem: StaticDataItem;
38
+ routePath: string;
39
+ rootStaticContent: RootStaticContent;
40
+ assetsTagStr: string;
41
+ frontmatter: any;
42
+ outDir: string;
43
+ showLog: boolean;
44
+ }): Promise<void>;
25
45
  export declare function buildTempAssets(viteConfig: InlineConfig, buildOptions: {
26
46
  input: string;
27
47
  bundleOutName: string;
@@ -62,4 +82,12 @@ export declare function buildPartialHydrateAssets(viteConfig: InlineConfig, buil
62
82
  assetDir: string;
63
83
  usePreact: boolean;
64
84
  }): Promise<void>;
85
+ export declare function buildSearchJson({ config, useCacheExists, entryPoints, entryBase, outFile, showLog, }: {
86
+ config: MinistaResolveConfig;
87
+ useCacheExists: boolean;
88
+ entryPoints: string[];
89
+ entryBase: string;
90
+ outFile: string;
91
+ showLog: boolean;
92
+ }): Promise<void>;
65
93
  export declare function buildCopyDir(targetDir: string, outDir: string, log?: "public" | "assets"): Promise<void>;
package/dist/build.js CHANGED
@@ -30,6 +30,8 @@ import {
30
30
  defineConfig as defineViteConfig,
31
31
  mergeConfig as mergeViteConfig
32
32
  } from "vite";
33
+ import { parse } from "node-html-parser";
34
+ import mojigiri from "mojigiri";
33
35
  import { systemConfig } from "./system.js";
34
36
  import { getFilePath } from "./path.js";
35
37
  import {
@@ -100,15 +102,29 @@ async function buildTempPages(entryPoints, buildOptions) {
100
102
  ]
101
103
  }).catch(() => process.exit(1));
102
104
  }
103
- async function buildStaticPages(entryPoints, tempRootFilePath, buildOptions, assetsTagStr) {
105
+ async function buildStaticPages({
106
+ entryPoints,
107
+ tempRootFilePath,
108
+ outBase,
109
+ outDir,
110
+ assetsTagStr,
111
+ showLog
112
+ }) {
104
113
  const rootStaticContent = await buildRootEsmContent(tempRootFilePath);
105
- const winOutBase = buildOptions.outBase.replaceAll("/", "\\");
114
+ const winOutBase = outBase.replaceAll("/", "\\");
106
115
  await Promise.all(entryPoints.map(async (entryPoint) => {
107
116
  const extname = path.extname(entryPoint);
108
117
  const basename = path.basename(entryPoint, extname);
109
- const dirname = path.dirname(entryPoint).replace(buildOptions.outBase, buildOptions.outDir).replace(winOutBase, buildOptions.outDir);
118
+ const dirname = path.dirname(entryPoint).replace(outBase, outDir).replace(winOutBase, outDir);
110
119
  const filename = path.join(dirname, basename + ".html");
111
- await buildStaticPage(entryPoint, filename, rootStaticContent, assetsTagStr, buildOptions.outDir);
120
+ await buildStaticPage({
121
+ entryPoint,
122
+ outFile: filename,
123
+ rootStaticContent,
124
+ assetsTagStr,
125
+ outDir,
126
+ showLog
127
+ });
112
128
  }));
113
129
  }
114
130
  async function buildRootEsmContent(tempRootFilePath) {
@@ -130,7 +146,14 @@ async function buildGlobalStaticData(getGlobalStaticData) {
130
146
  const response = await getGlobalStaticData();
131
147
  return response;
132
148
  }
133
- async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTagStr, outDir) {
149
+ async function buildStaticPage({
150
+ entryPoint,
151
+ outFile,
152
+ rootStaticContent,
153
+ assetsTagStr,
154
+ outDir,
155
+ showLog
156
+ }) {
134
157
  const targetFilePath = url.pathToFileURL(entryPoint).href;
135
158
  const pageEsmContent = await import(targetFilePath);
136
159
  const pageJsxContent = pageEsmContent.default;
@@ -139,11 +162,29 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
139
162
  const staticData = pageEsmContent.getStaticData ? await buildStaticData(pageEsmContent.getStaticData) : void 0;
140
163
  if (!staticData) {
141
164
  const staticDataItem = defaultStaticDataItem;
142
- return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr, frontmatter, outDir);
165
+ return await buildHtmlPage({
166
+ pageJsxContent,
167
+ staticDataItem,
168
+ routePath: outFile,
169
+ rootStaticContent,
170
+ assetsTagStr,
171
+ frontmatter,
172
+ outDir,
173
+ showLog
174
+ });
143
175
  }
144
176
  if ("props" in staticData && "paths" in staticData === false) {
145
177
  const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
146
- return await buildHtmlPage(pageJsxContent, staticDataItem, outFile, rootStaticContent, assetsTagStr, frontmatter, outDir);
178
+ return await buildHtmlPage({
179
+ pageJsxContent,
180
+ staticDataItem,
181
+ routePath: outFile,
182
+ rootStaticContent,
183
+ assetsTagStr,
184
+ frontmatter,
185
+ outDir,
186
+ showLog
187
+ });
147
188
  }
148
189
  if ("paths" in staticData) {
149
190
  const staticDataItem = __spreadValues(__spreadValues({}, defaultStaticDataItem), staticData);
@@ -152,7 +193,16 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
152
193
  const reg = new RegExp("\\[" + key + "\\]", "g");
153
194
  fixedOutfile = fixedOutfile.replace(reg, `${value}`);
154
195
  }
155
- return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr, frontmatter, outDir);
196
+ return await buildHtmlPage({
197
+ pageJsxContent,
198
+ staticDataItem,
199
+ routePath: fixedOutfile,
200
+ rootStaticContent,
201
+ assetsTagStr,
202
+ frontmatter,
203
+ outDir,
204
+ showLog
205
+ });
156
206
  }
157
207
  if (Array.isArray(staticData) && staticData.length > 0) {
158
208
  const entryPoints = staticData;
@@ -163,7 +213,16 @@ async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTag
163
213
  const reg = new RegExp("\\[" + key + "\\]", "g");
164
214
  fixedOutfile = fixedOutfile.replace(reg, `${value}`);
165
215
  }
166
- return await buildHtmlPage(pageJsxContent, staticDataItem, fixedOutfile, rootStaticContent, assetsTagStr, frontmatter, outDir);
216
+ return await buildHtmlPage({
217
+ pageJsxContent,
218
+ staticDataItem,
219
+ routePath: fixedOutfile,
220
+ rootStaticContent,
221
+ assetsTagStr,
222
+ frontmatter,
223
+ outDir,
224
+ showLog
225
+ });
167
226
  }));
168
227
  }
169
228
  }
@@ -171,7 +230,16 @@ async function buildStaticData(getStaticData) {
171
230
  const response = await getStaticData();
172
231
  return response;
173
232
  }
174
- async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStaticContent, assetsTagStr, frontmatter, outDir) {
233
+ async function buildHtmlPage({
234
+ pageJsxContent,
235
+ staticDataItem,
236
+ routePath,
237
+ rootStaticContent,
238
+ assetsTagStr,
239
+ frontmatter,
240
+ outDir,
241
+ showLog
242
+ }) {
175
243
  if (frontmatter == null ? void 0 : frontmatter.draft) {
176
244
  return;
177
245
  }
@@ -227,7 +295,7 @@ async function buildHtmlPage(pageJsxContent, staticDataItem, routePath, rootStat
227
295
  }
228
296
  const replacedHtml = html[0].replace(/<div class="minista-comment" hidden="">(.+?)<\/div>/g, "\n<!-- $1 -->");
229
297
  await fs.outputFile(routePath, replacedHtml).then(() => {
230
- console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
298
+ showLog && console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(routePath)}`);
231
299
  }).catch((err) => {
232
300
  console.error(err);
233
301
  });
@@ -525,7 +593,7 @@ async function buildPartialHydrateAssets(viteConfig, buildOptions) {
525
593
  resolve: {
526
594
  alias: activePreact ? resolveAliasPreact : {}
527
595
  },
528
- customLogger: viteConfig.customLogger
596
+ logLevel: "error"
529
597
  });
530
598
  const mergedConfig = mergeViteConfig({}, customConfig);
531
599
  const result = await viteBuild(mergedConfig);
@@ -545,6 +613,134 @@ async function buildPartialHydrateAssets(viteConfig, buildOptions) {
545
613
  });
546
614
  }
547
615
  }
616
+ async function buildSearchJson({
617
+ config,
618
+ useCacheExists,
619
+ entryPoints,
620
+ entryBase,
621
+ outFile,
622
+ showLog
623
+ }) {
624
+ if (useCacheExists) {
625
+ return;
626
+ }
627
+ const { trimTitle, targetSelector, hit } = config.search;
628
+ const tempWords = [];
629
+ const tempPages = [];
630
+ await Promise.all(entryPoints.map(async (filePath) => {
631
+ const html = await fs.readFile(filePath, { encoding: "utf-8" });
632
+ const parsedHtml = parse(html, {
633
+ blockTextElements: { script: false, style: false, pre: false }
634
+ });
635
+ const regTrimPath = new RegExp(`^${entryBase}|index|.html`, "g");
636
+ const path2 = filePath.replace(regTrimPath, "");
637
+ const regTrimTitle = new RegExp(trimTitle);
638
+ const pTitle = parsedHtml.querySelector("title");
639
+ const title = pTitle ? pTitle.rawText.replace(regTrimTitle, "") : "";
640
+ const titleArray = mojigiri(title);
641
+ const targetContent = parsedHtml.querySelector(targetSelector);
642
+ if (!targetContent) {
643
+ tempWords.push(title);
644
+ tempPages.push({
645
+ path: path2,
646
+ toc: [],
647
+ title: titleArray,
648
+ content: []
649
+ });
650
+ return;
651
+ }
652
+ const contents = [];
653
+ async function getContent(element) {
654
+ if (element.id) {
655
+ contents.push({ type: "id", value: [element.id] });
656
+ }
657
+ if (element._rawText) {
658
+ const text = element._rawText.replace(/\n/g, "").replace(/\s{2,}/g, " ").trim();
659
+ const words2 = mojigiri(text);
660
+ if (words2.length > 0) {
661
+ contents.push({ type: "words", value: words2 });
662
+ }
663
+ }
664
+ if (element.childNodes) {
665
+ await Promise.all(element.childNodes.map(async (childNode) => {
666
+ return await getContent(childNode);
667
+ }));
668
+ }
669
+ return;
670
+ }
671
+ await getContent(targetContent);
672
+ const toc = [];
673
+ const contentArray = [];
674
+ let contentCount = 0;
675
+ contents.forEach((content) => {
676
+ if (content.type === "id") {
677
+ toc.push([contentCount, content.value[0]]);
678
+ return;
679
+ } else if (content.type === "words") {
680
+ contentArray.push(content.value);
681
+ contentCount = contentCount + content.value.length;
682
+ return;
683
+ }
684
+ });
685
+ const body = targetContent.rawText.replace(/\n/g, "").replace(/\s{2,}/g, " ").trim();
686
+ tempWords.push(title);
687
+ tempWords.push(body);
688
+ tempPages.push({
689
+ path: path2,
690
+ toc,
691
+ title: titleArray,
692
+ content: contentArray.flat()
693
+ });
694
+ }));
695
+ const words = mojigiri(tempWords.join(" "));
696
+ const sortedWords = [...new Set(words)].sort();
697
+ const regHitsArray = [
698
+ hit.number && "[0-9]",
699
+ hit.english && "[a-zA-Z]",
700
+ hit.hiragana && "[\u3041-\u3093]",
701
+ hit.katakana && "[\u30A1-\u30F4]",
702
+ hit.kanji && "[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3400-\u4DB5\u4E00-\u9FC3\uF900-\uFA2D\uFA30-\uFA6A\uFA70-\uFAD9]"
703
+ ].filter((reg) => reg);
704
+ const regHits = new RegExp(`(${regHitsArray.join("|")})`);
705
+ const tempHits = sortedWords.filter((word) => word.length >= hit.minLength && regHits.test(word) && word !== "...");
706
+ const hits = tempHits.map((word) => {
707
+ return sortedWords.indexOf(word);
708
+ });
709
+ const pages = [];
710
+ await Promise.all(tempPages.map(async (page) => {
711
+ const path2 = page.path;
712
+ const toc = page.toc;
713
+ const title = page.title.map((word) => {
714
+ return sortedWords.indexOf(word);
715
+ });
716
+ const content = page.content.map((word) => {
717
+ return sortedWords.indexOf(word);
718
+ });
719
+ pages.push({ path: path2, title, toc, content });
720
+ }));
721
+ const sortedPages = pages.sort((a, b) => {
722
+ const pathA = a.path.toUpperCase();
723
+ const pathB = b.path.toUpperCase();
724
+ if (pathA < pathB) {
725
+ return -1;
726
+ }
727
+ if (pathA > pathB) {
728
+ return 1;
729
+ }
730
+ return 0;
731
+ });
732
+ const template = {
733
+ words: sortedWords,
734
+ hits,
735
+ pages: sortedPages
736
+ };
737
+ await fs.outputJson(outFile, template).then(() => {
738
+ showLog && console.log(`${pc.bold(pc.green("BUILD"))} ${pc.bold(outFile)}`);
739
+ }).catch((err) => {
740
+ console.error(err);
741
+ });
742
+ return;
743
+ }
548
744
  async function buildCopyDir(targetDir, outDir, log) {
549
745
  const checkTargetDir = await fs.pathExists(targetDir);
550
746
  if (checkTargetDir) {
@@ -574,6 +770,7 @@ export {
574
770
  buildPartialStringIndex,
575
771
  buildPartialStringInitial,
576
772
  buildRootEsmContent,
773
+ buildSearchJson,
577
774
  buildStaticData,
578
775
  buildStaticPage,
579
776
  buildStaticPages,
package/dist/cli.js CHANGED
@@ -23,7 +23,7 @@ import { systemConfig } from "./system.js";
23
23
  import { getViteConfig } from "./vite.js";
24
24
  import { getMdxConfig } from "./mdx.js";
25
25
  import { emptyResolveDir } from "./empty.js";
26
- import { createDevServer } from "./server.js";
26
+ import { createDevServer, createDevServerAssets } from "./server.js";
27
27
  import { previewLocal } from "./preview.js";
28
28
  import {
29
29
  generateViteImporters,
@@ -36,6 +36,7 @@ import {
36
36
  generateAssets,
37
37
  generatePublic,
38
38
  generateDownload,
39
+ generateSearchJson,
39
40
  generateBeautify
40
41
  } from "./generate.js";
41
42
  const cli = cac("minista");
@@ -58,11 +59,18 @@ cli.command("[root]", "start dev server").alias("dev").option("--host [host]", `
58
59
  const mdxConfig = await getMdxConfig(config);
59
60
  const viteConfig = await getViteConfig(config, mdxConfig, cliOptions);
60
61
  await Promise.all([
62
+ emptyResolveDir(systemConfig.temp.root.outDir),
63
+ emptyResolveDir(systemConfig.temp.assets.outDir),
64
+ emptyResolveDir(systemConfig.temp.pages.outDir),
61
65
  emptyResolveDir(systemConfig.temp.viteImporter.outDir),
62
- emptyResolveDir(systemConfig.temp.icons.outDir)
66
+ emptyResolveDir(systemConfig.temp.icons.outDir),
67
+ emptyResolveDir(systemConfig.temp.partialHydration.outDir)
63
68
  ]);
64
69
  await generateViteImporters(config, viteConfig);
65
- await createDevServer(viteConfig);
70
+ await Promise.all([
71
+ createDevServer(viteConfig),
72
+ createDevServerAssets(config, mdxConfig)
73
+ ]);
66
74
  } catch (err) {
67
75
  console.log(err);
68
76
  process.exit(1);
@@ -94,11 +102,11 @@ cli.command("build [root]", "build for production").action(async () => {
94
102
  generatePartialHydration(config, mdxConfig, viteConfig)
95
103
  ]);
96
104
  await Promise.all([
97
- generateHtmlPages(config),
105
+ generateHtmlPages(config, config.pagesOutDir, true),
98
106
  generateAssets(config),
99
107
  generatePublic(config)
100
108
  ]);
101
- await Promise.all([generateDownload(config)]);
109
+ await Promise.all([generateDownload(config), generateSearchJson(config)]);
102
110
  await Promise.all([
103
111
  generateBeautify(config, "html"),
104
112
  generateBeautify(config, "css"),
package/dist/config.js CHANGED
@@ -109,6 +109,24 @@ const defaultConfig = {
109
109
  rehypePlugins: []
110
110
  }
111
111
  },
112
+ search: {
113
+ useJson: false,
114
+ cache: false,
115
+ outDir: "assets",
116
+ outName: "search",
117
+ include: ["**/*"],
118
+ exclude: ["404"],
119
+ trimTitle: "",
120
+ targetSelector: "[data-search]",
121
+ hit: {
122
+ minLength: 3,
123
+ number: false,
124
+ english: true,
125
+ hiragana: false,
126
+ katakana: true,
127
+ kanji: true
128
+ }
129
+ },
112
130
  beautify: {
113
131
  useHtml: true,
114
132
  useAssets: false,
@@ -171,12 +189,15 @@ async function resolveConfig(config) {
171
189
  assetsOutHref: slashEnd(config.base) + noSlashEnd(config.assets.outDir),
172
190
  downloadOutDir: slashEnd(config.out) + noSlashEnd(config.assets.download.outDir),
173
191
  downloadOutHref: slashEnd(config.base) + noSlashEnd(config.assets.download.outDir),
192
+ searchJsonOutput: slashEnd(config.out) + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json",
174
193
  viteAssetsOutput: slashEnd(config.assets.outDir) + noSlashEnd(config.assets.outName) + ".[ext]",
175
194
  viteAssetsImagesOutput: slashEnd(config.assets.images.outDir) + noSlashEnd(config.assets.images.outName) + ".[ext]",
176
195
  viteAssetsFontsOutput: slashEnd(config.assets.fonts.outDir) + noSlashEnd(config.assets.fonts.outName) + ".[ext]",
177
196
  vitePluginSvgSpriteIconsSrcDir: noSlashEnd(config.assets.icons.srcDir),
178
197
  vitePluginSvgSpriteIconsOutput: slashEnd("/") + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg",
179
- vitePluginSvgSpriteIconsTempOutput: slashEnd(systemConfig.temp.icons.outDir) + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg"
198
+ vitePluginSvgSpriteIconsTempOutput: slashEnd(systemConfig.temp.icons.outDir) + slashEnd(config.assets.icons.outDir) + noSlashEnd(config.assets.icons.outName) + ".svg",
199
+ vitePluginSearchJsonOutput: slashEnd("/") + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json",
200
+ vitePluginSearchJsonTempOutput: slashEnd(systemConfig.temp.search.outDir) + slashEnd(config.search.outDir) + noSlashEnd(config.search.outName) + ".json"
180
201
  });
181
202
  return resolvedConfig;
182
203
  }
@@ -7,8 +7,9 @@ export declare function generateTempPages(config: MinistaResolveConfig, mdxConfi
7
7
  export declare function generateTempAssets(config: MinistaResolveConfig, viteConfig: InlineConfig): Promise<void>;
8
8
  export declare function generatePartialHydration(config: MinistaResolveConfig, mdxConfig: MdxOptions, viteConfig: InlineConfig): Promise<void>;
9
9
  export declare function generateNoStyleTemp(targetDir: string): Promise<void>;
10
- export declare function generateHtmlPages(config: MinistaResolveConfig): Promise<void>;
10
+ export declare function generateHtmlPages(config: MinistaResolveConfig, outDir: string, showLog: boolean): Promise<void>;
11
11
  export declare function generateAssets(config: MinistaResolveConfig): Promise<void>;
12
12
  export declare function generatePublic(config: MinistaResolveConfig): Promise<void>;
13
13
  export declare function generateDownload(config: MinistaResolveConfig): Promise<void>;
14
+ export declare function generateSearchJson(config: MinistaResolveConfig): Promise<void>;
14
15
  export declare function generateBeautify(config: MinistaResolveConfig, target: "html" | "css" | "js"): Promise<void>;
package/dist/generate.js CHANGED
@@ -3,7 +3,12 @@ import fs from "fs-extra";
3
3
  import path from "path";
4
4
  import url from "url";
5
5
  import { systemConfig } from "./system.js";
6
- import { getFilePath, getFilePaths, getSameFilePaths } from "./path.js";
6
+ import {
7
+ getFilePath,
8
+ getFilePaths,
9
+ getFilterFilePaths,
10
+ getSameFilePaths
11
+ } from "./path.js";
7
12
  import { slashEnd, noSlashEnd } from "./utils.js";
8
13
  import {
9
14
  buildTempPages,
@@ -20,7 +25,8 @@ import {
20
25
  buildPartialStringBundle,
21
26
  buildPartialStringInitial,
22
27
  buildPartialHydrateIndex,
23
- buildPartialHydrateAssets
28
+ buildPartialHydrateAssets,
29
+ buildSearchJson
24
30
  } from "./build.js";
25
31
  import { optimizeCommentOutStyleImport } from "./optimize.js";
26
32
  import { downloadFiles } from "./download.js";
@@ -119,7 +125,7 @@ async function generateNoStyleTemp(targetDir) {
119
125
  await optimizeCommentOutStyleImport(targetFiles);
120
126
  }
121
127
  }
122
- async function generateHtmlPages(config) {
128
+ async function generateHtmlPages(config, outDir, showLog) {
123
129
  const tempRootName = config.root.srcName;
124
130
  const tempRootOutDir = systemConfig.temp.root.outDir;
125
131
  const tempPagesOutDir = systemConfig.temp.pages.outDir;
@@ -134,10 +140,14 @@ async function generateHtmlPages(config) {
134
140
  outBase: tempAssetsOutDir,
135
141
  outDir: config.assetsOutHref
136
142
  });
137
- await buildStaticPages(tempPageFilePaths, tempRootFilePath, {
143
+ await buildStaticPages({
144
+ entryPoints: tempPageFilePaths,
145
+ tempRootFilePath,
138
146
  outBase: tempPagesOutDir,
139
- outDir: config.pagesOutDir
140
- }, assetsTagStr);
147
+ outDir,
148
+ assetsTagStr,
149
+ showLog
150
+ });
141
151
  }
142
152
  async function generateAssets(config) {
143
153
  await buildCopyDir(systemConfig.temp.assets.outDir, slashEnd(config.out) + noSlashEnd(config.assets.outDir), "assets");
@@ -152,6 +162,26 @@ async function generateDownload(config) {
152
162
  }
153
163
  return;
154
164
  }
165
+ async function generateSearchJson(config) {
166
+ if (config.search.useJson) {
167
+ const entryPoints = await getFilterFilePaths({
168
+ targetDir: config.out,
169
+ include: config.search.include,
170
+ exclude: config.search.exclude,
171
+ exts: "html"
172
+ });
173
+ const outFile = config.searchJsonOutput;
174
+ await buildSearchJson({
175
+ config,
176
+ useCacheExists: false,
177
+ entryPoints,
178
+ entryBase: config.out,
179
+ outFile,
180
+ showLog: true
181
+ });
182
+ }
183
+ return;
184
+ }
155
185
  async function generateBeautify(config, target) {
156
186
  switch (target) {
157
187
  case "html":
@@ -187,6 +217,7 @@ export {
187
217
  generateNoStyleTemp,
188
218
  generatePartialHydration,
189
219
  generatePublic,
220
+ generateSearchJson,
190
221
  generateTempAssets,
191
222
  generateTempPages,
192
223
  generateTempRoot,
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * from "./define.js";
3
3
  export * from "./head.js";
4
4
  export * from "./link.js";
5
5
  export * from "./comment.js";
6
+ export * from "./search.js";
6
7
  export * from "./migrate.js";
package/dist/index.js CHANGED
@@ -4,4 +4,5 @@ export * from "./define.js";
4
4
  export * from "./head.js";
5
5
  export * from "./link.js";
6
6
  export * from "./comment.js";
7
+ export * from "./search.js";
7
8
  export * from "./migrate.js";
package/dist/main.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from "./define.js";
2
2
  export * from "./head.js";
3
3
  export * from "./link.js";
4
4
  export * from "./comment.js";
5
+ export * from "./search.js";
5
6
  export * from "./migrate.js";
package/dist/main.js CHANGED
@@ -3,4 +3,5 @@ export * from "./define.js";
3
3
  export * from "./head.js";
4
4
  export * from "./link.js";
5
5
  export * from "./comment.js";
6
+ export * from "./search.js";
6
7
  export * from "./migrate.js";
package/dist/path.d.ts CHANGED
@@ -1,3 +1,9 @@
1
- export declare function getFilePath(targetDir: string, fileName: string, extension: string): string;
2
- export declare function getFilePaths(targetDir: string, extensions: string | string[]): Promise<string[]>;
3
- export declare function getSameFilePaths(targetDir: string, fileName: string, extensions: string | string[]): Promise<string[]>;
1
+ export declare function getFilePath(targetDir: string, fileName: string, ext: string): string;
2
+ export declare function getFilePaths(targetDir: string, exts: string | string[]): Promise<string[]>;
3
+ export declare function getFilterFilePaths({ targetDir, include, exclude, exts, }: {
4
+ targetDir?: string;
5
+ include: string[];
6
+ exclude?: string[];
7
+ exts?: string | string[];
8
+ }): Promise<string[]>;
9
+ export declare function getSameFilePaths(targetDir: string, fileName: string, exts: string | string[]): Promise<string[]>;
package/dist/path.js CHANGED
@@ -2,25 +2,41 @@ import React from "react";
2
2
  import fs from "fs-extra";
3
3
  import fg from "fast-glob";
4
4
  import path from "path";
5
- function getFilePath(targetDir, fileName, extension) {
6
- const filePath = `${targetDir}/${fileName}.${extension}`;
5
+ import { slashEnd } from "./utils.js";
6
+ function getFilePath(targetDir, fileName, ext) {
7
+ const filePath = `${targetDir}/${fileName}.${ext}`;
7
8
  const file = fs.existsSync(path.resolve(filePath)) ? path.resolve(filePath) : "";
8
9
  return file;
9
10
  }
10
- async function getFilePaths(targetDir, extensions) {
11
- const strExtension = typeof extensions === "string" ? extensions : extensions.join("|");
12
- const globPattern = `${targetDir}/**/*.+(${strExtension})`;
11
+ async function getFilePaths(targetDir, exts) {
12
+ const strExt = typeof exts === "string" ? exts : exts.join("|");
13
+ const globPattern = `${targetDir}/**/*.+(${strExt})`;
13
14
  const files = await fg(globPattern, { extglob: true });
14
15
  return files;
15
16
  }
16
- async function getSameFilePaths(targetDir, fileName, extensions) {
17
- const strExtension = typeof extensions === "string" ? extensions : extensions.join("|");
18
- const globPattern = `${targetDir}/${fileName}.+(${strExtension})`;
17
+ async function getFilterFilePaths({
18
+ targetDir,
19
+ include,
20
+ exclude,
21
+ exts
22
+ }) {
23
+ const fixDir = targetDir ? slashEnd(targetDir) : "";
24
+ const fixExt = exts ? typeof exts === "string" ? `.${exts.replace(/^\./, "")}` : `.+(${exts.map((ext) => ext.replace(/^\./, "")).join("|")})` : "";
25
+ const includes = include.map((str) => `${fixDir}${str}${fixExt}`);
26
+ const excludes = exclude ? exclude.map((str) => `!${fixDir}${str}${fixExt}`) : [];
27
+ const globPattern = [includes, excludes].flat();
28
+ const files = await fg(globPattern, { extglob: fixExt ? true : false });
29
+ return files;
30
+ }
31
+ async function getSameFilePaths(targetDir, fileName, exts) {
32
+ const strExt = typeof exts === "string" ? exts : exts.join("|");
33
+ const globPattern = `${targetDir}/${fileName}.+(${strExt})`;
19
34
  const files = await fg(globPattern, { extglob: true });
20
35
  return files;
21
36
  }
22
37
  export {
23
38
  getFilePath,
24
39
  getFilePaths,
40
+ getFilterFilePaths,
25
41
  getSameFilePaths
26
42
  };
@@ -0,0 +1,44 @@
1
+ /// <reference types="react" />
2
+ export declare type SearchData = {
3
+ words: string[];
4
+ hits: number[];
5
+ pages: SearchPage[];
6
+ };
7
+ export declare type SearchPage = {
8
+ path: string;
9
+ title: number[];
10
+ toc: [number, string][];
11
+ content: number[];
12
+ };
13
+ export declare type SearchResult = {
14
+ path: string;
15
+ content: string;
16
+ };
17
+ export interface SearchProps extends React.HTMLAttributes<HTMLElement> {
18
+ jsonPath: string;
19
+ minHitLength?: number;
20
+ maxHitPages?: number;
21
+ maxHitWords?: number;
22
+ searchFieldClassName?: string;
23
+ searchListClassName?: string;
24
+ attributes?: React.HTMLAttributes<HTMLElement>;
25
+ }
26
+ export interface SearchFieldProps extends React.HTMLAttributes<HTMLElement> {
27
+ jsonPath: string;
28
+ minHitLength?: number;
29
+ maxHitPages?: number;
30
+ maxHitWords?: number;
31
+ setSearchValues?: React.Dispatch<React.SetStateAction<string[]>>;
32
+ setSearchHitValues?: React.Dispatch<React.SetStateAction<string[]>>;
33
+ setSearchResults?: React.Dispatch<React.SetStateAction<SearchResult[]>>;
34
+ attributes?: React.HTMLAttributes<HTMLElement>;
35
+ }
36
+ export interface SearchListProps extends React.HTMLAttributes<HTMLElement> {
37
+ searchValues?: string[];
38
+ searchHitValues?: string[];
39
+ searchResults?: SearchResult[];
40
+ attributes?: React.HTMLAttributes<HTMLElement>;
41
+ }
42
+ export declare const Search: (props: SearchProps) => JSX.Element;
43
+ export declare const SearchField: (props: SearchFieldProps) => JSX.Element;
44
+ export declare const SearchList: (props: SearchListProps) => JSX.Element;
package/dist/search.js ADDED
@@ -0,0 +1,272 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+ import React from "react";
30
+ import { useState, useEffect } from "react";
31
+ function compNum(a, b) {
32
+ return a - b;
33
+ }
34
+ const Search = (props) => {
35
+ const _a = props, {
36
+ jsonPath,
37
+ minHitLength = props.minHitLength || 2,
38
+ maxHitPages = props.maxHitPages || 5,
39
+ maxHitWords = props.maxHitWords || 20,
40
+ searchFieldClassName,
41
+ searchListClassName
42
+ } = _a, attributes = __objRest(_a, [
43
+ "jsonPath",
44
+ "minHitLength",
45
+ "maxHitPages",
46
+ "maxHitWords",
47
+ "searchFieldClassName",
48
+ "searchListClassName"
49
+ ]);
50
+ const [searchValues, setSearchValues] = useState([]);
51
+ const [searchHitValues, setSearchHitValues] = useState([]);
52
+ const [searchResults, setSearchResults] = useState([]);
53
+ return /* @__PURE__ */ React.createElement("div", __spreadValues({}, attributes), /* @__PURE__ */ React.createElement(SearchField, {
54
+ className: searchFieldClassName,
55
+ jsonPath,
56
+ minHitLength,
57
+ maxHitPages,
58
+ maxHitWords,
59
+ setSearchValues,
60
+ setSearchHitValues,
61
+ setSearchResults
62
+ }), /* @__PURE__ */ React.createElement(SearchList, {
63
+ className: searchListClassName,
64
+ searchValues,
65
+ searchHitValues,
66
+ searchResults
67
+ }));
68
+ };
69
+ const SearchField = (props) => {
70
+ const _a = props, {
71
+ jsonPath,
72
+ minHitLength = props.minHitLength || 2,
73
+ maxHitPages = props.maxHitPages || 5,
74
+ maxHitWords = props.maxHitWords || 20,
75
+ setSearchValues,
76
+ setSearchHitValues,
77
+ setSearchResults
78
+ } = _a, attributes = __objRest(_a, [
79
+ "jsonPath",
80
+ "minHitLength",
81
+ "maxHitPages",
82
+ "maxHitWords",
83
+ "setSearchValues",
84
+ "setSearchHitValues",
85
+ "setSearchResults"
86
+ ]);
87
+ const [callSearchData, setCallSearchData] = useState(false);
88
+ const [searchData, setSearchData] = useState({
89
+ words: [],
90
+ hits: [],
91
+ pages: []
92
+ });
93
+ const [searchHits, setSearchHits] = useState([]);
94
+ const [searchPages, setSearchPages] = useState([]);
95
+ const searchHandler = (event) => {
96
+ if (!callSearchData) {
97
+ setCallSearchData(true);
98
+ }
99
+ if (!searchData || !searchHits || !searchPages) {
100
+ return;
101
+ }
102
+ const inputValues = event.target.value.split(" ");
103
+ const mergedInputValues = [...new Set(inputValues)].sort();
104
+ const hitValues = mergedInputValues.map((value) => {
105
+ if (value.length >= minHitLength) {
106
+ return searchHits.filter((hit) => {
107
+ return new RegExp(value, "i").test(hit);
108
+ });
109
+ } else {
110
+ return [];
111
+ }
112
+ });
113
+ const mergedHitValues = [...new Set(hitValues.flat())].sort();
114
+ const hitIndexes = mergedHitValues.map((value) => {
115
+ return searchData.words.indexOf(value);
116
+ });
117
+ const hitPages = searchPages.flatMap((page) => {
118
+ const titleIndexs = page.title.filter((i) => hitIndexes.indexOf(i) !== -1);
119
+ const contentIndexs = page.content.filter((i) => hitIndexes.indexOf(i) !== -1);
120
+ if (titleIndexs.length || contentIndexs.length) {
121
+ return {
122
+ path: page.path,
123
+ title: titleIndexs,
124
+ toc: page.toc,
125
+ content: contentIndexs
126
+ };
127
+ } else {
128
+ return [];
129
+ }
130
+ });
131
+ const sortedHitPages = [...new Set(hitPages)].sort((a, b) => {
132
+ if (a.title.length !== b.title.length) {
133
+ return (a.title.length - b.title.length) * -1;
134
+ }
135
+ if (a.content.length !== b.content.length) {
136
+ return (a.content.length - b.content.length) * -1;
137
+ }
138
+ return 0;
139
+ }).slice(0, maxHitPages);
140
+ const resultHitPages = sortedHitPages.map((page) => {
141
+ const targetPage = searchData.pages.find((dataPage) => dataPage.path === page.path);
142
+ if (page.title.length) {
143
+ const targetContent = targetPage.title.map((num) => searchData.words[num]).join(" ");
144
+ return {
145
+ path: targetPage.path,
146
+ content: targetContent
147
+ };
148
+ } else {
149
+ let getTargetId = function(targetIndex2, toc) {
150
+ if (!toc.length) {
151
+ return "";
152
+ }
153
+ const targetToc = page.toc.filter((item) => targetIndex2 >= item[0]).slice(-1)[0];
154
+ const targetId2 = targetToc ? "#" + targetToc[1] : "";
155
+ return targetId2;
156
+ };
157
+ const targetWord = page.content[0];
158
+ const targetIndex = targetPage.content.indexOf(targetWord);
159
+ const targetIndexes = targetPage.content.slice(targetIndex, targetIndex + maxHitWords);
160
+ const targetWords = targetIndexes.map((num) => searchData.words[num]).join("");
161
+ const targetContent = "..." + targetWords + "...";
162
+ const targetId = getTargetId(targetIndex, page.toc);
163
+ return {
164
+ path: targetPage.path + targetId,
165
+ content: targetContent
166
+ };
167
+ }
168
+ });
169
+ if (setSearchValues) {
170
+ const filterdInputValues = mergedInputValues.filter((value) => value && !value.includes(" "));
171
+ setSearchValues(filterdInputValues);
172
+ }
173
+ if (setSearchHitValues) {
174
+ setSearchHitValues(mergedHitValues);
175
+ }
176
+ if (setSearchResults) {
177
+ setSearchResults(resultHitPages);
178
+ }
179
+ return;
180
+ };
181
+ useEffect(() => {
182
+ if (callSearchData) {
183
+ const getSearchData = async () => {
184
+ const response = await fetch(jsonPath);
185
+ const data = await response.json();
186
+ setSearchData(data);
187
+ if (data.words && data.hits) {
188
+ const hitWords = [];
189
+ await Promise.all(data.hits.map(async (hit) => {
190
+ return hitWords.push(data.words[hit]);
191
+ }));
192
+ setSearchHits(hitWords);
193
+ }
194
+ if (data.words && data.pages) {
195
+ const optimizePages = [];
196
+ await Promise.all(data.pages.map(async (page) => {
197
+ return optimizePages.push({
198
+ path: page.path,
199
+ title: [...new Set(page.title)].sort(compNum),
200
+ toc: page.toc,
201
+ content: [...new Set(page.content)].sort(compNum)
202
+ });
203
+ }));
204
+ setSearchPages(optimizePages);
205
+ }
206
+ };
207
+ getSearchData();
208
+ }
209
+ }, [callSearchData]);
210
+ return /* @__PURE__ */ React.createElement("input", __spreadValues({
211
+ type: "text",
212
+ onChange: searchHandler
213
+ }, attributes));
214
+ };
215
+ const SearchList = (props) => {
216
+ const _a = props, { searchValues, searchHitValues, searchResults } = _a, attributes = __objRest(_a, ["searchValues", "searchHitValues", "searchResults"]);
217
+ const checkValues = searchValues && searchValues.length;
218
+ const checkHitValues = searchHitValues && searchHitValues.length;
219
+ const checkResults = searchResults && searchResults.length;
220
+ if (checkValues && checkHitValues && checkResults) {
221
+ const regValues = new RegExp(`(${searchValues.join("|")})`, "ig");
222
+ const regHitValues = new RegExp(`(${searchHitValues.join("|")})`, "ig");
223
+ return /* @__PURE__ */ React.createElement("ul", __spreadValues({}, attributes), searchResults.map((item, index) => {
224
+ const words = item.content.split(regHitValues);
225
+ const filteredWords = words.filter((word) => word && word.length > 0);
226
+ const renderdWords = filteredWords.map((word, wordIndex) => {
227
+ if (word.match(regHitValues)) {
228
+ const glyphs = word.split(regValues);
229
+ const renderdGlyphs = glyphs.map((glyph, glyphIndex) => {
230
+ if (glyph.match(regValues)) {
231
+ return /* @__PURE__ */ React.createElement("mark", {
232
+ key: glyphIndex
233
+ }, glyph);
234
+ } else {
235
+ return /* @__PURE__ */ React.createElement("span", {
236
+ key: glyphIndex
237
+ }, glyph);
238
+ }
239
+ });
240
+ return /* @__PURE__ */ React.createElement("span", {
241
+ key: wordIndex
242
+ }, renderdGlyphs);
243
+ } else {
244
+ return /* @__PURE__ */ React.createElement("span", {
245
+ key: wordIndex
246
+ }, word);
247
+ }
248
+ });
249
+ const content = renderdWords;
250
+ return /* @__PURE__ */ React.createElement("li", {
251
+ key: index
252
+ }, /* @__PURE__ */ React.createElement("a", {
253
+ href: item.path
254
+ }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, content)), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("small", null, item.path)))));
255
+ }));
256
+ } else if (checkResults) {
257
+ return /* @__PURE__ */ React.createElement("ul", __spreadValues({}, attributes), searchResults.map((item, index) => {
258
+ return /* @__PURE__ */ React.createElement("li", {
259
+ key: index
260
+ }, /* @__PURE__ */ React.createElement("a", {
261
+ href: item.path
262
+ }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, item.content)), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("small", null, item.path)))));
263
+ }));
264
+ } else {
265
+ return /* @__PURE__ */ React.createElement(React.Fragment, null);
266
+ }
267
+ };
268
+ export {
269
+ Search,
270
+ SearchField,
271
+ SearchList
272
+ };
package/dist/server.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  import type { InlineConfig } from "vite";
2
+ import type { Options as MdxOptions } from "@mdx-js/esbuild";
3
+ import type { MinistaResolveConfig } from "./types.js";
2
4
  export declare function createDevServer(viteConfig: InlineConfig): Promise<void>;
5
+ export declare function createDevServerAssets(config: MinistaResolveConfig, mdxConfig: MdxOptions): Promise<void>;
package/dist/server.js CHANGED
@@ -1,10 +1,64 @@
1
1
  import React from "react";
2
+ import fs from "fs-extra";
3
+ import path from "path";
2
4
  import { createServer } from "vite";
5
+ import { systemConfig } from "./system.js";
6
+ import { getFilterFilePaths } from "./path.js";
7
+ import { emptyResolveDir } from "./empty.js";
8
+ import {
9
+ generateTempRoot,
10
+ generateTempPages,
11
+ generateNoStyleTemp,
12
+ generateHtmlPages
13
+ } from "./generate.js";
14
+ import { buildSearchJson } from "./build.js";
3
15
  async function createDevServer(viteConfig) {
4
16
  const server = await createServer(viteConfig);
5
17
  await server.listen();
6
18
  server.printUrls();
7
19
  }
20
+ async function createDevServerAssets(config, mdxConfig) {
21
+ const stopUseTriggers = [!config.search.useJson];
22
+ const stopUseTrigger = stopUseTriggers.every((trigger) => trigger);
23
+ if (stopUseTrigger) {
24
+ return;
25
+ }
26
+ const searchFile = config.vitePluginSearchJsonTempOutput;
27
+ const searchFileRelative = path.relative(".", searchFile);
28
+ const searchFileExists = fs.existsSync(searchFileRelative);
29
+ const searchUseCacheExists = config.search.cache && searchFileExists;
30
+ const stopCacheTriggers = [searchUseCacheExists];
31
+ const stopCacheTrigger = stopCacheTriggers.every((cache) => cache);
32
+ if (stopCacheTrigger) {
33
+ return;
34
+ }
35
+ await emptyResolveDir(systemConfig.temp.html.outDir);
36
+ await Promise.all([
37
+ generateTempRoot(config, mdxConfig),
38
+ generateTempPages(config, mdxConfig)
39
+ ]);
40
+ await Promise.all([
41
+ generateNoStyleTemp(systemConfig.temp.root.outDir),
42
+ generateNoStyleTemp(systemConfig.temp.pages.outDir)
43
+ ]);
44
+ await generateHtmlPages(config, systemConfig.temp.html.outDir, false);
45
+ const searchEntryPoints = await getFilterFilePaths({
46
+ targetDir: systemConfig.temp.html.outDir,
47
+ include: config.search.include,
48
+ exclude: config.search.exclude,
49
+ exts: "html"
50
+ });
51
+ await buildSearchJson({
52
+ config,
53
+ useCacheExists: searchUseCacheExists,
54
+ entryPoints: searchEntryPoints,
55
+ entryBase: systemConfig.temp.html.outDir,
56
+ outFile: searchFile,
57
+ showLog: false
58
+ });
59
+ return;
60
+ }
8
61
  export {
9
- createDevServer
62
+ createDevServer,
63
+ createDevServerAssets
10
64
  };
package/dist/system.js CHANGED
@@ -22,6 +22,12 @@ const systemConfig = {
22
22
  },
23
23
  icons: {
24
24
  outDir: "node_modules/.minista/svg-sprite-icons"
25
+ },
26
+ html: {
27
+ outDir: "node_modules/.minista/temp-html-pages"
28
+ },
29
+ search: {
30
+ outDir: "node_modules/.minista/temp-search"
25
31
  }
26
32
  }
27
33
  };
package/dist/types.d.ts CHANGED
@@ -78,6 +78,24 @@ export declare type MinistaConfig = {
78
78
  highlightOptions: HighlightOptions;
79
79
  mdxOptions: MdxOptions;
80
80
  };
81
+ search: {
82
+ useJson: boolean;
83
+ cache: boolean;
84
+ outDir: string;
85
+ outName: string;
86
+ include: string[];
87
+ exclude: string[];
88
+ trimTitle: string;
89
+ targetSelector: string;
90
+ hit: {
91
+ minLength: number;
92
+ number: boolean;
93
+ english: boolean;
94
+ hiragana: boolean;
95
+ katakana: boolean;
96
+ kanji: boolean;
97
+ };
98
+ };
81
99
  beautify: {
82
100
  useHtml: boolean;
83
101
  useAssets: boolean;
@@ -157,6 +175,24 @@ export declare type MinistaUserConfig = {
157
175
  highlightOptions?: HighlightOptions;
158
176
  mdxOptions?: MdxOptions;
159
177
  };
178
+ search?: {
179
+ useJson?: boolean;
180
+ cache?: boolean;
181
+ outDir?: string;
182
+ outName?: string;
183
+ include?: string[];
184
+ exclude?: string[];
185
+ trimTitle?: string;
186
+ targetSelector?: string;
187
+ hit?: {
188
+ minLength?: number;
189
+ number?: boolean;
190
+ english?: boolean;
191
+ hiragana?: boolean;
192
+ katakana?: boolean;
193
+ kanji?: boolean;
194
+ };
195
+ };
160
196
  beautify?: {
161
197
  useHtml?: boolean;
162
198
  useAssets?: boolean;
@@ -178,12 +214,15 @@ export declare type MinistaResolvePathConfig = {
178
214
  assetsOutHref: string;
179
215
  downloadOutDir: string;
180
216
  downloadOutHref: string;
217
+ searchJsonOutput: string;
181
218
  viteAssetsOutput: string;
182
219
  viteAssetsImagesOutput: string;
183
220
  viteAssetsFontsOutput: string;
184
221
  vitePluginSvgSpriteIconsSrcDir: string;
185
222
  vitePluginSvgSpriteIconsOutput: string;
186
223
  vitePluginSvgSpriteIconsTempOutput: string;
224
+ vitePluginSearchJsonOutput: string;
225
+ vitePluginSearchJsonTempOutput: string;
187
226
  };
188
227
  export declare type MinistaSystemConfig = {
189
228
  temp: {
@@ -209,6 +248,12 @@ export declare type MinistaSystemConfig = {
209
248
  icons: {
210
249
  outDir: string;
211
250
  };
251
+ html: {
252
+ outDir: string;
253
+ };
254
+ search: {
255
+ outDir: string;
256
+ };
212
257
  };
213
258
  };
214
259
  export declare type MinistaCliDevOptions = {
package/dist/vite.js CHANGED
@@ -108,6 +108,13 @@ async function getViteConfig(config, mdxConfig, cliOptions) {
108
108
  mergedViteConfig.plugins.push(iconsPlugin);
109
109
  mergedViteConfig.resolve.alias.push(iconsResolveAlias);
110
110
  }
111
+ if (config.search.useJson) {
112
+ const searchResolveAlias = {
113
+ find: config.vitePluginSearchJsonOutput,
114
+ replacement: path.resolve(config.vitePluginSearchJsonTempOutput)
115
+ };
116
+ mergedViteConfig.resolve.alias.push(searchResolveAlias);
117
+ }
111
118
  const mdxPlugin = mdx(mdxConfig);
112
119
  mergedViteConfig.plugins.push(mdxPlugin);
113
120
  return cliOptions ? mergeViteConfig(mergedViteConfig, { server: cliOptions }) : mergedViteConfig;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minista",
3
3
  "description": "Next.js Like Development with 100% Static Generate",
4
- "version": "2.6.2",
4
+ "version": "2.7.0",
5
5
  "bin": {
6
6
  "minista": "./bin/minista.js"
7
7
  },
@@ -97,6 +97,7 @@
97
97
  "fs-extra": "^10.1.0",
98
98
  "js-beautify": "^1.14.3",
99
99
  "mime-types": "^2.1.35",
100
+ "mojigiri": "^0.3.0",
100
101
  "node-fetch": "^3.2.5",
101
102
  "node-html-parser": "^5.3.3",
102
103
  "picocolors": "^1.0.0",