<commit_before>"use strict";

import * as path from 'path';
import {Doc} from './Doc';
import {MarkdownRenderer} from './MarkdownRenderer';
import {Styleguide} from './Styleguide';
import {IRenderer} from './Renderer';

export interface IPageConfig {
  label?: string;
  type?: string;
  content?: string;
  styleguide?: Styleguide;
  mdRenderer?: IRenderer;
}

export class Page {
  target: string;
  content: string;
  parent: Page;
  children: Page[];
  mdRenderer: IRenderer;

  constructor(private config: IPageConfig, parent?: Page) {
    /** TODO: rotating demeter in his grave, so at least encapsulate the access to the engine */
    this.mdRenderer = this.config.mdRenderer;
  }

  resolveChildren():Promise<Page> {
    return new Promise((resolve) => resolve(this));
  }

  buildContent():Promise<Page> {
      var contentPromise:Promise<any>;

      switch(this.config.type) {
        case "md":
          contentPromise = new Doc(path.resolve(this.config.content), this.config.label).load()
          .then((doc: Doc) => {
            return this.mdRenderer.render(doc);
          });
          break;
        default:
          contentPromise = new Promise((resolve) => resolve(this));
        // case "tags":
        //   this.content = "";

      }

      return contentPromise
      .then((content: string) => {
        this.content = content;
        return this
      });
  }

  build():Promise<Page> {
    return this.resolveChildren()
    .then((page) => this.buildContent())
    .then(() => {return this; });
  }
}<commit_msg>implemented child resolution for pages<commit_after>"use strict";

import * as path from 'path';
import {Doc} from './Doc';
import {MarkdownRenderer} from './MarkdownRenderer';
import {Styleguide} from './Styleguide';
import {IRenderer} from './Renderer';

export interface IPageConfig {
  label?: string;
  type?: string;
  content?: string;
  styleguide?: Styleguide;
  mdRenderer?: IRenderer;
}

export class Page {
  target: string;
  content: string;
  parent: Page;
  children: Page[];
  mdRenderer: IRenderer;

  constructor(private config: IPageConfig, parent?: Page) {
    /** TODO: rotating demeter in his grave, so at least encapsulate the access to the engine */
    this.mdRenderer = this.config.mdRenderer;
  }

  resolveChildren():Promise<Page> {
    if (!!this.children && this.children.length > 0) {
      return Promise.all(this.children.map(childPageConfig => {
        return new Page(childPageConfig, this).build();
      }))
      .then(children => {
        this.children = children;
        return this;
      });
    } else {
      return new Promise((resolve) => resolve(this));
    }
  }

  buildContent():Promise<Page> {
      var contentPromise:Promise<any>;

      switch(this.config.type) {
        case "md":
          contentPromise = new Doc(path.resolve(this.config.content), this.config.label).load()
          .then((doc: Doc) => {
            return this.mdRenderer.render(doc);
          });
          break;
        case "tags":
          // TODO: handle tag pages
        default:
          contentPromise = new Promise((resolve) => resolve(this));

      }

      return contentPromise
      .then((content: string) => {
        this.content = content;
        return this
      });
  }

  build():Promise<Page> {
    return this.resolveChildren()
    .then((page) => this.buildContent())
    .then(() => {return this; });
  }
}
{'fraction_non_alphanumeric': 0.14223002633889376, 'fraction_numerical': 0.000292654375182909, 'mean_word_length': 2.76431718061674, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3769106', 'n_tokens_mistral': 997, 'n_tokens_neox': 983, 'n_words': 253}