-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(PN-12551): generate html template script #13
base: feature/bilinguismo-amministrativo
Are you sure you want to change the base?
Conversation
package.json
Outdated
"description": "This repo contains the mail templates used by Piattaforma Notifiche, created using [MJML](https://mjml.io/) markup language.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SarahDonvito ti suggerisco qui di aggiungere uno script tipo "generate" che chiama lo script node generateHtmlTemplate.
da qui possiamo lavorare sui parametri da passare in input allo script node per la generazione dei template
generateHtmlTemplates.js
Outdated
} | ||
|
||
async function generateHtmlTemplates() { | ||
const languages = ["de"]; // Elenca le lingue supportate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qui avremo "de", "fr", "sl"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dobbiamo aggiungere anche it, corretto? @SarahDonvito la generazione del template base potrebbe comunque passare da qui, ti torna?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non so se avrebbe senso dal momento che vorrebbe dire realizzare a mano l'html ita qui e copiarlo in delivery-push
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
così avremo la separazione del contenuto dal layout però (soprattutto in ottica di template engine)
package.json
Outdated
"keywords": [], | ||
"author": "", | ||
"license": "SEE LICENSE IN LICENSE", | ||
"dependencies": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forse è meglio settarle come dev-dependencies
.idea/.gitignore
Outdated
@@ -0,0 +1,3 @@ | |||
# Default ignored files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this file?
.idea/vcs.xml
Outdated
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this file?
"/i18n", | ||
`${language}.json` | ||
); | ||
const result = await fs.readJson(filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when using await, the code must be surrounded by a try catch block. insert try catch blocks in all cases and log the errors with a custom message.
For example console.error("Error during translations loading", e)
// generazione template BILINGUA | ||
async function generateHtmlTemplates() { | ||
const languages = ["it", "de", "fr", "sl"]; // Elenca le lingue supportate | ||
const templates = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should avoid to define the list in this way because, if we add a new template, we have to remember to edit this file too.
Get the templates reading the content of the resources/templates directory
const templateLang = | ||
language === "it" | ||
? templateContent.replaceAll( | ||
/<[^>]*data-hide-on-it="true"[^>]*>[\s\S]*?<\/[^>]*>/g, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This not work on nested elements. Try on regex101 and use and example string like this
<div>
<div-to-remove data-hide-on-it="true">
<p>
This a text for testing
</p>
</div-to-remove>
</div>
you will see that the regexp will stop at p closing tag. This happen because the regular expression stops to the first closing tag regardless of whether it is the same as opening with data-hide-on-it.
Maybe we can manage the task in a simple way:
- or define a custom tag (i.e.
<start-lang></end-lang>
). this tag must be always removed with the difference that in italian must me removed also the content - or define a comment (i.e.
<!-- START lang --> and <!-- END lang -->
)
…nto fix/PN-12551 # Conflicts: # output/templates/NotificationAARForEMAIL/NotificationAARForEMAIL_sl.html
To test
yarn generate
to check template are correctly produced