Skip to content

Commit

Permalink
Merge pull request #539 from biz-dev-ops/feature/auto-h1
Browse files Browse the repository at this point in the history
Feature/auto h1
  • Loading branch information
arjangeertsema authored Jan 16, 2024
2 parents 340ae6d + aee6c27 commit c2abf4f
Show file tree
Hide file tree
Showing 23 changed files with 460 additions and 518 deletions.
2 changes: 1 addition & 1 deletion assets/scripts/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
li.classList.add("active");

const a = document.createElement("a");
a.href = `../${branch.path}`;
a.href = `${x_md_docs_cli_root}${branch.path}`;
a.setAttribute("title", branch.name);

branch.name.split("/").forEach((slug, idx, array) => {
Expand Down
11 changes: 6 additions & 5 deletions assets/style/page/theme.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
:root {
/* Brand colors */
--color-brand-a80: rgba(var(--rgb-brand) / 80%);
--color-brand-a60: rgba(var(--rgb-brand) / 60%);
--color-brand-a40: rgba(var(--rgb-brand) / 40%);
--color-brand-a20: rgba(var(--rgb-brand) / 20%);
--color-brand-a10: rgba(var(--rgb-brand) / 10%);
--color-brand-a80: color-mix(in srgb, rgb(var(--rgb-brand)) 80%, white);
--color-brand-a60: color-mix(in srgb, rgb(var(--rgb-brand)) 60%, white);
--color-brand-a40: color-mix(in srgb, rgb(var(--rgb-brand)) 40%, white);
--color-brand-a20: color-mix(in srgb, rgb(var(--rgb-brand)) 20%, white);
--color-brand-a10: color-mix(in srgb, rgb(var(--rgb-brand)) 10%, white);

/* Colors */
--color-white-rgb: 255 255 255;
Expand All @@ -13,6 +13,7 @@
--color-white-a20: rgba(var(--color-white-rgb) / 20%);
--color-white-a50: rgba(var(--color-white-rgb) / 50%);
--color-white-a90: rgba(var(--color-white-rgb) / 90%);

--color-black-rgb: 0 0 0;
--color-black: rgb(var(--color-black-rgb));
--color-black-a05: rgba(var(--color-black-rgb) / 5%);
Expand Down
3 changes: 3 additions & 0 deletions assets/style/theme.css
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));
}
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);
}
}
15 changes: 12 additions & 3 deletions bin/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const git = require('../utils/git');
const files = require('../utils/files');

const Locale = require('../locale');
const Relative = require('../utils/relative');

const MarkdownRenderer = require('../utils/markdown');
const Menu = require('../utils/menu');
const PageUtil = require('../utils/page-util');
const Sitemap = require('../utils/sitemap');
const CucumberTestExecutionParser = require('../utils/bdd//cucumber-test-execution-parser');
const SpecflowTestExecutionParser = require('../utils/bdd/specflow-test-execution-parser');
Expand All @@ -34,6 +34,7 @@ const GherkinParser = require('../utils/bdd/gherkin-parser');

const CompositeFileParser = require('../file-parsers/composite-file-parser');
const BPMNFileParser = require('../file-parsers/bpmn-file-parser');
const BusinessReferenceArchitectureFileParser = require('../file-parsers/business-reference-architecture-file-parser');
const DrawIOFileParser = require('../file-parsers/drawio-file-parser');
const FeatureFileParser = require('../file-parsers/feature-file-parser');
const MarkdownFileParser = require('../file-parsers/markdown-file-parser');
Expand Down Expand Up @@ -62,6 +63,8 @@ const CleanUpHtmlParser = require('../html-parsers/clean-up-html-parser');
const DefinitionHtmlParser = require('../html-parsers/definition-html-parser');
const ImageHtmlParser = require('../html-parsers/image-html-parser');
const ImageSVGHtmlParser = require('../html-parsers/image-svg-html-parser');
const RelativeUrlHtmlParser = require('../html-parsers/relative-url-html-parser');
const RemoveH1HtmlParser = require('../html-parsers/remove-h1-html-parser');
const FullscreenHtmlParser = require('../html-parsers/fullscreen-html-parser');
const HeadingHtmlParser = require('../html-parsers/heading-html-parser');
const UnsortedListHtmlParser = require('../html-parsers/unsorted-list-html-parser');
Expand Down Expand Up @@ -412,10 +415,10 @@ Please review the error and fix the problem. A new version will be automaticly b
'testExecutionStore': asClass(TestExecutionStore).singleton(),
'userTaskParser': asClass(UserTaskParser).singleton(),
'menu': asClass(Menu).singleton(),
'pageUtil': asClass(PageUtil).singleton(),
'sitemap': asClass(Sitemap).singleton(),
'markdownRenderer': asClass(MarkdownRenderer).singleton(),
'locale': asClass(Locale).singleton(),
'relative': asClass(Relative).singleton(),
'progress': asValue(logger.progress),

