-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #539 from biz-dev-ops/feature/auto-h1
Feature/auto h1
- Loading branch information
Showing
23 changed files
with
460 additions
and
518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
:root { | ||
--rgb-brand: 0 102 255; | ||
--rgb-brand-secondary: var(--rgb-brand); | ||
--rgb-text: 26 26 26; | ||
--rgb-heading: 0 51 102; | ||
|
||
--color-brand-base: rgb(var(--rgb-brand)); | ||
--color-brand-secondary: rgb(var(--rgb-brand-secondary)); | ||
--text-color-base: rgba(var(--rgb-text) / 90%); | ||
--text-color-heading: rgb(var(--rgb-heading)); | ||
} |
97 changes: 6 additions & 91 deletions
97
bin/anchor-parsers/business-reference-architecture-anchor-parser/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,33 @@ | ||
const fs = require('fs').promises; | ||
const { env, cwd } = require('process'); | ||
const { env } = require('process'); | ||
const colors = require('colors'); | ||
const path = require('path'); | ||
const glob = require('glob-promise'); | ||
|
||
const files = require('../../utils/files');; | ||
const jsonSchemaParser = require('../../utils/json-schema-parser'); | ||
const files = require('../../utils/files'); | ||
|
||
const AnchorParser = require('../anchor-parser'); | ||
|
||
module.exports = class BusinessReferenceArchitectureParser extends AnchorParser { | ||
constructor({ businessReferenceArchitectureComponent }) { | ||
constructor({ businessReferenceArchitectureComponent, sitemap }) { | ||
super(); | ||
|
||
this.component = businessReferenceArchitectureComponent; | ||
this.sitemap = sitemap; | ||
} | ||
|
||
_canParse(anchor) { return anchor.href.endsWith('business-reference-architecture.yml') || anchor.href.endsWith('business-reference-architecture.yaml'); } | ||
|
||
async _parse(anchor, file) { | ||
console.info(colors.green(`\t\t\t\t* parsing yaml`)); | ||
const json = await this.#getJson(file); | ||
|
||
if (env.NODE_ENV === 'development') | ||
await fs.writeFile(`${file}.json`, JSON.stringify(json)); | ||
const json = JSON.parse(await files.readFileAsString(`${file}.json`)); | ||
|
||
console.info(colors.green(`\t\t\t\t* rendering`)); | ||
const html = this.component.render({ | ||
json: JSON.stringify(json) | ||
.replace(/(\r\n|\n|\r)/gm, "") | ||
.replace(/"/g, """) | ||
json: json | ||
}); | ||
|
||
if (env.NODE_ENV === 'development') | ||
await fs.writeFile(`${file}.html`, html); | ||
|
||
return html; | ||
} | ||
|
||
async #getJson(file) { | ||
const json = await jsonSchemaParser.parse(file); | ||
await this.#dereference(json, path.dirname(file)); | ||
return json; | ||
} | ||
|
||
async #dereference(el, basePath) { | ||
if (!el) { | ||
return; | ||
} | ||
|
||
if (Array.isArray(el)) { | ||
el.forEach(item => this.#dereference(item, basePath)); | ||
return; | ||
} | ||
|
||
if (typeof el === 'object') { | ||
for (const [key, value] of Object.entries(el)) { | ||
if (!["groups", "buttons"].includes(key) || typeof value !== "string") { | ||
await this.#dereference(value, basePath); | ||
} | ||
else { | ||
const ref = path.resolve(basePath, value); | ||
|
||
if (await !files.exists(ref)) { | ||
throw `Path does not exist. ${ref}`; | ||
} | ||
|
||
el[key] = await (key === "groups" ? this.#parseGroups(ref) : this.#parseButtons(ref)); | ||
} | ||
} | ||
return; | ||
} | ||
} | ||
|
||
async #parseGroups(ref) { | ||
const paths = await glob("*/", { cwd: ref }); | ||
|
||
return await Promise.all( | ||
paths.map(async (p) => { | ||
const group = { | ||
title: this.#getTitle(p), | ||
link: await this.#resolveRelativeLinkIfPathContainsIndex(p), | ||
buttons: await this.#parseButtons(p) | ||
}; | ||
return group; | ||
}) | ||
); | ||
} | ||
|
||
async #parseButtons(ref) { | ||
const paths = await glob("*/", { cwd: ref }); | ||
|
||
return await Promise.all( | ||
paths.map(async (p) => { | ||
const button = { | ||
title: this.#getTitle(p), | ||
link: await this.#resolveRelativeLinkIfPathContainsIndex(p) | ||
}; | ||
return button; | ||
}) | ||
); | ||
} | ||
|
||
#getTitle(p) { | ||
const title = path.basename(p); | ||
return title.charAt(0).toUpperCase() + title.slice(1) | ||
.replace("-", " "); | ||
} | ||
|
||
async #resolveRelativeLinkIfPathContainsIndex(p) { | ||
if (!await files.exists(path.resolve(p, "index.md"))) { | ||
return null; | ||
} | ||
|
||
return path.relative(cwd(), p); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.