@xingwangzhe/stalux 1.25.8 → 1.25.9
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/package.json +1 -1
- package/src/plugins/feature-flags.ts +27 -7
package/package.json
CHANGED
|
@@ -170,20 +170,40 @@ export const featureFlagsHast = defineHastPlugin({
|
|
|
170
170
|
},
|
|
171
171
|
});
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
* 直接用 Sätteri AST 分析一篇文章,供文章页、全局统计和 API 复用。
|
|
175
|
-
* 这里不复用内容集合的 data,也不读取 Astro 的渲染 metadata。
|
|
176
|
-
*/
|
|
177
|
-
export async function analyzeFeatureFlags(body: string | undefined): Promise<{
|
|
173
|
+
type FeatureFlagsResult = {
|
|
178
174
|
hasImage: boolean;
|
|
179
175
|
readingMinutes: number;
|
|
180
176
|
wordCount: number;
|
|
181
|
-
}
|
|
182
|
-
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
let processorPromise: ReturnType<typeof createSatteriMarkdownProcessor> | undefined;
|
|
180
|
+
const analysisCache = new Map<string, Promise<FeatureFlagsResult>>();
|
|
181
|
+
|
|
182
|
+
function getFeatureFlagsProcessor() {
|
|
183
|
+
processorPromise ??= createSatteriMarkdownProcessor({
|
|
183
184
|
mdastPlugins: [featureFlagsMdast],
|
|
184
185
|
hastPlugins: [featureFlagsHast],
|
|
185
186
|
features: { math: true },
|
|
186
187
|
});
|
|
188
|
+
return processorPromise;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 直接用 Sätteri AST 分析一篇文章,供文章页、全局统计和 API 复用。
|
|
193
|
+
* 这里不复用内容集合的 data,也不读取 Astro 的渲染 metadata。
|
|
194
|
+
*/
|
|
195
|
+
export function analyzeFeatureFlags(body: string | undefined): Promise<FeatureFlagsResult> {
|
|
196
|
+
const content = body ?? "";
|
|
197
|
+
const cached = analysisCache.get(content);
|
|
198
|
+
if (cached) return cached;
|
|
199
|
+
|
|
200
|
+
const resultPromise = analyzeFeatureFlagsUncached(content);
|
|
201
|
+
analysisCache.set(content, resultPromise);
|
|
202
|
+
return resultPromise;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function analyzeFeatureFlagsUncached(body: string): Promise<FeatureFlagsResult> {
|
|
206
|
+
const processor = await getFeatureFlagsProcessor();
|
|
187
207
|
const result = await processor.render(body ?? "");
|
|
188
208
|
const metadata = result.metadata.frontmatter as Record<string, unknown>;
|
|
189
209
|
const proseWords = (
|