UNPKG

conflutora

Version:

Provider to convert and publish Antora documentation on Confluence

72 lines 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PageService = void 0; const Logger_1 = require("../utils/Logger"); class PageService { client; siteStructure; logger = new Logger_1.Logger(this.constructor.name); constructor(client, siteStructure) { this.client = client; this.siteStructure = siteStructure; } async deletePage(page) { try { await this.client.deletePage(page.id); this.logger.info(`Deleted page: ${page.title}`); } catch (error) { this.logger.error(`Error deleting page: ${page.title}`, error); } } async handleAttachments(page, attachments) { for (const attachment of attachments) { try { const existingAttachment = await this.client.getAttachment(page.id, attachment.fileName); if (existingAttachment && existingAttachment.results.length > 0) { this.logger.warn(`Update attachment not implemented: ${attachment.fileName}`); // const { id } = existingAttachment.results[0] // await this.client.updateAttachment({ // pageId: page.id, // fileName: attachment.fileName, // file: attachment.file, // comment: attachment.comment, // attachmentId: id // }) // this.logger.info(`Updated attachment: ${attachment.fileName}`) } else { await this.client.addAttachment(page.id, attachment.fileName, attachment.file, attachment.comment); this.logger.info(`Created new attachment: ${attachment.fileName}`); } } catch (error) { this.logger.error(`Error handling attachment ${attachment.fileName}`, error); } } } async processPage(page) { const parentPage = this.siteStructure.getParentPage(page); const remotePage = await this.client.findPageByTitle(page.title); if (remotePage) { page.setConfluenceId(remotePage.id); // await this.client.updatePage(page) this.logger.info(`[Process] Updated page: ${page.title}`); } else { if (parentPage) page.setConfluenceParentId(parentPage.confluenceId); const createdPage = await this.client.createPage(page); page.setConfluenceId(createdPage.id); this.logger.info(`[Process] Created page: ${page.title}`); } } async publishPages() { const pages = this.siteStructure.getAllPages(); for (const page of pages) { await this.processPage(page); } } } exports.PageService = PageService; //# sourceMappingURL=page.service.js.map