Add Prettier plugin for Nunjuck templates (#3887)

This commit is contained in:
Veeck
2025-09-11 13:10:53 +02:00
committed by GitHub
parent 3260b9dfe4
commit 08d29c3083
13 changed files with 325 additions and 323 deletions

View File

@@ -18,6 +18,7 @@ Thanks to: @dathbe.
### Added ### Added
- Added configuration option for `User-Agent`, used by calendar & news module (#3255) - Added configuration option for `User-Agent`, used by calendar & news module (#3255)
- [linter] Added prettier plugin for nunjuck templates (#3887)
### Changed ### Changed
@@ -308,7 +309,7 @@ For more info, please read the following post: [A New Chapter for MagicMirror: T
### Added ### Added
- Output of system information to the console for troubleshooting (#3328 and #3337), ignore errors under aarch64 (#3349) - Output of system information to the console for troubleshooting (#3328 and #3337), ignore errors under aarch64 (#3349)
- [core] Add `eslint-plugin-package-json` to lint the `package.json` files (#3368) - [linter] Add `eslint-plugin-package-json` to lint the `package.json` files (#3368)
- [weather] `showHumidity` config is now a string describing where to show this element. Supported values: "wind", "temp", "feelslike", "below", "none". (#3330) - [weather] `showHumidity` config is now a string describing where to show this element. Supported values: "wind", "temp", "feelslike", "below", "none". (#3330)
- electron-rebuild test suite for electron and 3rd party modules compatibility (#3392) - electron-rebuild test suite for electron and 3rd party modules compatibility (#3392)
- Create MM² icon and attach it to electron process (#3407) - Create MM² icon and attach it to electron process (#3407)
@@ -470,7 +471,7 @@ Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not al
- Added UV Index to hourly and current Weather, with support for Openmeteo - Added UV Index to hourly and current Weather, with support for Openmeteo
- Added tests for serveronly - Added tests for serveronly
- Set Timezone `Europe/Berlin` in unit tests (needed for new formatTime tests) - Set Timezone `Europe/Berlin` in unit tests (needed for new formatTime tests)
- Added no-param-reassign eslint rule and fix warnings - [linter] Added no-param-reassign eslint rule and fix warnings
- [updatenotification] Added `sendUpdatesNotifications` feature. Broadcast update with `UPDATES` notification to other modules - [updatenotification] Added `sendUpdatesNotifications` feature. Broadcast update with `UPDATES` notification to other modules
- [updatenotification] Allow force scanning with `SCAN_UPDATES` notification from other modules - [updatenotification] Allow force scanning with `SCAN_UPDATES` notification from other modules
- Added per-calendar fetchInterval - Added per-calendar fetchInterval

View File

@@ -1,13 +1,13 @@
{% if imageUrl or imageFA %} {% if imageUrl or imageFA %}
{% set imageHeight = imageHeight if imageHeight else "80px" %} {% set imageHeight = imageHeight if imageHeight else "80px" %}
{% if imageUrl %} {% if imageUrl %}
<img src="{{ imageUrl }}" <img src="{{ imageUrl }}" height="{{ imageHeight }}" style="margin-bottom: 10px" />
height="{{ imageHeight }}"
style="margin-bottom: 10px" />
{% else %} {% else %}
<span class="bright fas fa-{{ imageFA }}" <span
class="bright fas fa-{{ imageFA }}"
style="margin-bottom: 10px; style="margin-bottom: 10px;
font-size: {{ imageHeight }}"></span> font-size: {{ imageHeight }}"
></span>
{% endif %} {% endif %}
<br /> <br />
{% endif %} {% endif %}

View File

@@ -8,19 +8,25 @@
{% macro escapeTitle(title, url, dangerouslyDisableAutoEscaping=false, showTitleAsUrl=false) %} {% macro escapeTitle(title, url, dangerouslyDisableAutoEscaping=false, showTitleAsUrl=false) %}
{% if dangerouslyDisableAutoEscaping %} {% if dangerouslyDisableAutoEscaping %}
{% if showTitleAsUrl %} {% if showTitleAsUrl %}
<a href="{{ url }}" <a
href="{{ url }}"
style="text-decoration:none; style="text-decoration:none;
color:#ffffff" color:#ffffff"
target="_blank">{{ title | safe }}</a> target="_blank"
>{{ title | safe }}</a
>
{% else %} {% else %}
{{ title | safe }} {{ title | safe }}
{% endif %} {% endif %}
{% else %} {% else %}
{% if showTitleAsUrl %} {% if showTitleAsUrl %}
<a href="{{ url }}" <a
href="{{ url }}"
style="text-decoration:none; style="text-decoration:none;
color:#ffffff" color:#ffffff"
target="_blank">{{ title }}</a> target="_blank"
>{{ title }}</a
>
{% else %} {% else %}
{{ title }} {{ title }}
{% endif %} {% endif %}
@@ -39,9 +45,7 @@
{% if config.showPublishDate %}{{ item.publishDate }}:{% endif %} {% if config.showPublishDate %}{{ item.publishDate }}:{% endif %}
</div> </div>
{% endif %} {% endif %}
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}"> <div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">{{ escapeTitle(item.title, item.url, config.dangerouslyDisableAutoEscaping, config.showTitleAsUrl) }}</div>
{{ escapeTitle(item.title, item.url, config.dangerouslyDisableAutoEscaping, config.showTitleAsUrl) }}
</div>
{% if config.showDescription %} {% if config.showDescription %}
<div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}"> <div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
{% if config.truncDescription %} {% if config.truncDescription %}
@@ -64,9 +68,7 @@
{% if config.showPublishDate %}{{ publishDate }}:{% endif %} {% if config.showPublishDate %}{{ publishDate }}:{% endif %}
</div> </div>
{% endif %} {% endif %}
<div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}"> <div class="newsfeed-title bright medium light{{ ' no-wrap' if not config.wrapTitle }}">{{ escapeTitle(title, url, config.dangerouslyDisableAutoEscaping, config.showTitleAsUrl) }}</div>
{{ escapeTitle(title, url, config.dangerouslyDisableAutoEscaping, config.showTitleAsUrl) }}
</div>
{% if config.showDescription %} {% if config.showDescription %}
<div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}"> <div class="newsfeed-desc small light{{ ' no-wrap' if not config.wrapDescription }}">
{% if config.truncDescription %} {% if config.truncDescription %}
@@ -81,9 +83,7 @@
{% elseif empty %} {% elseif empty %}
<div class="small dimmed">{{ "NEWSFEED_NO_ITEMS" | translate | safe }}</div> <div class="small dimmed">{{ "NEWSFEED_NO_ITEMS" | translate | safe }}</div>
{% elseif error %} {% elseif error %}
<div class="small dimmed"> <div class="small dimmed">{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Newsfeed", ERROR: error}) | safe }}</div>
{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Newsfeed", ERROR: error}) | safe }}
</div>
{% else %} {% else %}
<div class="small dimmed">{{ "LOADING" | translate | safe }}</div> <div class="small dimmed">{{ "LOADING" | translate | safe }}</div>
{% endif %} {% endif %}

View File

@@ -1,3 +1 @@
<div class="small bright"> <div class="small bright">{{ "MODULE_CONFIG_CHANGED" | translate({MODULE_NAME: "Newsfeed"}) | safe }}</div>
{{ "MODULE_CONFIG_CHANGED" | translate({MODULE_NAME: "Newsfeed"}) | safe }}
</div>

View File

@@ -1,6 +1,8 @@
{% macro humidity() %} {% macro humidity() %}
{% if current.humidity %} {% if current.humidity %}
<span class="humidity"><span>{{ current.humidity | decimalSymbol }}</span><sup>&nbsp;<i class="wi wi-humidity humidity-icon"></i></sup></span> <span class="humidity"
><span>{{ current.humidity | decimalSymbol }}</span><sup>&nbsp;<i class="wi wi-humidity humidity-icon"></i></sup
></span>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% if current %} {% if current %}
@@ -47,16 +49,12 @@
<span style="display: inline-block"> <span style="display: inline-block">
{% if config.showIndoorTemperature and indoor.temperature %} {% if config.showIndoorTemperature and indoor.temperature %}
<sup class="small" style="position: relative; display: block; text-align: left;"> <sup class="small" style="position: relative; display: block; text-align: left;">
<span> <span> {{ indoor.temperature | roundValue | unit("temperature") | decimalSymbol }} </span>
{{ indoor.temperature | roundValue | unit("temperature") | decimalSymbol }}
</span>
</sup> </sup>
{% endif %} {% endif %}
{% if config.showIndoorHumidity and indoor.humidity %} {% if config.showIndoorHumidity and indoor.humidity %}
<sub class="small" style="position: relative; display: block; text-align: left;"> <sub class="small" style="position: relative; display: block; text-align: left;">
<span> <span> {{ indoor.humidity | roundValue | unit("humidity") | decimalSymbol }} </span>
{{ indoor.humidity | roundValue | unit("humidity") | decimalSymbol }}
</span>
</sub> </sub>
{% endif %} {% endif %}
</span> </span>
@@ -79,15 +77,11 @@
<br /> <br />
{% endif %} {% endif %}
{% if config.showPrecipitationAmount and current.precipitationAmount %} {% if config.showPrecipitationAmount and current.precipitationAmount %}
<span class="dimmed"> <span class="dimmed"> <span class="precipitationLeadText">{{ "PRECIP_AMOUNT" | translate }}</span> {{ current.precipitationAmount | unit("precip", current.precipitationUnits) }} </span>
<span class="precipitationLeadText">{{ "PRECIP_AMOUNT" | translate }}</span> {{ current.precipitationAmount | unit("precip", current.precipitationUnits) }}
</span>
<br /> <br />
{% endif %} {% endif %}
{% if config.showPrecipitationProbability and current.precipitationProbability %} {% if config.showPrecipitationProbability and current.precipitationProbability %}
<span class="dimmed"> <span class="dimmed"> <span class="precipitationLeadText">{{ "PRECIP_POP" | translate }}</span> {{ current.precipitationProbability }}% </span>
<span class="precipitationLeadText">{{ "PRECIP_POP" | translate }}</span> {{ current.precipitationProbability }}%
</span>
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}

View File

@@ -7,8 +7,10 @@
{% endif %} {% endif %}
{% set forecast = forecast.slice(0, numSteps) %} {% set forecast = forecast.slice(0, numSteps) %}
{% for f in forecast %} {% for f in forecast %}
<tr {% if config.colored %}class="colored"{% endif %} <tr
{% if config.fade %}style="opacity: {{ currentStep | opacity(numSteps) }};"{% endif %}> {% if config.colored %}class="colored"{% endif %}
{% if config.fade %}style="opacity: {{ currentStep | opacity(numSteps) }};"{% endif %}
>
{% if (currentStep == 0) and config.ignoreToday == false and config.absoluteDates == false %} {% if (currentStep == 0) and config.ignoreToday == false and config.absoluteDates == false %}
<td class="day">{{ "TODAY" | translate }}</td> <td class="day">{{ "TODAY" | translate }}</td>
{% elif (currentStep == 1) and config.ignoreToday == false and config.absoluteDates == false %} {% elif (currentStep == 1) and config.ignoreToday == false and config.absoluteDates == false %}
@@ -19,21 +21,13 @@
<td class="bright weather-icon"> <td class="bright weather-icon">
<span class="wi weathericon wi-{{ f.weatherType }}"></span> <span class="wi weathericon wi-{{ f.weatherType }}"></span>
</td> </td>
<td class="align-right bright max-temp"> <td class="align-right bright max-temp">{{ f.maxTemperature | roundValue | unit("temperature") | decimalSymbol }}</td>
{{ f.maxTemperature | roundValue | unit("temperature") | decimalSymbol }} <td class="align-right min-temp">{{ f.minTemperature | roundValue | unit("temperature") | decimalSymbol }}</td>
</td>
<td class="align-right min-temp">
{{ f.minTemperature | roundValue | unit("temperature") | decimalSymbol }}
</td>
{% if config.showPrecipitationAmount %} {% if config.showPrecipitationAmount %}
<td class="align-right bright precipitation-amount"> <td class="align-right bright precipitation-amount">{{ f.precipitationAmount | unit("precip", f.precipitationUnits) }}</td>
{{ f.precipitationAmount | unit("precip", f.precipitationUnits) }}
</td>
{% endif %} {% endif %}
{% if config.showPrecipitationProbability %} {% if config.showPrecipitationProbability %}
<td class="align-right bright precipitation-prob"> <td class="align-right bright precipitation-prob">{{ f.precipitationProbability | unit('precip', '%') }}</td>
{{ f.precipitationProbability | unit('precip', '%') }}
</td>
{% endif %} {% endif %}
{% if config.showUVIndex %} {% if config.showUVIndex %}
<td class="align-right dimmed uv-index"> <td class="align-right dimmed uv-index">

View File

@@ -4,15 +4,15 @@
<table class="{{ config.tableClass }}"> <table class="{{ config.tableClass }}">
{% set hours = hourly.slice(0, numSteps) %} {% set hours = hourly.slice(0, numSteps) %}
{% for hour in hours %} {% for hour in hours %}
<tr {% if config.colored %}class="colored"{% endif %} <tr
{% if config.fade %}style="opacity: {{ currentStep | opacity(numSteps) }};"{% endif %}> {% if config.colored %}class="colored"{% endif %}
{% if config.fade %}style="opacity: {{ currentStep | opacity(numSteps) }};"{% endif %}
>
<td class="day">{{ hour.date | formatTime }}</td> <td class="day">{{ hour.date | formatTime }}</td>
<td class="bright weather-icon"> <td class="bright weather-icon">
<span class="wi weathericon wi-{{ hour.weatherType }}"></span> <span class="wi weathericon wi-{{ hour.weatherType }}"></span>
</td> </td>
<td class="align-right bright"> <td class="align-right bright">{{ hour.temperature | roundValue | unit("temperature") }}</td>
{{ hour.temperature | roundValue | unit("temperature") }}
</td>
{% if config.showUVIndex %} {% if config.showUVIndex %}
<td class="align-right bright uv-index"> <td class="align-right bright uv-index">
{% if hour.uv_index!=0 %} {% if hour.uv_index!=0 %}
@@ -29,16 +29,12 @@
{% endif %} {% endif %}
{% if config.showPrecipitationAmount %} {% if config.showPrecipitationAmount %}
{% if (not config.hideZeroes or hour.precipitationAmount>0) %} {% if (not config.hideZeroes or hour.precipitationAmount>0) %}
<td class="align-right bright precipitation-amount"> <td class="align-right bright precipitation-amount">{{ hour.precipitationAmount | unit("precip", hour.precipitationUnits) }}</td>
{{ hour.precipitationAmount | unit("precip", hour.precipitationUnits) }}
</td>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if config.showPrecipitationProbability %} {% if config.showPrecipitationProbability %}
{% if (not config.hideZeroes or hour.precipitationAmount>0) %} {% if (not config.hideZeroes or hour.precipitationAmount>0) %}
<td class="align-right bright precipitation-prob"> <td class="align-right bright precipitation-prob">{{ hour.precipitationProbability | unit('precip', '%') }}</td>
{{ hour.precipitationProbability | unit('precip', '%') }}
</td>
{% endif %} {% endif %}
{% endif %} {% endif %}
</tr> </tr>

11
package-lock.json generated
View File

@@ -52,6 +52,7 @@
"markdownlint-cli2": "^0.18.1", "markdownlint-cli2": "^0.18.1",
"playwright": "^1.55.0", "playwright": "^1.55.0",
"prettier": "^3.6.2", "prettier": "^3.6.2",
"prettier-plugin-jinja-template": "^2.1.0",
"stylelint": "^16.24.0", "stylelint": "^16.24.0",
"stylelint-config-standard": "^39.0.0", "stylelint-config-standard": "^39.0.0",
"stylelint-prettier": "^5.0.3" "stylelint-prettier": "^5.0.3"
@@ -11763,6 +11764,16 @@
"node": ">=6.0.0" "node": ">=6.0.0"
} }
}, },
"node_modules/prettier-plugin-jinja-template": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/prettier-plugin-jinja-template/-/prettier-plugin-jinja-template-2.1.0.tgz",
"integrity": "sha512-mzoCp2Oy9BDSug80fw3B3J4n4KQj1hRvoQOL1akqcDKBb5nvYxrik9zUEDs4AEJ6nK7QDTGoH0y9rx7AlnQ78Q==",
"dev": true,
"license": "MIT",
"peerDependencies": {
"prettier": "^3.0.0"
}
},
"node_modules/pretty-format": { "node_modules/pretty-format": {
"version": "30.0.5", "version": "30.0.5",
"resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-30.0.5.tgz", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-30.0.5.tgz",

View File

@@ -111,6 +111,7 @@
"markdownlint-cli2": "^0.18.1", "markdownlint-cli2": "^0.18.1",
"playwright": "^1.55.0", "playwright": "^1.55.0",
"prettier": "^3.6.2", "prettier": "^3.6.2",
"prettier-plugin-jinja-template": "^2.1.0",
"stylelint": "^16.24.0", "stylelint": "^16.24.0",
"stylelint-config-standard": "^39.0.0", "stylelint-config-standard": "^39.0.0",
"stylelint-prettier": "^5.0.3" "stylelint-prettier": "^5.0.3"

View File

@@ -1,10 +1,17 @@
const config = { const config = {
plugins: ["prettier-plugin-jinja-template"],
overrides: [ overrides: [
{ {
files: "*.md", files: "*.md",
options: { options: {
parser: "markdown" parser: "markdown"
} }
},
{
files: ["*.njk"],
options: {
parser: "jinja-template"
}
} }
], ],
trailingComma: "none" trailingComma: "none"