@tryghost/helpers 1.1.72 → 1.1.74
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/es/helpers.js +45 -51
- package/es/helpers.js.map +1 -1
- package/package.json +4 -4
- package/umd/helpers.min.js +1 -1
- package/umd/helpers.min.js.map +1 -1
package/es/helpers.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import 'core-js/modules/es6.regexp.split.js';
|
|
2
|
-
import 'core-js/modules/es6.regexp.replace.js';
|
|
3
|
-
import 'core-js/modules/es6.regexp.match.js';
|
|
4
|
-
import 'core-js/modules/es6.function.name.js';
|
|
5
|
-
import 'core-js/modules/es6.array.slice.js';
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
2
|
* The base implementation of `_.findIndex` and `_.findLastIndex` without
|
|
9
3
|
* support for iteratee shorthands.
|
|
@@ -3484,7 +3478,7 @@ function trim(string, chars, guard) {
|
|
|
3484
3478
|
* @returns {*}
|
|
3485
3479
|
*/
|
|
3486
3480
|
|
|
3487
|
-
|
|
3481
|
+
const parse = visibility => {
|
|
3488
3482
|
if (!visibility) {
|
|
3489
3483
|
return ['public'];
|
|
3490
3484
|
}
|
|
@@ -3503,22 +3497,22 @@ var parse = function parse(visibility) {
|
|
|
3503
3497
|
* @returns {Array|Object} filtered items
|
|
3504
3498
|
*/
|
|
3505
3499
|
|
|
3506
|
-
|
|
3500
|
+
const filter = (items, visibility, fn) => {
|
|
3507
3501
|
if (isFunction(visibility)) {
|
|
3508
3502
|
fn = visibility;
|
|
3509
3503
|
visibility = null;
|
|
3510
3504
|
}
|
|
3511
3505
|
|
|
3512
|
-
|
|
3513
|
-
|
|
3506
|
+
const memo = isArray$1(items) ? [] : {};
|
|
3507
|
+
const visArray = isArray$1(visibility) ? visibility : parse(visibility); // Fallback behaviour for items that don't have visibility set on them
|
|
3514
3508
|
|
|
3515
|
-
|
|
3516
|
-
|
|
3509
|
+
const defaultVisibility = 'public';
|
|
3510
|
+
const returnByDefault = includes(visArray, defaultVisibility); // We don't want to change the structure of what is returned
|
|
3517
3511
|
|
|
3518
3512
|
return reduce(items, function (accumulator, item, key) {
|
|
3519
3513
|
// If the item has visibility, check to see if it matches, else if there's no visibility check for a match with the default visibility
|
|
3520
3514
|
if (includes(visArray, 'all') || item.visibility && includes(visArray, item.visibility) || !item.visibility && returnByDefault) {
|
|
3521
|
-
|
|
3515
|
+
const newItem = fn ? fn(item) : item;
|
|
3522
3516
|
|
|
3523
3517
|
if (isArray$1(items)) {
|
|
3524
3518
|
accumulator.push(newItem);
|
|
@@ -3557,10 +3551,10 @@ function countWords(text) {
|
|
|
3557
3551
|
|
|
3558
3552
|
text = text.replace(/<(.|\n)*?>/g, ' '); // strip any HTML tags
|
|
3559
3553
|
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3554
|
+
const pattern = /[a-zA-ZÀ-ÿ0-9_\u0392-\u03c9\u0410-\u04F9]+|[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g;
|
|
3555
|
+
const RTLPattern = /([\u0600-\u06ff]+|[\u0591-\u05F4]+)/g;
|
|
3556
|
+
const match = text.match(pattern) || text.match(RTLPattern);
|
|
3557
|
+
let count = 0;
|
|
3564
3558
|
|
|
3565
3559
|
if (match === null) {
|
|
3566
3560
|
return count;
|
|
@@ -3597,17 +3591,19 @@ function countImages(html) {
|
|
|
3597
3591
|
}
|
|
3598
3592
|
|
|
3599
3593
|
function estimatedReadingTimeInMinutes(_ref) {
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3594
|
+
let {
|
|
3595
|
+
wordCount,
|
|
3596
|
+
imageCount
|
|
3597
|
+
} = _ref;
|
|
3598
|
+
const wordsPerMinute = 275;
|
|
3599
|
+
const wordsPerSecond = wordsPerMinute / 60;
|
|
3600
|
+
let readingTimeSeconds = wordCount / wordsPerSecond; // add 12 seconds for the first image, 11 for the second, etc. limiting at 3
|
|
3605
3601
|
|
|
3606
3602
|
for (var i = 12; i > 12 - imageCount; i -= 1) {
|
|
3607
3603
|
readingTimeSeconds += Math.max(i, 3);
|
|
3608
3604
|
}
|
|
3609
3605
|
|
|
3610
|
-
|
|
3606
|
+
let readingTimeMinutes = Math.round(readingTimeSeconds / 60);
|
|
3611
3607
|
return readingTimeMinutes;
|
|
3612
3608
|
}
|
|
3613
3609
|
/**
|
|
@@ -3623,16 +3619,16 @@ function readingMinutes(html, additionalImages) {
|
|
|
3623
3619
|
return '';
|
|
3624
3620
|
}
|
|
3625
3621
|
|
|
3626
|
-
|
|
3627
|
-
|
|
3622
|
+
let imageCount = countImages(html);
|
|
3623
|
+
let wordCount = countWords(html);
|
|
3628
3624
|
|
|
3629
3625
|
if (additionalImages) {
|
|
3630
3626
|
imageCount += additionalImages;
|
|
3631
3627
|
}
|
|
3632
3628
|
|
|
3633
3629
|
return estimatedReadingTimeInMinutes({
|
|
3634
|
-
wordCount
|
|
3635
|
-
imageCount
|
|
3630
|
+
wordCount,
|
|
3631
|
+
imageCount
|
|
3636
3632
|
});
|
|
3637
3633
|
}
|
|
3638
3634
|
|
|
@@ -3647,22 +3643,22 @@ function readingMinutes(html, additionalImages) {
|
|
|
3647
3643
|
*/
|
|
3648
3644
|
|
|
3649
3645
|
function readingTime (post) {
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3646
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3647
|
+
const minuteStr = typeof options.minute === 'string' ? options.minute : '1 min read';
|
|
3648
|
+
const minutesStr = typeof options.minutes === 'string' ? options.minutes : '% min read';
|
|
3653
3649
|
|
|
3654
3650
|
if (!post.html && !post.reading_time) {
|
|
3655
3651
|
return '';
|
|
3656
3652
|
}
|
|
3657
3653
|
|
|
3658
|
-
|
|
3654
|
+
let imageCount = 0;
|
|
3659
3655
|
|
|
3660
3656
|
if (post.feature_image) {
|
|
3661
3657
|
imageCount += 1;
|
|
3662
3658
|
}
|
|
3663
3659
|
|
|
3664
|
-
|
|
3665
|
-
|
|
3660
|
+
const time = post.reading_time || readingMinutes(post.html, imageCount);
|
|
3661
|
+
let readingTime = '';
|
|
3666
3662
|
|
|
3667
3663
|
if (time <= 1) {
|
|
3668
3664
|
readingTime = minuteStr;
|
|
@@ -4353,19 +4349,17 @@ var zip$1 = zip;
|
|
|
4353
4349
|
*/
|
|
4354
4350
|
|
|
4355
4351
|
function tags (data) {
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
return tag.name;
|
|
4368
|
-
};
|
|
4352
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4353
|
+
let output = '';
|
|
4354
|
+
let separator = options.separator ? options.separator : '';
|
|
4355
|
+
let prefix = options.prefix ? options.prefix : '';
|
|
4356
|
+
let suffix = options.suffix ? options.suffix : '';
|
|
4357
|
+
let limit = options.limit ? parseInt(options.limit, 10) : undefined;
|
|
4358
|
+
let from = options.from ? parseInt(options.from, 10) : 1;
|
|
4359
|
+
let to = options.to ? parseInt(options.to, 10) : undefined;
|
|
4360
|
+
let visibilityArr = parse(options.visibility);
|
|
4361
|
+
let fallback = options.fallback ? isArray$1(options.fallback) ? options.fallback : [options.fallback] : undefined;
|
|
4362
|
+
let displayFn = options.fn ? options.fn : tag => tag.name;
|
|
4369
4363
|
|
|
4370
4364
|
if (data.tags && data.tags.length) {
|
|
4371
4365
|
output = filter(data.tags, visibilityArr, displayFn);
|
|
@@ -4406,11 +4400,11 @@ function tags (data) {
|
|
|
4406
4400
|
return output;
|
|
4407
4401
|
}
|
|
4408
4402
|
|
|
4409
|
-
|
|
4410
|
-
countImages
|
|
4411
|
-
countWords
|
|
4412
|
-
visibility
|
|
4413
|
-
readingMinutes
|
|
4403
|
+
const utils = {
|
|
4404
|
+
countImages,
|
|
4405
|
+
countWords,
|
|
4406
|
+
visibility,
|
|
4407
|
+
readingMinutes
|
|
4414
4408
|
};
|
|
4415
4409
|
|
|
4416
4410
|
export { readingTime, tags, utils };
|