world/book/node_modules/honkit/lib/json/encodeSummaryArticleWithCache.js
2025-05-12 05:38:44 +09:00

37 lines
1.1 KiB
JavaScript

"use strict";
/**
Encode a SummaryArticle to JSON
@param {SummaryArticle}
@return {Object}
*/
Object.defineProperty(exports, "__esModule", { value: true });
const lru_map_1 = require("lru_map");
const LRU_MAP_LIMIT = 1000;
const articleCacheMap = new lru_map_1.LRUMap(LRU_MAP_LIMIT);
function encodeSummaryArticleWithCache(article, recursive) {
if (articleCacheMap.has(article)) {
return articleCacheMap.get(article);
}
let articles = undefined;
if (recursive !== false) {
articles = article
.getArticles()
.map((article) => encodeSummaryArticleWithCache(article))
.toJS();
}
const encodedArticle = {
title: article.getTitle(),
level: article.getLevel(),
depth: article.getDepth(),
anchor: article.getAnchor(),
url: article.getUrl(),
path: article.getPath(),
ref: article.getRef(),
articles: articles
};
articleCacheMap.set(article, encodedArticle);
return encodedArticle;
}
exports.default = encodeSummaryArticleWithCache;