From 641eb25047977d2e08e878951ef8fb027aa1c628 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 09:09:28 -0800 Subject: [PATCH 1/3] Chore(deps): Bump actions/cache from 3 to 4 (#2662) Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/docs-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs-publish.yml b/.github/workflows/docs-publish.yml index 92900e25..d3aea8e6 100644 --- a/.github/workflows/docs-publish.yml +++ b/.github/workflows/docs-publish.yml @@ -46,7 +46,7 @@ jobs: with: python-version: 3.x - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: key: mkdocs-material-${{ env.cache_id }} path: .cache @@ -71,7 +71,7 @@ jobs: with: python-version: 3.x - run: echo "cache_id=${{github.sha}}" >> $GITHUB_ENV - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: key: mkdocs-material-${{ env.cache_id }} path: .cache From 7837864841dde44da603d1293156ac9949816b9d Mon Sep 17 00:00:00 2001 From: 0phoff <0phoff@users.noreply.github.com> Date: Wed, 17 Jan 2024 18:23:11 +0100 Subject: [PATCH 2/3] Enhancement: locale option for date & relativeDate format (#2658) --- docs/widgets/services/customapi.md | 11 ++++++++++- next-i18next.config.js | 14 ++++++++++++++ public/locales/en/common.json | 1 + src/widgets/customapi/component.jsx | 15 ++++++++++++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/widgets/services/customapi.md b/docs/widgets/services/customapi.md index f39d8d5e..d392f0a9 100644 --- a/docs/widgets/services/customapi.md +++ b/docs/widgets/services/customapi.md @@ -34,11 +34,20 @@ widget: - field: key # needs to be YAML string or object label: Field 4 format: date # optional - defaults to text + locale: nl # optional dateStyle: long # optional - defaults to "long". Allowed values: `["full", "long", "medium", "short"]`. timeStyle: medium # optional - Allowed values: `["full", "long", "medium", "short"]`. + - field: key # needs to be YAML string or object + label: Field 5 + format: relativeDate # optional - defaults to text + locale: nl # optional + style: short # optional - defaults to "long". Allowed values: `["long", "short", "narrow"]`. + numeric: auto # optional - defaults to "always". Allowed values `["always", "auto"]`. ``` -Supported formats for the values are `text`, `number`, `float`, `percent`, `bytes`, `bitrate` and `date`. +Supported formats for the values are `text`, `number`, `float`, `percent`, `bytes`, `bitrate`, `date` and `relativeDate`. + +The `dateStyle` and `timeStyle` options of the `date` format are passed directly to [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat) and the `style` and `numeric` options of `relativeDate` are passed to [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat). ## Example diff --git a/next-i18next.config.js b/next-i18next.config.js index 6790e14d..96483cc3 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -100,6 +100,17 @@ function uptime(uptimeInSeconds, i18next) { return (moDisplay + dDisplay + hDisplay + mDisplay + sDisplay).replace(/,\s*$/, ""); } +function relativeDate(date, formatter) { + const cutoffs = [60, 3600, 86400, 86400 * 7, 86400 * 30, 86400 * 365, Infinity]; + const units = ["second", "minute", "hour", "day", "week", "month", "year"]; + + const delta = Math.round((date.getTime() - Date.now()) / 1000); + const unitIndex = cutoffs.findIndex((cutoff) => cutoff > Math.abs(delta)); + const divisor = unitIndex ? cutoffs[unitIndex - 1] : 1; + + return formatter.format(Math.floor(delta / divisor), units[unitIndex]); +} + module.exports = { i18n: { defaultLocale: "en", @@ -142,6 +153,9 @@ module.exports = { i18next.services.formatter.add("date", (value, lng, options) => new Intl.DateTimeFormat(lng, { ...options }).format(new Date(value)), ); + i18next.services.formatter.add("relativeDate", (value, lng, options) => + relativeDate(new Date(value), new Intl.RelativeTimeFormat(lng, { ...options })), + ); i18next.services.formatter.add("uptime", (value, lng) => uptime(value, i18next)); }, type: "3rdParty", diff --git a/public/locales/en/common.json b/public/locales/en/common.json index bf39f1d9..1c43e506 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -12,6 +12,7 @@ "number": "{{value, number}}", "ms": "{{value, number}}", "date": "{{value, date}}", + "relativeDate": "{{value, relativeDate}}", "uptime": "{{value, uptime}}", "months": "mo", "days": "d", diff --git a/src/widgets/customapi/component.jsx b/src/widgets/customapi/component.jsx index fcf6e82f..7e6ad4d7 100644 --- a/src/widgets/customapi/component.jsx +++ b/src/widgets/customapi/component.jsx @@ -70,7 +70,20 @@ function formatValue(t, mapping, rawValue) { value = t("common.bitrate", { value }); break; case "date": - value = t("common.date", { value, dateStyle: mapping?.dateStyle ?? "long", timeStyle: mapping?.timeStyle }); + value = t("common.date", { + value, + lng: mapping?.locale, + dateStyle: mapping?.dateStyle ?? "long", + timeStyle: mapping?.timeStyle, + }); + break; + case "relativeDate": + value = t("common.relativeDate", { + value, + lng: mapping?.locale, + style: mapping?.style, + numeric: mapping?.numeric, + }); break; case "text": default: From 93dc6db4efa50b23e2042425e16a91ddea6ef062 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 17 Jan 2024 09:35:05 -0800 Subject: [PATCH 3/3] Remove mkdocs-material insiders --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index b55fe427..e0365917 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,8 +10,8 @@ Markdown==3.4.4 MarkupSafe==2.1.3 mergedeep==1.3.4 mkdocs==1.5.3 -mkdocs-material @ git+https://github.com/benphelps/mkdocs-material-insiders.git@bcad61c278491d58e74c39e164b821cec795c161 -mkdocs-material-extensions==1.2 +mkdocs-material==9.5.2 +mkdocs-material-extensions==1.3 packaging==23.1 paginate==0.5.6 pathspec==0.11.2