//BDD
Expand All @@ -432,6 +435,7 @@ Please review the error and fix the problem. A new version will be automaticly b
//File parser
'fileParser': asClass(CompositeFileParser).singleton(),
'bpmnFileParser': asClass(BPMNFileParser).singleton(),
'businessReferenceArchitectureFileParser': asClass(BusinessReferenceArchitectureFileParser).singleton(),
'drawIOFileParser': asClass(DrawIOFileParser).singleton(),
'featureFileParser': asClass(FeatureFileParser).singleton(),
'markdownFileParser': asClass(MarkdownFileParser).singleton(),
Expand All @@ -447,6 +451,8 @@ Please review the error and fix the problem. A new version will be automaticly b
'headingHtmlParser': asClass(HeadingHtmlParser).singleton(),
'imageHtmlParser': asClass(ImageHtmlParser).singleton(),
'imageSVGHtmlParser': asClass(ImageSVGHtmlParser).singleton(),
'relativeUrlHtmlParser': asClass(RelativeUrlHtmlParser).singleton(),
'removeH1HtmlParser': asClass(RemoveH1HtmlParser).singleton(),
'unsortedListHtmlParser': asClass(UnsortedListHtmlParser).singleton(),

//Anchor parser
Expand Down Expand Up @@ -490,6 +496,7 @@ Please review the error and fix the problem. A new version will be automaticly b
//File parsers: order can be important!
'fileParsers': [
'bpmnFileParser',
'businessReferenceArchitectureFileParser',
'drawIOFileParser',
'featureFileParser',
'markdownEmailFileParser',
Expand All @@ -506,7 +513,9 @@ Please review the error and fix the problem. A new version will be automaticly b
'unsortedListHtmlParser',
'imageHtmlParser',
'fullscreenHtmlParser',
'cleanUpHtmlParser'
'cleanUpHtmlParser',
'removeH1HtmlParser',
'relativeUrlHtmlParser'
],

//Anchor parsers, order can be important!
Expand Down
7 changes: 4 additions & 3 deletions bin/components/email-component/template.pug
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
doctype html
html
head
base(href=data.baseHref target='_top')
meta(charset='UTF-8')
title=data.title

link(rel='stylesheet' type='text/css' href=data.root + 'assets/style/email/style.css')
link(rel='stylesheet' type='text/css' href='assets/style/email/style.css')

if(data.googleFont)
link(rel='preconnect' href='https://fonts.googleapis.com')
Expand All @@ -26,7 +27,7 @@ html
article
header
figure
img(src=data.root + 'assets/images/message/logo.svg')
img(src='assets/images/message/logo.svg')

main
| !{data.message}
Expand Down Expand Up @@ -61,4 +62,4 @@ html
};
})();

script(src=data.root + 'assets/iframe-resizer-dist/iframeResizer.contentWindow.js' charset='UTF-8')
script(src='assets/iframe-resizer-dist/iframeResizer.contentWindow.js' charset='UTF-8')
9 changes: 5 additions & 4 deletions bin/components/message-component/template.pug
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
doctype html
html
head
base(href=data.baseHref target='_top')
meta(charset='UTF-8')
title=data.title

link(rel='stylesheet' type='text/css' href=data.root + 'assets/style/message/style.css')
link(rel='stylesheet' type='text/css' href='assets/style/message/style.css')

if(data.googleFont)
link(rel='preconnect' href='https://fonts.googleapis.com')
Expand All @@ -16,7 +17,7 @@ html
header
div(class='logo')
figure
img(src=data.root + 'assets/images/message/logo.svg')
img(src='assets/images/message/logo.svg')

footer
div(class='contact')
Expand Down Expand Up @@ -48,7 +49,7 @@ html
each attachment in data.attachments
li=attachment.name

script(src=data.root + 'assets/iframe-resizer-dist/iframeResizer.contentWindow.js' charset='UTF-8')
script(src='assets/iframe-resizer-dist/iframeResizer.contentWindow.js' charset='UTF-8')

script.
window.PagedConfig = {
Expand All @@ -58,7 +59,7 @@ html
}
};

script(src=data.root + 'assets/pagedjs/paged.polyfill.min.js')
script(src='assets/pagedjs/paged.polyfill.min.js')

script.
(() => {
Expand Down
5 changes: 3 additions & 2 deletions bin/components/page-component/template.pug
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mixin breadcrumbItems(items)
doctype html
html
head
base(href=relative.root target='_top')
base(href=baseHref target='_top')
meta(http-equiv='Content-Type' content='text/html; charset=UTF-8')
meta(name='viewport' content='width=device-width,initial-scale=1.0')
meta(name='robots' content='noindex,nofollow')
Expand Down Expand Up @@ -97,9 +97,10 @@ html
| !{content}

script.
window.x_md_docs_cli_root = '!{baseHref}!{root}'
window.x_md_docs_cli_branch = '!{git.branch.name}';

script(src=relative.basePath + 'branches.js' charset='UTF-8')
script(src=root + 'branches.js' charset='UTF-8')

script(src='assets/iframe-resizer-dist/iframeResizer.js' charset='UTF-8')
script(src='assets/svg-pan-zoom-dist/svg-pan-zoom.min.js' charset='UTF-8')
Expand Down
Loading

0 comments on commit c2abf4f

Please sign in to comment.