Skip to content

Commit

Permalink
Use menus config file instead of frontmatters
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Oct 24, 2023
1 parent 8c87647 commit e573dac
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
13 changes: 5 additions & 8 deletions src/containers/transform/TaskLocalFileTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {FileContentService} from '../../utils/FileContentService';
import {GoogleFile, MimeTypes} from '../../model/GoogleFile';
import {BinaryFile, DrawingFile, LocalFile, MdFile} from '../../model/LocalFile';
import {SvgTransform} from '../../SvgTransform';
import {NavigationHierarchy} from './generateNavigationHierarchy';
import {generateDocumentFrontMatter} from './frontmatters/generateDocumentFrontMatter';
import {generateConflictMarkdown} from './frontmatters/generateConflictMarkdown';
import {OdtProcessor} from '../../odt/OdtProcessor';
Expand Down Expand Up @@ -48,7 +47,6 @@ export class TaskLocalFileTransform extends QueueTask {
private googleFile: GoogleFile,
private destinationDirectory: FileContentService,
private localFile: LocalFile,
private hierarchy: NavigationHierarchy,
private localLinks: LocalLinks,
private userConfig: UserConfig
) {
Expand All @@ -60,7 +58,7 @@ export class TaskLocalFileTransform extends QueueTask {
}

async run(): Promise<QueueTask[]> {
await this.generate(this.localFile, this.hierarchy);
await this.generate(this.localFile);

return [];
}
Expand Down Expand Up @@ -125,7 +123,7 @@ export class TaskLocalFileTransform extends QueueTask {
});
}

async generateDocument(localFile: MdFile, googleFile: GoogleFile, hierarchy: NavigationHierarchy) {
async generateDocument(localFile: MdFile) {
let frontMatter;
let markdown;
let links = [];
Expand Down Expand Up @@ -156,7 +154,7 @@ export class TaskLocalFileTransform extends QueueTask {
}
markdown = await converter.convert();
links = Array.from(converter.links);
frontMatter = generateDocumentFrontMatter(localFile, hierarchy, links, this.userConfig.fm_without_version);
frontMatter = generateDocumentFrontMatter(localFile, links, this.userConfig.fm_without_version);
errors = converter.getErrors();
this.warnings = errors.length;
} else {
Expand All @@ -169,7 +167,6 @@ export class TaskLocalFileTransform extends QueueTask {

const workerResult: WorkerResult = await this.jobManagerContainer.scheduleWorker('OdtToMarkdown', {
localFile,
hierarchy,
realFileName: this.realFileName,
fileNameMap,
content,
Expand Down Expand Up @@ -198,7 +195,7 @@ export class TaskLocalFileTransform extends QueueTask {
this.localLinks.append(localFile.id, localFile.fileName, links);
}

async generate(localFile: LocalFile, hierarchy: NavigationHierarchy): Promise<void> {
async generate(localFile: LocalFile): Promise<void> {
try {
const verStr = this.localFile.version ? ' #' + this.localFile.version : ' ';
if (localFile.type === 'conflict') {
Expand All @@ -218,7 +215,7 @@ export class TaskLocalFileTransform extends QueueTask {
// const googleFile = await this.googleScanner.getFileById(localFile.id);
// const downloadFile = await this.downloadFilesStorage.findFile(f => f.id === localFile.id);
if (this.googleFile) { // && downloadFile
await this.generateDocument(localFile, this.googleFile, hierarchy);
await this.generateDocument(localFile);
}
} else if (localFile.type === 'drawing') {
this.logger.info('Transforming drawing: ' + this.localFile.fileName + verStr);
Expand Down
11 changes: 10 additions & 1 deletion src/containers/transform/TransformContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ export class TransformContainer extends Container {
googleFile,
destinationDirectory,
localFile,
this.hierarchy,
this.localLinks,
this.userConfigService.config
);
Expand Down Expand Up @@ -329,6 +328,7 @@ export class TransformContainer extends Container {
await this.localLinks.load();

this.hierarchy = await this.loadNavigationHierarchy();
await this.writeHugoMenu(this.hierarchy);

const processed = new Set<string>();
const previouslyFailed = new Set<string>();
Expand Down Expand Up @@ -507,6 +507,15 @@ export class TransformContainer extends Container {
async destroy(): Promise<void> {
}

async writeHugoMenu(hierarchy: NavigationHierarchy) {
const menus = {
main: Object.values(hierarchy)
};

await this.generatedFileService.mkdir('config/_default');
await this.generatedFileService.writeJson('config/_default/menu.en.json', menus);
}

async loadNavigationHierarchy(): Promise<NavigationHierarchy> {
const googleFiles: GoogleFile[] = await this.filesService.readJson('.folder-files.json') || [];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import yaml from 'js-yaml';

import {NavigationHierarchy} from '../generateNavigationHierarchy';
import {MdFile} from '../../../model/LocalFile';
import {FRONTMATTER_DUMP_OPTS} from './frontmatter';

export function generateDocumentFrontMatter(localFile: MdFile, navigationHierarchy: NavigationHierarchy, links: string[],
export function generateDocumentFrontMatter(localFile: MdFile, links: string[],
fm_without_version = false) {
const obj = {
id: localFile.id,
Expand All @@ -19,18 +18,6 @@ export function generateDocumentFrontMatter(localFile: MdFile, navigationHierarc
wikigdrive: !fm_without_version ? process.env.GIT_SHA : undefined
};

if (navigationHierarchy[localFile.id]) {
const navigationData = navigationHierarchy[localFile.id];
obj['menu'] = {
main: {
name: navigationData.name,
identifier: navigationData.identifier,
parent: navigationData.parent,
weight: navigationData.weight,
}
};
}

const fmt = yaml.dump(obj, FRONTMATTER_DUMP_OPTS);

return '---\n' + fmt + '---\n';
Expand Down
2 changes: 1 addition & 1 deletion src/odt/executeOdtToMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function executeOdtToMarkdown(workerData) {
const markdown = await converter.convert();
const links = Array.from(converter.links);

const frontMatter = generateDocumentFrontMatter(workerData.localFile, workerData.hierarchy, links, workerData.fm_without_version);
const frontMatter = generateDocumentFrontMatter(workerData.localFile, links, workerData.fm_without_version);
const errors = converter.getErrors();
return { links, frontMatter, markdown, errors };
}

0 comments on commit e573dac

Please sign in to comment.