@pcdevil/eleventy-plugin-intl-utils 0.2.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eleventy.js CHANGED
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- const countryNameFactory = require('./src/country_name');
4
- const languageNameFactory = require('./src/language_name');
5
- const shortDateTimeFormatFactory = require('./src/short_datetime_format');
6
- const yearIntervalFactory = require('./src/year_interval');
3
+ const countryNameFactory = require('./src/filters/country_name');
4
+ const languageNameFactory = require('./src/filters/language_name');
5
+ const shortDateTimeFormatFactory = require('./src/filters/short_datetime_format');
6
+ const yearIntervalFactory = require('./src/shortcodes/year_interval');
7
7
 
8
8
  module.exports = (eleventyConfig, pluginConfig = {}) => {
9
9
  const { locale } = pluginConfig;
@@ -11,5 +11,6 @@ module.exports = (eleventyConfig, pluginConfig = {}) => {
11
11
  eleventyConfig.addFilter('country_name', countryNameFactory(locale));
12
12
  eleventyConfig.addFilter('language_name', languageNameFactory(locale));
13
13
  eleventyConfig.addFilter('short_datetime_format', shortDateTimeFormatFactory(locale));
14
- eleventyConfig.addFilter('year_interval', yearIntervalFactory(locale));
14
+
15
+ eleventyConfig.addShortcode('year_interval', yearIntervalFactory(locale));
15
16
  };
package/README.md CHANGED
@@ -4,7 +4,7 @@ A set of internationalization utils for [Eleventy](https://www.11ty.dev/).
4
4
  ## Motivation
5
5
  It's super fast to create a static website with **Eleventy** and with the help of [`eleventy-plugin-i18n`](https://www.npmjs.com/package/eleventy-plugin-i18n) localization can be done with ease too.
6
6
 
7
- However it only gives solution for static data and dynamic data still needs treatment during layout rendering. This plugin aims to help with a set of [filters](https://www.11ty.dev/docs/filters/).
7
+ However it only gives solution for static data and dynamic data still needs treatment during layout rendering. This plugin aims to help with a set of [filters](https://www.11ty.dev/docs/filters/) and [shortcodes](https://www.11ty.dev/docs/shortcodes/).
8
8
 
9
9
  The implementations of the filters are mostly wrappers around the [ECMAScript Internationalization API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) with a little _bit of sugar_.
10
10
 
@@ -53,9 +53,10 @@ Transforms a country code into a country name. Useful to display author's locati
53
53
  ```
54
54
  {% assign country = "FR" %}
55
55
  {{ country | country_name }}
56
- {% comment %} renders "France" when the `intlUtilConfig.locale` is `en` {% endcomment %}
57
56
  ```
58
57
 
58
+ This renders "France" when the `intlUtilConfig.locale` is `en`.
59
+
59
60
  ### `language_name`
60
61
  Transforms a language code to a renderable text. Useful for language selectors or when the current language is displayed.
61
62
 
@@ -66,9 +67,10 @@ Transforms a language code to a renderable text. Useful for language selectors o
66
67
  ```
67
68
  {% assign language = "en-GB" %}
68
69
  {{ language | language_name }}
69
- {% comment %} renders "British English" when the `intlUtilConfig.locale` is `en` {% endcomment %}
70
70
  ```
71
71
 
72
+ This renders "British English" when the `intlUtilConfig.locale` is `en`.
73
+
72
74
  ### `short_datetime_format`
73
75
  Transforms a date string to a short date time text. Useful for blog post dates.
74
76
 
@@ -79,9 +81,12 @@ Transforms a date string to a short date time text. Useful for blog post dates.
79
81
  ```
80
82
  {% assign postDate = "2021-12-12 17:36 +0100" %}
81
83
  {{ postDate | short_datetime_format }}
82
- {% comment %} renders "12/12/21, 5:36 PM" when the `intlUtilConfig.locale` is `en` {% endcomment %}
83
84
  ```
84
85
 
86
+ This renders "12/12/21, 5:36 PM" when the `intlUtilConfig.locale` is `en`.
87
+
88
+ ## Shortcodes
89
+
85
90
  ### `year_interval`
86
91
  Transforms two date strings to a year range. Useful when a larger time interval is presented.
87
92
 
@@ -92,10 +97,24 @@ The input should be an array with two date string and the first one should prece
92
97
  #### LiquidJS Example
93
98
 
94
99
  ```
95
- {% assign dates = "2011-05-16 11:00 +0200, 2020-03-01 00:00 +0100" | split: ", " %}
96
- {{ dates | year_interval }}
97
- {% comment %} renders "2011 – 2020" (with en dash in the middle) when the `intlUtilConfig.locale` is `en` {% endcomment %}
100
+ {% assign startDate = "2011-05-16 11:00 +0200" %}
101
+ {% assign endDate = "2020-03-01 00:00 +0100" %}
102
+ {% year_interval startDate, endDate %}
98
103
  ```
99
104
 
105
+ This renders "2011 – 2020" (with en dash in the middle) when the `intlUtilConfig.locale` is `en`.
106
+
107
+ #### Fallback value
108
+ The second `endDate` argument can be omitted and it has the current date as default value.
109
+
110
+ This behaviour helps when an open-ended / ongoing interval needs be displayed:
111
+
112
+ ```
113
+ {% assign startDate = "2011-05-16 11:00 +0200" %}
114
+ {% year_interval startDate %}
115
+ ```
116
+
117
+ This renders "2011 – 2021" (with en dash in the middle) when the `intlUtilConfig.locale` is `en` and the current year is 2021.
118
+
100
119
  ## License
101
120
  Available under the [MIT license](LICENSE.md).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pcdevil/eleventy-plugin-intl-utils",
3
- "version": "0.2.0",
3
+ "version": "1.0.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -21,6 +21,7 @@
21
21
  "11ty",
22
22
  "blog",
23
23
  "eleventy",
24
+ "eleventy-plugin",
24
25
  "internationalization",
25
26
  "static-site",
26
27
  "website"
File without changes
@@ -5,7 +5,7 @@ function yearIntervalFactory (locale) {
5
5
  year: 'numeric',
6
6
  });
7
7
 
8
- return ([startDate, endDate]) => dateTimeFormat.formatRange(new Date(startDate), new Date(endDate));
8
+ return (startDate, endDate = new Date()) => dateTimeFormat.formatRange(new Date(startDate), new Date(endDate));
9
9
  }
10
10
 
11
11
  module.exports = yearIntervalFactory;
package/.eslintrc.json DELETED
@@ -1,36 +0,0 @@
1
- {
2
- "extends": [
3
- "eslint:recommended",
4
- "standard"
5
- ],
6
-
7
- "ignorePatterns": [
8
- "!.eleventy.js"
9
- ],
10
-
11
- "parserOptions": {
12
- "sourceType": "script"
13
- },
14
-
15
- "root": true,
16
-
17
- "rules": {
18
- "curly": ["error", "all"],
19
- "array-element-newline": ["error", "consistent"],
20
- "arrow-parens": ["error", "always"],
21
- "comma-dangle": ["error", {
22
- "arrays": "always-multiline",
23
- "exports": "always-multiline",
24
- "functions": "never",
25
- "imports": "always-multiline",
26
- "objects": "always-multiline"
27
- }],
28
- "indent": ["error", "tab"],
29
- "no-tabs": "off",
30
- "object-property-newline": ["error", {
31
- "allowAllPropertiesOnSameLine": false
32
- }],
33
- "semi": ["error", "always"],
34
- "valid-jsdoc": "off"
35
- }
36
- }
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- v16.13.1