40 lines
1.4 KiB
JavaScript
40 lines
1.4 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const encodeSummaryArticle_1 = __importDefault(require("./encodeSummaryArticle"));
|
|
/**
|
|
Return a JSON representation of a page
|
|
*/
|
|
function encodePage(page, summary) {
|
|
const file = page.getFile();
|
|
const attributes = page.getAttributes();
|
|
const article = summary.getByPath(file.getPath());
|
|
const result = attributes.toJS();
|
|
if (article) {
|
|
result.title = article.getTitle();
|
|
result.level = article.getLevel();
|
|
result.depth = article.getDepth();
|
|
const nextArticle = summary.getNextArticle(article);
|
|
if (nextArticle) {
|
|
result.next = (0, encodeSummaryArticle_1.default)(nextArticle);
|
|
}
|
|
const prevArticle = summary.getPrevArticle(article);
|
|
if (prevArticle) {
|
|
result.previous = (0, encodeSummaryArticle_1.default)(prevArticle);
|
|
}
|
|
const articles = article
|
|
.getArticles()
|
|
.map((article) => (0, encodeSummaryArticle_1.default)(article))
|
|
.toJS();
|
|
if (articles.length > 0) {
|
|
result.articles = articles;
|
|
}
|
|
}
|
|
result.content = page.getContent();
|
|
result.dir = page.getDir();
|
|
return result;
|
|
}
|
|
exports.default = encodePage;
|