Skip to content

Commit

Permalink
Allow for the option to add a custom summary.j2 to the generator
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofVDB1 committed Jul 23, 2024
1 parent 46dac60 commit 817ce76
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/oslo-generator-html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ The service is executed from the CLI and expects the following parameters:
| `--specificationName` | Title of the document | No ||
| `--language` | The language in which the HTML file must be generated (labels) | :heavy_check_mark: ||
| `--silent` | Suppress log messages | No | `true` or `false` (default) |
| `--summary` | The URL or local file path to a custom jinja summary document | No | summary.j2 |

## Usage

```bash
oslo-generator-html --input webuniversum-config.json --language nl --stakeholders stakeholders.json --metadata metadata.json
oslo-generator-html --input webuniversum-config.json --language nl --specificationType ApplicationProfile --specificationName "OSLO-Verkeersmetingen" --stakeholders stakeholders.json --metadata metadata.json
oslo-generator-html --input webuniversum-config.json --language nl --specificationType ApplicationProfile --specificationName "OSLO-Verkeersmetingen" --stakeholders stakeholders.json --metadata metadata.json --summary summary.j2
```
24 changes: 22 additions & 2 deletions packages/oslo-generator-html/lib/HtmlGenerationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ export class HtmlGenerationService implements IService {
}

public async run(): Promise<void> {
const [config, stakeholders, metadata] = await Promise.all([
const [config, stakeholders, metadata, summary] = await Promise.all([
this.readConfigFile(this.configuration.input),
this.readConfigFile(this.configuration.stakeholders),
this.readConfigFile(this.configuration.metadata),
this.configuration.summary
? this.readFile(this.configuration.summary)
: Promise.resolve(undefined),
]);

const indexPath =
Expand All @@ -49,9 +52,15 @@ export class HtmlGenerationService implements IService {
: 'application-profile/index.njk';

let data: any = {};

// Remove any jinja tags from the summary since they can't be interpreted dynamically
if (summary) {
const cleanedSummary = summary.replace(/{%.*?%}/g, '');
data.summary = cleanedSummary;
}

const languageKey: Languages =
Languages[<keyof typeof Languages>this.configuration.language];
// AP

const { classes, dataTypes } = config;

Expand Down Expand Up @@ -147,4 +156,15 @@ export class HtmlGenerationService implements IService {
throw error;
}
}

private async readFile(file: string): Promise<any> {
try {
const buffer: Buffer = await fetchFileOrUrl(file);
const fileContent = buffer.toString();
return fileContent;
} catch (error) {
console.error('Error reading or parsing file:', error);
throw error;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export class HtmlGenerationServiceRunner extends AppRunner<
default: false,
boolean: true,
})
.option('summary', {
describe: 'Input file containing the summary of the publication',
type: 'string',
})
.demandOption(['input', 'metadata', 'language', 'stakeholders'])
.help('h')
.alias('h', 'help');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ export class HtmlGenerationServiceConfiguration implements IConfiguration {
*/
private _specificationName: string | undefined;

/**
* Local path or URL to the summary jinja
*/
private _summary: string | undefined;

public async createFromCli(params: YargsParams): Promise<void> {
this._input = <string>params.input;
this._output = <string>params.output;
this._stakeholders = <string>params.stakeholders;
this._metadata = <string>params.metadata;
this._language = <string>params.language;
this._summary = <string>params.summary;
this._specificationType = this.getSpecificationType(
<string>params.specificationType,
);
Expand Down Expand Up @@ -111,6 +117,10 @@ export class HtmlGenerationServiceConfiguration implements IConfiguration {
return this._specificationName;
}

public get summary(): string | undefined {
return this._summary;
}

private getSpecificationType(value: string): SpecificationType {
switch (value) {
case 'Vocabulary':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<div class="region region--no-space-top typography" id="summary">
<h2 class="h2" aria-level="1" role="heading" id="h2_sotd">Samenvatting</h2>
{% block summary %}
{% if data.metadata.description %}
{{ data.metadata.description[language] }}
{% if data.summary %}
{{ data.summary | safe }}
{% else %}
{% if data.metadata.description %}
{{ data.metadata.description[language] }}
{% endif %}
{% endif %}
{% endblock %}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
typeof="bibo:Chapter"
resource="#ref"
rel="bibo:Chapter">
<h2 class="h2" aria-level="1" role="heading" id="h2_abstract">Samenvatting</h2>
<div class="region region--no-space-top typography" id="summary">
<h2 class="h2" aria-level="1" role="heading" id="h2_abstract">Samenvatting</h2>
{% block summary %}
<p>
Het {{ data.metadata.title }} vocabularium specificeert een aantal klassen en eigenschappen om een
{{ data.metadata.title | lower }} te beschrijven.
</p>
<p>
{{ data.metadata.abstract[language] }}
</p>
{% if data.summary %}
{{ data.summary | safe }}
{% else %}
<p>
Het {{ data.metadata.title }} vocabularium specificeert een aantal klassen en eigenschappen om een
{{ data.metadata.title | lower }} te beschrijven.
</p>
<p>
{{ data.metadata.abstract[language] }}
</p>
{% endif %}
{% endblock %}
</div>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<div class="layout layout--wide">
<div class="grid">
<div class="col--8-12 col--12-12--s">
{% include "components/voc/introduction.njk" %}
{% include "components/voc/summary.njk" %}
{% include "components/voc/status.njk" %}
{% include "components/license.njk" %}
Expand Down

0 comments on commit 817ce76

Please sign in to comment.