@taprootio/site-authoring 0.40.0 → 0.41.0
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/README.md +30 -3
- package/package.json +1 -1
- package/src/changelog.json +15 -0
- package/src/content/components.js +36 -2
- package/src/content/testimonial-google-reviews.js +140 -10
- package/src/reference-help.js +1 -1
package/README.md
CHANGED
|
@@ -1315,7 +1315,7 @@ tracked-Markdown conflict, and a stale push is refused. There is no reverse
|
|
|
1315
1315
|
Markdown exporter. See `taproot-site help page free-form` for the closed attrs
|
|
1316
1316
|
reference and examples.
|
|
1317
1317
|
|
|
1318
|
-
### Testimonial Google reviews in 0.38.0
|
|
1318
|
+
### Testimonial Google reviews in 0.38.0 and 0.41.0
|
|
1319
1319
|
|
|
1320
1320
|
A Testimonial block can show the site's selected Google reviews instead of
|
|
1321
1321
|
hand-written quotes. In its component data set `"source": "google-reviews"` and
|
|
@@ -1327,12 +1327,39 @@ hand-written `items`. The `items` are kept in the data whichever source is set.
|
|
|
1327
1327
|
`source` and `maxItems` are refused at their field path when the value is
|
|
1328
1328
|
unknown or out of range.
|
|
1329
1329
|
|
|
1330
|
+
From 0.41.0 a block can show particular reviews: set `"reviewSelection":
|
|
1331
|
+
"chosen"` and list the reviews in `"reviewIds"`, at most 12 review ids. They are
|
|
1332
|
+
shown in the listed order and `maxItems` is ignored. A chosen review keeps showing
|
|
1333
|
+
after it passes the newest 200 (a site keeps up to 200 such older reviews across
|
|
1334
|
+
all its pages, and the oldest of them stop showing if pages chose more), and is
|
|
1335
|
+
left out of the page when it is hidden, below the minimum rating, without text or
|
|
1336
|
+
deleted at Google. Omit
|
|
1337
|
+
`reviewSelection`, or use `"newest"`, for the newest reviews; the ids are kept in
|
|
1338
|
+
the data and not used. No command lists reviews, so an id comes from a page that
|
|
1339
|
+
was pulled after someone chose reviews in the app: copy it exactly as pulled. An
|
|
1340
|
+
unknown `reviewSelection`, more than 12 ids and an id that is not 1 to 256 letters,
|
|
1341
|
+
digits, underscores or hyphens are refused at their field path.
|
|
1342
|
+
|
|
1343
|
+
Also from 0.41.0 two switches, both `true` or `false` (anything else is refused at
|
|
1344
|
+
its field path, and omitted is `false`). `"showAll": true` lists every review that
|
|
1345
|
+
can be shown, up to the newest 200, in a grid on a page of its own, such as one
|
|
1346
|
+
titled Reviews, each with its star rating written out and the owner's reply; it
|
|
1347
|
+
ignores `maxItems` and `carousel` (the carousel setting is kept in the data and not
|
|
1348
|
+
used) and does nothing beside chosen reviews. `"showProfileSummary": true` shows
|
|
1349
|
+
Google's average rating and total number of reviews above the reviews, with a link
|
|
1350
|
+
to read all reviews on Google and, when Google provides one, a link to write a
|
|
1351
|
+
review, and works with either selection. Reviews hidden in Marketing, reviews
|
|
1352
|
+
without text and reviews below the minimum rating stay off the list. The figures
|
|
1353
|
+
are as of the last time Taproot checked Google, once a day, and a page that shows
|
|
1354
|
+
them is published again when Google's average rating or total number of reviews changes.
|
|
1355
|
+
|
|
1330
1356
|
Which reviews are selected, and the minimum star rating, are set by someone who
|
|
1331
1357
|
can manage the site's settings in the app under **Marketing → Google reviews**;
|
|
1332
1358
|
they are not in the pulled workspace. The site needs a connected Google profile.
|
|
1333
1359
|
Until it has reviews to show, a Google Testimonial publishes as empty. A release
|
|
1334
|
-
takes the reviews as they are when it is published.
|
|
1335
|
-
|
|
1360
|
+
takes the reviews as they are when it is published. A quotation's own line breaks
|
|
1361
|
+
are kept as line breaks on the published page. Help reference version 62 covers
|
|
1362
|
+
the fields in `taproot-site help component testimonial`.
|
|
1336
1363
|
|
|
1337
1364
|
### What changed between releases
|
|
1338
1365
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taprootio/site-authoring",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "Taproot site authoring CLI: sign in once in the browser, then pull, validate, push, preview, approve, and deploy a site from the terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "ISC",
|
package/src/changelog.json
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"entries": [
|
|
3
|
+
{
|
|
4
|
+
"version": "0.41.0",
|
|
5
|
+
"note": "A Google Testimonial can show particular reviews (reviewSelection and reviewIds), list every review with showAll, and show Google's rating and links with showProfileSummary. A quotation's own line breaks are kept on the published page.",
|
|
6
|
+
"behavior": [
|
|
7
|
+
"Testimonial component data accepts reviewSelection (newest or chosen) and reviewIds (at most 12 review ids, each 1 to 256 letters, digits, underscores or hyphens). Omitted reviewSelection is newest, so every existing page is unchanged. Other values, more than 12 ids and a malformed id are refused at the field path before saving.",
|
|
8
|
+
"With reviewSelection chosen and source google-reviews the published page shows the listed reviews in the listed order, ignoring maxItems, and leaves out one that is hidden, below the minimum rating, without text or deleted at Google. A chosen review keeps showing after it passes the newest 200, up to 200 such older reviews across all the pages of a site: if pages chose more, the oldest of them stop showing. The ids stay in the data while reviewSelection is newest.",
|
|
9
|
+
"No command lists reviews: an id comes from a page that was pulled after someone chose reviews in the app. Copy it exactly as pulled.",
|
|
10
|
+
"Testimonial component data accepts showAll and showProfileSummary, each true or false (anything else is refused at the field path before saving, and omitted is false). With source google-reviews and the newest selection, showAll true lists every review that can be shown, up to the newest 200, in a grid with each star rating written out and the owner's reply, ignoring maxItems and carousel; beside chosen reviews it does nothing. showProfileSummary true shows Google's average rating and total above the reviews with links to read and to write reviews, with either selection. The published page follows both by itself, and is published again when Google's average rating or total number of reviews changes.",
|
|
11
|
+
"A quotation's own line breaks, and a Google review's, are kept as line breaks on the published page after its next publish.",
|
|
12
|
+
"The help reference version is 62."
|
|
13
|
+
],
|
|
14
|
+
"help": [
|
|
15
|
+
"component"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
3
18
|
{
|
|
4
19
|
"version": "0.40.0",
|
|
5
20
|
"note": "Choose a theme context and logo artwork independently for the header and footer, with an offline warning when the selected artwork may be hard to see.",
|
|
@@ -22,7 +22,13 @@ import {
|
|
|
22
22
|
} from "./vocabulary.js";
|
|
23
23
|
import { normalizeCssLengthOverride } from "./media-presentation.js";
|
|
24
24
|
import { isVideoEmbedId, parseVideoEmbedUrl, VIDEO_EMBED_REFUSAL } from "./video-embed-url.js";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
REVIEW_ID_PATTERN,
|
|
27
|
+
TESTIMONIAL_MAX_CHOSEN_REVIEWS,
|
|
28
|
+
TESTIMONIAL_MAX_ITEMS,
|
|
29
|
+
TESTIMONIAL_REVIEW_SELECTIONS,
|
|
30
|
+
TESTIMONIAL_SOURCES,
|
|
31
|
+
} from "./testimonial-google-reviews.js";
|
|
26
32
|
|
|
27
33
|
/**
|
|
28
34
|
* The eight canonical `componentBlock` data shapes. Seven remain mirrored
|
|
@@ -216,8 +222,29 @@ const TESTIMONIAL = Object.freeze({
|
|
|
216
222
|
integer: true,
|
|
217
223
|
minimum: TESTIMONIAL_MAX_ITEMS.minimum,
|
|
218
224
|
maximum: TESTIMONIAL_MAX_ITEMS.maximum,
|
|
219
|
-
description:
|
|
225
|
+
description:
|
|
226
|
+
"How many Google reviews to show, newest first. Used only when source is google-reviews, reviewSelection is newest and showAll is not true.",
|
|
220
227
|
}),
|
|
228
|
+
reviewSelection: described(
|
|
229
|
+
enumOf(...TESTIMONIAL_REVIEW_SELECTIONS),
|
|
230
|
+
"newest shows the newest selected reviews, as many as maxItems says (up to the newest 200 reviews that can be shown when showAll is true). chosen shows the reviews listed in reviewIds, in that order, and ignores maxItems. Used only when source is google-reviews. Omitted is newest.",
|
|
231
|
+
),
|
|
232
|
+
reviewIds: described(
|
|
233
|
+
list(boundedStr(256, {
|
|
234
|
+
pattern: REVIEW_ID_PATTERN,
|
|
235
|
+
patternSource: REVIEW_ID_PATTERN.source,
|
|
236
|
+
patternDescription: "1 to 256 letters, digits, underscores or hyphens",
|
|
237
|
+
}), { maxItems: TESTIMONIAL_MAX_CHOSEN_REVIEWS }),
|
|
238
|
+
"The Google reviews a chosen component shows, by review id, at most 12. No command lists reviews: an id comes from a page that was pulled after someone chose reviews in the app, so copy it as it is. A chosen review that is hidden, below the minimum rating, without text or deleted at Google is left out of the page. Kept, and not used, while reviewSelection is newest.",
|
|
239
|
+
),
|
|
240
|
+
showAll: described(
|
|
241
|
+
bool(),
|
|
242
|
+
"true lists every review that can be shown, up to the newest 200, in a grid, each with its star rating written out and the owner's reply, and ignores maxItems and carousel (a carousel setting is kept in the data and not used). Used only when source is google-reviews and reviewSelection is newest; beside chosen reviews it does nothing. Omitted is false.",
|
|
243
|
+
),
|
|
244
|
+
showProfileSummary: described(
|
|
245
|
+
bool(),
|
|
246
|
+
"true shows Google's average rating and total number of reviews above the reviews, with a link to read all reviews on Google and, when Google provides one, a link to write a review. Used only when source is google-reviews, with either selection. Omitted is false.",
|
|
247
|
+
),
|
|
221
248
|
items: withOmission(
|
|
222
249
|
list(shape({
|
|
223
250
|
quote: str(),
|
|
@@ -666,6 +693,10 @@ const COMPONENT_DEFINITIONS = Object.freeze({
|
|
|
666
693
|
{
|
|
667
694
|
source: "manual",
|
|
668
695
|
maxItems: TESTIMONIAL_MAX_ITEMS.default,
|
|
696
|
+
reviewSelection: "newest",
|
|
697
|
+
reviewIds: [],
|
|
698
|
+
showAll: false,
|
|
699
|
+
showProfileSummary: false,
|
|
669
700
|
items: [{ quote: "", authorName: "", authorTitle: "", authorImage: null }],
|
|
670
701
|
columns: 1,
|
|
671
702
|
carousel: false,
|
|
@@ -679,6 +710,9 @@ const COMPONENT_DEFINITIONS = Object.freeze({
|
|
|
679
710
|
"Set carousel:true for directional previous/next arrows, dot navigation and a play/pause control. Navigation or keyboard focus pauses rotation; reduced-motion users get manual navigation without sliding or automatic rotation.",
|
|
680
711
|
"Use real attributed reviews, or clearly label fictional demo reviews. Never imply invented testimonials are genuine customer endorsements.",
|
|
681
712
|
"Set source:\"google-reviews\" only for a site with a connected Google profile; the published page shows the selected reviews with their reviewer names and a link to read all reviews on Google, and shows nothing until the profile has reviews it can show.",
|
|
713
|
+
"A Google Testimonial shows the newest reviews unless reviewSelection is \"chosen\". Choose reviews in the app: it writes their ids into reviewIds, and a pulled page carries them. Keep an id exactly as pulled, because no command lists reviews and a made-up id shows nothing.",
|
|
714
|
+
"A quotation's own line breaks are kept on the published page.",
|
|
715
|
+
"Set showAll:true on a Google Testimonial with the newest selection to list up to the newest 200 reviews that can be shown on a page of its own, such as one titled Reviews; reviews hidden in Marketing, without text or below the minimum rating stay off it. Set showProfileSummary:true to show Google's average rating and total number of reviews above the reviews, with links to read and to write reviews.",
|
|
682
716
|
],
|
|
683
717
|
{
|
|
684
718
|
items: [{
|
|
@@ -19,10 +19,25 @@ export const MANUAL_SOURCE = "manual";
|
|
|
19
19
|
export const GOOGLE_REVIEWS_SOURCE = "google-reviews";
|
|
20
20
|
/** How many reviews a Google-source component shows, as stored: a whole number from 1 to 12. */
|
|
21
21
|
export const TESTIMONIAL_MAX_ITEMS = Object.freeze({ minimum: 1, maximum: 12, default: 6 });
|
|
22
|
+
/**
|
|
23
|
+
* Which Google reviews a component shows (TR01341): the `newest` ones, as many as `maxItems` says, or the ones the
|
|
24
|
+
* author picked by id, in the order picked. Stored `reviewIds` stay when the selection is `newest`, so switching back
|
|
25
|
+
* loses nothing.
|
|
26
|
+
*/
|
|
27
|
+
export const TESTIMONIAL_REVIEW_SELECTIONS = ["newest", "chosen"];
|
|
28
|
+
export const NEWEST_SELECTION = "newest";
|
|
29
|
+
export const CHOSEN_SELECTION = "chosen";
|
|
30
|
+
/** The most reviews one component can choose; the C# `BusinessProfilePolicy.MaxChosenReviewsPerComponent` is the same number. */
|
|
31
|
+
export const TESTIMONIAL_MAX_CHOSEN_REVIEWS = 12;
|
|
32
|
+
/** A review id Taproot keeps: 1 to 256 letters, digits, `_` or `-`, as `BusinessProfilePolicy.IsValidReviewId` says. */
|
|
33
|
+
export const REVIEW_ID_PATTERN = /^[A-Za-z0-9_-]{1,256}$/u;
|
|
22
34
|
/** What a creator reads on a published page. Each is one sentence, so a change is made here only. */
|
|
23
35
|
export const GOOGLE_REVIEWS_ATTRIBUTION = "Selected reviews from Google";
|
|
24
36
|
export const GOOGLE_REVIEWS_LINK_TEXT = "Read all reviews on Google";
|
|
25
37
|
export const GOOGLE_REVIEW_LABEL = "Google review";
|
|
38
|
+
/** The label above the owner's reply on a listed review, and the link to write a review (TR01342). */
|
|
39
|
+
export const GOOGLE_REVIEWS_REPLY_LABEL = "Reply from the owner";
|
|
40
|
+
export const GOOGLE_REVIEWS_WRITE_LINK_TEXT = "Write a review";
|
|
26
41
|
/** The reviewer shown when Google sent no name (the freeze stores an empty name, never these words). */
|
|
27
42
|
export const GOOGLE_USER_NAME = "Google user";
|
|
28
43
|
/** An unknown or mistyped source is the hand-written one, so older and foreign data renders as it always did. */
|
|
@@ -35,7 +50,22 @@ export function normalizeTestimonialMaxItems(value) {
|
|
|
35
50
|
return TESTIMONIAL_MAX_ITEMS.default;
|
|
36
51
|
return Math.min(TESTIMONIAL_MAX_ITEMS.maximum, Math.max(TESTIMONIAL_MAX_ITEMS.minimum, Math.trunc(value)));
|
|
37
52
|
}
|
|
38
|
-
/**
|
|
53
|
+
/** Anything but the exact word `chosen` is the newest reviews, so older and foreign data renders as it always did. */
|
|
54
|
+
export function normalizeReviewSelection(value) {
|
|
55
|
+
return value === CHOSEN_SELECTION ? CHOSEN_SELECTION : NEWEST_SELECTION;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The review ids a component stored: the strings that are valid review ids, later duplicates dropped, then the first
|
|
59
|
+
* twelve. Anything that is not a list is none. The C# page extractor applies the same rule, and the corpus holds them
|
|
60
|
+
* to the same answers.
|
|
61
|
+
*/
|
|
62
|
+
export function normalizeReviewIds(value) {
|
|
63
|
+
if (!Array.isArray(value))
|
|
64
|
+
return [];
|
|
65
|
+
const valid = value.filter((id) => typeof id === "string" && REVIEW_ID_PATTERN.test(id));
|
|
66
|
+
return [...new Set(valid)].slice(0, TESTIMONIAL_MAX_CHOSEN_REVIEWS);
|
|
67
|
+
}
|
|
68
|
+
/** The fields of component data that is not an object (or has none of them) are the defaults. */
|
|
39
69
|
export function normalizeTestimonialGoogleFields(data) {
|
|
40
70
|
const record = data !== null && typeof data === "object" && !Array.isArray(data)
|
|
41
71
|
? data
|
|
@@ -43,8 +73,61 @@ export function normalizeTestimonialGoogleFields(data) {
|
|
|
43
73
|
return {
|
|
44
74
|
source: normalizeTestimonialSource(record.source),
|
|
45
75
|
maxItems: normalizeTestimonialMaxItems(record.maxItems),
|
|
76
|
+
reviewSelection: normalizeReviewSelection(record.reviewSelection),
|
|
77
|
+
reviewIds: normalizeReviewIds(record.reviewIds),
|
|
78
|
+
// Only the boolean `true` turns a switch on, so a string or a number in older or foreign data is off.
|
|
79
|
+
showAll: record.showAll === true,
|
|
80
|
+
showProfileSummary: record.showProfileSummary === true,
|
|
46
81
|
};
|
|
47
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* The one answer to what a Testimonial shows (TR01342), computed once from the stored fields. The renderer, the editor
|
|
85
|
+
* preview, the editor and the page preview's reference walk all call it, and the C# page extractor's answers are held to
|
|
86
|
+
* it by the corpus. The editor passes its draft fields in the stored shape.
|
|
87
|
+
*/
|
|
88
|
+
export function googleReviewsDisplay(data) {
|
|
89
|
+
const fields = normalizeTestimonialGoogleFields(data);
|
|
90
|
+
const record = data !== null && typeof data === "object" && !Array.isArray(data)
|
|
91
|
+
? data
|
|
92
|
+
: {};
|
|
93
|
+
const google = fields.source === GOOGLE_REVIEWS_SOURCE;
|
|
94
|
+
const listAll = google && fields.reviewSelection === NEWEST_SELECTION && fields.showAll;
|
|
95
|
+
return { listAll, summary: google && fields.showProfileSummary, carousel: Boolean(record.carousel) && !listAll };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The review ids a component chooses: its stored ids when the source is Google and the selection is `chosen`, and none
|
|
99
|
+
* otherwise (a `newest` component ignores ids it still holds). The page preview, the editor, the chooser below and the
|
|
100
|
+
* C# extractor all mean this.
|
|
101
|
+
*/
|
|
102
|
+
export function chosenGoogleReviewIds(data) {
|
|
103
|
+
const fields = normalizeTestimonialGoogleFields(data);
|
|
104
|
+
return fields.source === GOOGLE_REVIEWS_SOURCE && fields.reviewSelection === CHOSEN_SELECTION ? fields.reviewIds : [];
|
|
105
|
+
}
|
|
106
|
+
/** The one test of an address a page may link to: https, as the profile's Maps address and the address to write a review at both need (TR01342). */
|
|
107
|
+
function isHttpsAddress(value) {
|
|
108
|
+
return /^https:\/\//iu.test(value);
|
|
109
|
+
}
|
|
110
|
+
/** "1 star", "5 stars": the one place the rating is worded, for the published page, the editor and the review cards. */
|
|
111
|
+
export function googleRatingWords(stars) {
|
|
112
|
+
return stars === 1 ? "1 star" : `${stars} stars`;
|
|
113
|
+
}
|
|
114
|
+
const COUNT_FORMAT = new Intl.NumberFormat("en-US");
|
|
115
|
+
const AVERAGE_FORMAT = new Intl.NumberFormat("en-US", { minimumFractionDigits: 1, maximumFractionDigits: 1 });
|
|
116
|
+
/**
|
|
117
|
+
* The sentence above a listing (TR01342): "4.8 average from 212 reviews on Google", "1 review" for one, the count with a US
|
|
118
|
+
* thousands separator and the average to one decimal place. An average that is not a rating from 1 to 5 (Google's reader stores an
|
|
119
|
+
* absent one as 0) leaves the count alone ("212 reviews on Google"), and a total of zero or less, which Google reports for a
|
|
120
|
+
* profile it counts no reviews for, has no figures at all, so the sentence is null.
|
|
121
|
+
*/
|
|
122
|
+
export function googleSummarySentence(averageRating, totalReviewCount) {
|
|
123
|
+
if (!Number.isFinite(totalReviewCount) || totalReviewCount < 1)
|
|
124
|
+
return null;
|
|
125
|
+
const total = Math.trunc(totalReviewCount);
|
|
126
|
+
const count = `${COUNT_FORMAT.format(total)} ${total === 1 ? "review" : "reviews"} on Google`;
|
|
127
|
+
return Number.isFinite(averageRating) && averageRating >= 1 && averageRating <= 5
|
|
128
|
+
? `${AVERAGE_FORMAT.format(averageRating)} average from ${count}`
|
|
129
|
+
: count;
|
|
130
|
+
}
|
|
48
131
|
/**
|
|
49
132
|
* The month and year of a review in US English, in the given IANA time zone and in UTC when none is given or
|
|
50
133
|
* the zone is not one the runtime knows. Empty when the date is not a date.
|
|
@@ -62,26 +145,73 @@ export function formatReviewMonthYear(value, timeZone) {
|
|
|
62
145
|
}
|
|
63
146
|
}
|
|
64
147
|
/**
|
|
65
|
-
* Which reviews a Testimonial component shows. With the Google source
|
|
66
|
-
* in the order given (a release freezes them newest first),
|
|
67
|
-
*
|
|
68
|
-
*
|
|
148
|
+
* Which reviews a Testimonial component shows, and every word around them. With the Google source and the `newest`
|
|
149
|
+
* selection it is the first `maxItems` of the showable reviews in the order given (a release freezes them newest first),
|
|
150
|
+
* or every one of them, never an older chosen one, while `googleReviewsDisplay(data).listAll` holds (TR01342); with `chosen`
|
|
151
|
+
* it is the reviews the component lists, in the listed order, each taken from the showable reviews or from the older chosen
|
|
152
|
+
* ones, and a listed review that is in neither is skipped (TR01341). Each item has its reviewer and its second line (with the
|
|
153
|
+
* rating written out when the list is in effect) and, for the list, the owner's reply. `summary` holds the words and links of
|
|
154
|
+
* Google's rating when the component shows it and the release froze the figures, and `attribution` the line after the
|
|
155
|
+
* reviews, which keeps its link to read all reviews unless the summary is returned and carries it. With the manual source,
|
|
156
|
+
* with nothing to show, or without an https profile address it is null, and the component renders as an empty or
|
|
157
|
+
* hand-written one does. The renderer and the editor preview both call this and only lay the result out.
|
|
69
158
|
*/
|
|
70
159
|
export function chooseGoogleReviews(data, input, timeZone) {
|
|
71
160
|
const fields = normalizeTestimonialGoogleFields(data);
|
|
72
|
-
if (fields.source !== GOOGLE_REVIEWS_SOURCE || !input
|
|
161
|
+
if (fields.source !== GOOGLE_REVIEWS_SOURCE || !input)
|
|
73
162
|
return null;
|
|
74
163
|
// The profile link is the attribution every review needs, so an address that cannot be one shows no review.
|
|
75
|
-
if (
|
|
164
|
+
if (!isHttpsAddress(input.mapsUri))
|
|
76
165
|
return null;
|
|
77
|
-
const
|
|
166
|
+
const display = googleReviewsDisplay(data);
|
|
167
|
+
// A list shows every showable review whatever maxItems holds, and never the older ones another page chose (TR01342).
|
|
168
|
+
const selected = fields.reviewSelection === CHOSEN_SELECTION
|
|
169
|
+
? listedReviews(chosenGoogleReviewIds(data), input)
|
|
170
|
+
: display.listAll
|
|
171
|
+
? [...input.reviews]
|
|
172
|
+
: input.reviews.slice(0, fields.maxItems);
|
|
173
|
+
if (selected.length === 0)
|
|
174
|
+
return null;
|
|
175
|
+
const items = selected.map((review) => {
|
|
78
176
|
const month = formatReviewMonthYear(review.createTime, timeZone);
|
|
177
|
+
const parts = [GOOGLE_REVIEW_LABEL, month, ...(display.listAll ? [googleRatingWords(review.starRating)] : [])];
|
|
79
178
|
return {
|
|
80
179
|
reviewId: review.reviewId,
|
|
81
180
|
text: review.text,
|
|
82
181
|
name: review.reviewerName.trim() === "" ? GOOGLE_USER_NAME : review.reviewerName,
|
|
83
|
-
byline:
|
|
182
|
+
byline: parts.filter((part) => part !== "").join(", "),
|
|
183
|
+
reply: display.listAll && typeof review.replyText === "string" && review.replyText.trim() !== ""
|
|
184
|
+
? review.replyText
|
|
185
|
+
: null,
|
|
84
186
|
};
|
|
85
187
|
});
|
|
86
|
-
|
|
188
|
+
const summary = display.summary && input.summary ? summaryWords(input.summary, input.mapsUri) : null;
|
|
189
|
+
return {
|
|
190
|
+
items,
|
|
191
|
+
summary,
|
|
192
|
+
// The summary carries the link to read all reviews, so the page keeps one link of each kind.
|
|
193
|
+
attribution: {
|
|
194
|
+
text: `${GOOGLE_REVIEWS_ATTRIBUTION}.`,
|
|
195
|
+
link: summary ? null : { label: GOOGLE_REVIEWS_LINK_TEXT, href: input.mapsUri },
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** The summary's words and links. The write link needs an https address, as the profile's own link does. */
|
|
200
|
+
function summaryWords(summary, mapsUri) {
|
|
201
|
+
return {
|
|
202
|
+
sentence: googleSummarySentence(summary.averageRating, summary.totalReviewCount),
|
|
203
|
+
readAll: { label: GOOGLE_REVIEWS_LINK_TEXT, href: mapsUri },
|
|
204
|
+
write: isHttpsAddress(summary.newReviewUri)
|
|
205
|
+
? { label: GOOGLE_REVIEWS_WRITE_LINK_TEXT, href: summary.newReviewUri }
|
|
206
|
+
: null,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** The listed reviews in the listed order; a showable review wins over an older copy of the same id. */
|
|
210
|
+
function listedReviews(ids, input) {
|
|
211
|
+
const known = new Map();
|
|
212
|
+
for (const review of input.olderChosenReviews ?? [])
|
|
213
|
+
known.set(review.reviewId, review);
|
|
214
|
+
for (const review of input.reviews)
|
|
215
|
+
known.set(review.reviewId, review);
|
|
216
|
+
return ids.flatMap((id) => known.get(id) ?? []);
|
|
87
217
|
}
|
package/src/reference-help.js
CHANGED
|
@@ -95,7 +95,7 @@ import {
|
|
|
95
95
|
|
|
96
96
|
export { getAppearanceReference, getFooterReference, getSettingsReference, getThemeReference };
|
|
97
97
|
|
|
98
|
-
export const REFERENCE_VERSION =
|
|
98
|
+
export const REFERENCE_VERSION = 62;
|
|
99
99
|
|
|
100
100
|
// The date-limit examples `help forms` prints; tests run them through the form validator.
|
|
101
101
|
export const FORM_DATE_WINDOW_FIELD = Object.freeze({
|