basklee-react 0.9.18 → 0.9.20
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/package.json +1 -1
- package/templates/components/basklee/blog/BlogArticle.README.md +11 -7
- package/templates/components/basklee/blog/BlogArticle.module.css +13 -3
- package/templates/lib/basklee/blogArticleHtml.ts +48 -9
- package/templates/lib/basklee/blogMediaFallback.ts +13 -4
- package/templates/lib/basklee/productStructuredData.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basklee-react",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.20",
|
|
4
4
|
"description": "Next.js 16 storefront for your Basklee marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English, Russian and Spanish, plus an Android app build. Powered by Basklee: https://basklee.com",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,6 +63,7 @@ player from the editor (an `<iframe>` with a `youtube.com` or
|
|
|
63
63
|
`loading="lazy"` and referrer attributes and an optional start second.
|
|
64
64
|
Scripts, other frames, forms, event attributes, unsafe URLs and unsupported
|
|
65
65
|
styles are removed.
|
|
66
|
+
Empty paragraphs keep one line of height, as in the editor, so blank lines the author adds (for example to start the text below a floated picture) stay. A list the author moved right with the editor's list offset is indented by that distance, at most half the width of the text, so it never sticks out of the column.
|
|
66
67
|
A leading heading that repeats the page title is removed.
|
|
67
68
|
|
|
68
69
|
For an authenticated, accessible non-public article with a positive reading
|
|
@@ -75,9 +76,11 @@ the access-changed notice.
|
|
|
75
76
|
|
|
76
77
|
Products the author places in the text appear at those positions. The
|
|
77
78
|
marketplace blog editor writes an empty block with `data-product-id="12"` for
|
|
78
|
-
one card or `data-product-ids="12,15,9"` for a row of up to 24 cards;
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
one card or `data-product-ids="12,15,9"` for a row of up to 24 cards; a
|
|
80
|
+
single card keeps its float or centred style, and a row of cards always takes
|
|
81
|
+
the whole width of the text, also when the editor places it left or right.
|
|
82
|
+
`data-product-hidden-badges` (`new`, `popular`, `good-deal`) turns card badges
|
|
83
|
+
off. Products missing from
|
|
81
84
|
`related_products` are requested through `onLoadPlacements` with
|
|
82
85
|
`products_search` and `filters.id_in`, up to 35 IDs per request. A block whose
|
|
83
86
|
products are not found stays hidden. Article text styles do not reach the
|
|
@@ -171,7 +174,7 @@ YouTube нет настройки, отключающей предложения
|
|
|
171
174
|
раскрываемые разделы, выравнивание и поддерживаемые стили текста. Внешние
|
|
172
175
|
ссылки открываются в новой вкладке с `noopener noreferrer`, а ссылки редактора
|
|
173
176
|
на статьи ведут на `/journal/<id>`. Скрипты, фреймы, формы, обработчики
|
|
174
|
-
событий, небезопасные адреса и неподдерживаемые стили удаляются. Первый
|
|
177
|
+
событий, небезопасные адреса и неподдерживаемые стили удаляются. Пустые абзацы, как в редакторе, занимают одну строку: пустые строки автора (например, чтобы текст начался под картинкой с обтеканием) сохраняются. Список, который автор сдвинул вправо «смещением списка» редактора, получает отступ на это расстояние, но не больше половины ширины текста, и не выходит за колонку. Первый
|
|
175
178
|
заголовок, повторяющий название страницы, удаляется.
|
|
176
179
|
|
|
177
180
|
Для вошедшего покупателя чтение доступной непубличной статьи с положительным
|
|
@@ -185,9 +188,10 @@ YouTube нет настройки, отключающей предложения
|
|
|
185
188
|
Товары, которые автор разместил в тексте, показываются на своих местах.
|
|
186
189
|
Редактор блога маркетплейса пишет пустой блок с `data-product-id="12"` для
|
|
187
190
|
одной карточки или `data-product-ids="12,15,9"` для ряда до 24 карточек;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
+
одна карточка сохраняет обтекание или выравнивание по центру, а ряд карточек
|
|
192
|
+
всегда занимает всю ширину текста, даже если в редакторе он поставлен слева
|
|
193
|
+
или справа. `data-product-hidden-badges` (`new`, `popular`, `good-deal`)
|
|
194
|
+
отключает значки карточки. Товары, которых нет в `related_products`, запрашиваются через
|
|
191
195
|
`onLoadPlacements` — `products_search` с `filters.id_in`, до 35 ID за запрос.
|
|
192
196
|
Блок, товары которого не найдены, скрыт. Стили текста статьи не действуют на
|
|
193
197
|
карточки, а в узкой статье карточка с обтеканием стоит отдельно по центру.
|
|
@@ -80,6 +80,13 @@
|
|
|
80
80
|
margin: 1rem 0;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/* An empty line of the editor stays one line high, as the owner saw it there
|
|
84
|
+
(blank lines under a floated picture keep the text below it). */
|
|
85
|
+
.prose p:empty:where(:not([data-product-id] *, [data-product-ids] *)) {
|
|
86
|
+
min-height: 1lh;
|
|
87
|
+
margin: 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
83
90
|
.prose :where(h1, h2, h3, h4, h5, h6, figure, table, pre):where(:not([data-product-id] *, [data-product-ids] *)) {
|
|
84
91
|
clear: both;
|
|
85
92
|
}
|
|
@@ -201,14 +208,14 @@
|
|
|
201
208
|
.prose :where(img, figure)[data-float='left']:where(:not([data-product-id] *, [data-product-ids] *)),
|
|
202
209
|
.prose :where(img, figure)[style*='float: left']:where(:not([data-product-id] *, [data-product-ids] *)) {
|
|
203
210
|
float: left;
|
|
204
|
-
max-width:
|
|
211
|
+
max-width: 60%;
|
|
205
212
|
margin: 0.25rem 1.5rem 1rem 0;
|
|
206
213
|
}
|
|
207
214
|
|
|
208
215
|
.prose :where(img, figure)[data-float='right']:where(:not([data-product-id] *, [data-product-ids] *)),
|
|
209
216
|
.prose :where(img, figure)[style*='float: right']:where(:not([data-product-id] *, [data-product-ids] *)) {
|
|
210
217
|
float: right;
|
|
211
|
-
max-width:
|
|
218
|
+
max-width: 60%;
|
|
212
219
|
margin: 0.25rem 0 1rem 1.5rem;
|
|
213
220
|
}
|
|
214
221
|
|
|
@@ -325,9 +332,12 @@
|
|
|
325
332
|
display: none;
|
|
326
333
|
}
|
|
327
334
|
|
|
335
|
+
/* A list of cards is a row of its own. The editor's «left» or «right» is a
|
|
336
|
+
float, and a floated row has no width: its cards would not show. */
|
|
328
337
|
.prose [data-product-ids] {
|
|
338
|
+
float: none !important;
|
|
329
339
|
clear: both;
|
|
330
|
-
margin: 1.5rem 0;
|
|
340
|
+
margin: 1.5rem 0 !important;
|
|
331
341
|
}
|
|
332
342
|
|
|
333
343
|
.prose [data-product-id]:not([data-product-ids]) {
|
|
@@ -358,6 +358,38 @@ function prepareLink(link: Element) {
|
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
+
/**
|
|
362
|
+
* The editor's «list offset» draws a list N pixels to the right of its place
|
|
363
|
+
* (`position: relative; left: Npx`) and leaves its width alone, so the list
|
|
364
|
+
* sticks N pixels out of the column: on a phone the whole page scrolls
|
|
365
|
+
* sideways. Here the offset becomes an indent of at most half the column, and
|
|
366
|
+
* the list stays inside it.
|
|
367
|
+
*/
|
|
368
|
+
function indentOffsetList(list: Element) {
|
|
369
|
+
const style = list.getAttribute('style') ?? '';
|
|
370
|
+
const moved = /(?:^|;)\s*left:\s*(\d+(?:\.\d+)?)px/i.exec(style)?.[1];
|
|
371
|
+
const attribute = list.getAttribute('data-list-offset');
|
|
372
|
+
|
|
373
|
+
if (moved === undefined && attribute === null) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const offset = Number(moved ?? attribute);
|
|
378
|
+
const kept = style
|
|
379
|
+
.split(';')
|
|
380
|
+
.map((declaration) => declaration.trim())
|
|
381
|
+
.filter((declaration) => declaration && !/^(position|left|margin-left)\s*:/i.test(declaration));
|
|
382
|
+
|
|
383
|
+
if (Number.isFinite(offset) && offset > 0) {
|
|
384
|
+
kept.push(`margin-left: min(${offset}px, 50%)`);
|
|
385
|
+
}
|
|
386
|
+
if (kept.length) {
|
|
387
|
+
list.setAttribute('style', kept.join('; '));
|
|
388
|
+
} else {
|
|
389
|
+
list.removeAttribute('style');
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
361
393
|
function prepareElement(node: Element) {
|
|
362
394
|
const name = node.nodeName;
|
|
363
395
|
|
|
@@ -396,6 +428,10 @@ function prepareElement(node: Element) {
|
|
|
396
428
|
node.setAttribute('playsinline', '');
|
|
397
429
|
}
|
|
398
430
|
|
|
431
|
+
if (name === 'UL' || name === 'OL') {
|
|
432
|
+
indentOffsetList(node);
|
|
433
|
+
}
|
|
434
|
+
|
|
399
435
|
if (name === 'INPUT') {
|
|
400
436
|
if (node.getAttribute('type') !== 'checkbox') {
|
|
401
437
|
node.remove();
|
|
@@ -596,6 +632,16 @@ export function blogArticleVideos(
|
|
|
596
632
|
return found;
|
|
597
633
|
}
|
|
598
634
|
|
|
635
|
+
/** One video of an article for search engines (pageSeo IStorefrontVideo). */
|
|
636
|
+
export interface IBlogArticleVideoData {
|
|
637
|
+
name: string;
|
|
638
|
+
description?: string;
|
|
639
|
+
thumbnailUrl?: string;
|
|
640
|
+
uploadDate?: string;
|
|
641
|
+
embedUrl?: string;
|
|
642
|
+
contentUrl?: string;
|
|
643
|
+
}
|
|
644
|
+
|
|
599
645
|
/**
|
|
600
646
|
* An article's videos for search engines (pageSeo storefrontVideoObject):
|
|
601
647
|
* the YouTube players and uploaded videos of its text, then the post's own
|
|
@@ -613,14 +659,7 @@ export function blogArticleVideoData(input: {
|
|
|
613
659
|
published?: string;
|
|
614
660
|
/** Makes an address complete (storefrontAbsoluteUrl). */
|
|
615
661
|
absoluteUrl: (value: string | undefined) => string | undefined;
|
|
616
|
-
}): {
|
|
617
|
-
name: string;
|
|
618
|
-
description?: string;
|
|
619
|
-
thumbnailUrl?: string;
|
|
620
|
-
uploadDate?: string;
|
|
621
|
-
embedUrl?: string;
|
|
622
|
-
contentUrl?: string;
|
|
623
|
-
}[] {
|
|
662
|
+
}): IBlogArticleVideoData[] {
|
|
624
663
|
const seen = new Set<string>();
|
|
625
664
|
const named = (title: string) =>
|
|
626
665
|
title && !/^youtube video$/i.test(title) ? title : input.title;
|
|
@@ -631,7 +670,7 @@ export function blogArticleVideoData(input: {
|
|
|
631
670
|
...(video.poster ? { poster: video.poster } : {}),
|
|
632
671
|
}));
|
|
633
672
|
|
|
634
|
-
return [...blogArticleVideos(input.html, ''), ...own].flatMap((video) => {
|
|
673
|
+
return [...blogArticleVideos(input.html, ''), ...own].flatMap((video): IBlogArticleVideoData[] => {
|
|
635
674
|
const key = video.id ?? video.src;
|
|
636
675
|
|
|
637
676
|
if (!key || seen.has(key)) {
|
|
@@ -214,6 +214,9 @@ function imageFailed(image: HTMLImageElement) {
|
|
|
214
214
|
return Boolean(image.getAttribute('src')) && image.complete && image.naturalWidth === 0;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
// A video also reports NETWORK_NO_SOURCE from the moment it is put on the page
|
|
218
|
+
// until the browser starts loading it, so this is asked one task after that
|
|
219
|
+
// moment at the earliest (see guardBlogMedia), never in the same one.
|
|
217
220
|
function videoFailed(video: HTMLVideoElement) {
|
|
218
221
|
const NO_SOURCE = 3; // HTMLMediaElement.NETWORK_NO_SOURCE
|
|
219
222
|
return Boolean(video.error) || (Boolean(videoSource(video)) && video.networkState === NO_SOURCE);
|
|
@@ -300,11 +303,16 @@ export function guardBlogMedia(
|
|
|
300
303
|
failImage(image, labels);
|
|
301
304
|
}
|
|
302
305
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
+
// The videos are looked at in the next task: the text has often just been
|
|
307
|
+
// rendered, and a video that has not begun to load looks like one without a
|
|
308
|
+
// source. A failure in between still comes as an `error` event above.
|
|
309
|
+
const videoCheck = setTimeout(() => {
|
|
310
|
+
for (const video of root.querySelectorAll('video')) {
|
|
311
|
+
if (videoFailed(video)) {
|
|
312
|
+
failVideo(video, labels);
|
|
313
|
+
}
|
|
306
314
|
}
|
|
307
|
-
}
|
|
315
|
+
});
|
|
308
316
|
|
|
309
317
|
const players = [...root.querySelectorAll('iframe')]
|
|
310
318
|
.map((frame) => ({ frame, id: youtubeEmbed.exec(frame.getAttribute('src') ?? '')?.[1] }))
|
|
@@ -333,6 +341,7 @@ export function guardBlogMedia(
|
|
|
333
341
|
|
|
334
342
|
return () => {
|
|
335
343
|
active = false;
|
|
344
|
+
clearTimeout(videoCheck);
|
|
336
345
|
root.removeEventListener('error', onError, true);
|
|
337
346
|
stopCovers();
|
|
338
347
|
};
|
|
@@ -161,7 +161,7 @@ export function storefrontProductVideoObjects(
|
|
|
161
161
|
if (!product || !uploadDate) {
|
|
162
162
|
return [];
|
|
163
163
|
}
|
|
164
|
-
return (product.videos ?? []).flatMap((video, index, list) => {
|
|
164
|
+
return (product.videos ?? []).flatMap((video, index, list): Record<string, unknown>[] => {
|
|
165
165
|
const contentUrl = options.absoluteUrl(video.product_video ?? undefined);
|
|
166
166
|
const thumbnailUrl = options.absoluteUrl(video.preview ?? undefined) || options.fallbackImage;
|
|
167
167
|
if (!contentUrl || !thumbnailUrl) {
|