@telefonica/markdown-confluence-sync
Version:
Creates/updates/deletes Confluence pages based on markdown files in a directory. Supports Mermaid diagrams and per-page configuration using frontmatter metadata. Works great with Docusaurus
65 lines (64 loc) • 2.3 kB
JavaScript
// SPDX-FileCopyrightText: 2024 Telefónica Innovación Digital
// SPDX-License-Identifier: Apache-2.0
import { resolve } from "node:path";
import { MarkdownDocumentsFactory } from "./DocusaurusPagesFactory.js";
const DEFAULT_DOCS_DIR = "docs";
const docsDirOption = {
name: "docsDir",
type: "string",
default: DEFAULT_DOCS_DIR,
};
export const MarkdownDocuments = class MarkdownDocuments {
_docsDirOption;
_modeOption;
_initialized = false;
_path;
_pages;
_logger;
_config;
_filesPattern;
_filesMetadata;
_filesIgnore;
_contentPreprocessorOption;
_contentPreprocessor;
_cwd;
constructor({ config, logger, mode, filesPattern, filesMetadata, filesIgnore, contentPreprocessor, cwd, }) {
this._docsDirOption = config.addOption(docsDirOption);
this._cwd = cwd;
this._modeOption = mode;
this._filesPattern = filesPattern;
this._filesMetadata = filesMetadata;
this._filesIgnore = filesIgnore;
this._contentPreprocessorOption = contentPreprocessor;
this._config = config;
this._logger = logger;
}
async read() {
await this._init();
this._logger.debug(`docsDir option is ${this._docsDirOption.value}`);
return this._pages.read();
}
_init() {
this._logger.debug(`mode option is ${this._modeOption.value}`);
if (!this._initialized) {
const path = resolve(this._cwd, this._docsDirOption.value);
this._contentPreprocessor = this._contentPreprocessorOption.value;
const filesMetadata = (this._filesMetadata?.value || []).map((metadata) => ({
...metadata,
path: resolve(this._cwd, metadata.path),
}));
this._path = path;
this._pages = MarkdownDocumentsFactory.fromMode(this._modeOption.value, {
contentPreprocessor: this._contentPreprocessor,
config: this._config,
logger: this._logger,
path: this._path,
filesPattern: this._filesPattern?.value,
filesIgnore: this._filesIgnore?.value,
filesMetadata,
cwd: this._cwd,
});
this._initialized = true;
}
}
};