@aglyn/aglyn 1.4.0 → 1.6.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.
Files changed (31) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/business-details.d.ts +93 -0
  3. package/src/lib/app-utils/business-details.js +145 -0
  4. package/src/lib/app-utils/business-details.js.map +1 -0
  5. package/src/lib/app-utils/business-profile.d.ts +20 -3
  6. package/src/lib/app-utils/business-profile.js +31 -7
  7. package/src/lib/app-utils/business-profile.js.map +1 -1
  8. package/src/lib/app-utils/content-authors.d.ts +2 -0
  9. package/src/lib/app-utils/content-authors.js.map +1 -1
  10. package/src/lib/app-utils/docs-help-sections.generated.js +0 -1
  11. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  12. package/src/lib/app-utils/docs-help.generated.js +0 -1
  13. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  14. package/src/lib/app-utils/docs-index.generated.js +15 -15
  15. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  16. package/src/lib/app-utils/health-report.d.ts +39 -0
  17. package/src/lib/app-utils/health-report.js +41 -0
  18. package/src/lib/app-utils/health-report.js.map +1 -1
  19. package/src/lib/app-utils/host-tokens.d.ts +53 -11
  20. package/src/lib/app-utils/host-tokens.js +173 -18
  21. package/src/lib/app-utils/host-tokens.js.map +1 -1
  22. package/src/lib/app-utils/site-email-chrome.js +3 -0
  23. package/src/lib/app-utils/site-email-chrome.js.map +1 -1
  24. package/src/lib/app-utils/site-entity-json-ld.js +17 -2
  25. package/src/lib/app-utils/site-entity-json-ld.js.map +1 -1
  26. package/src/lib/app-utils/weekly-summary.d.ts +15 -4
  27. package/src/lib/app-utils/weekly-summary.js +76 -21
  28. package/src/lib/app-utils/weekly-summary.js.map +1 -1
  29. package/src/lib/plugin-manager/plugin-figures.d.ts +22 -2
  30. package/src/lib/plugin-manager/plugin-figures.js +5 -0
  31. package/src/lib/plugin-manager/plugin-figures.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-entity-json-ld.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type ContentAuthorImageContext,\n type HostSeoEntity,\n type SiteEntityHost,\n AUTHOR_NAME_MAX_LENGTH,\n SITE_ENTITY_FRAGMENT,\n contentAuthorSchemaType,\n hostSeoEntityImageJsonLd,\n siteProfileUrls,\n} from './content-authors'\nimport {\n type LocalBusinessType,\n PAYMENT_ACCEPTED_MAX_LENGTH,\n PRICE_RANGE_MAX_LENGTH,\n localBusinessType,\n normalizeAreaServed,\n parseOpeningHours,\n} from './local-business'\n\n/*\n * The SITE entity's JSON-LD: the nested `publisher` and the standalone node.\n *\n * ⛔ Kept apart from `content-authors`, which the compose pipeline reads and\n * therefore ships whole in the site runtime a published page downloads\n * (`check:tenant-wire-weight`). Only the tenant page's server render calls\n * these, and the LocalBusiness allow-list and hours parser they carry\n * (AGL-3383) have no business in a visitor's bundle. Reached through\n * `@aglyn/aglyn/server` only.\n */\n\n/** `content-authors`' trim-and-cap, for the fields this module reads. */\nconst text = (value: unknown, max = AUTHOR_NAME_MAX_LENGTH): string =>\n typeof value === 'string' ? value.trim().slice(0, max) : ''\n\n/**\n * The `@type` the SITE entity publishes under — {@link contentAuthorSchemaType}\n * with one refinement (AGL-3383): an entity that is not a Person and names a\n * business type on the allow-list publishes as that type.\n *\n * Person wins over a business type, because `schema.org` gives a Person none\n * of the properties a business type exists to carry. The stored `type` stays\n * Organization or Person either way; every LocalBusiness subtype IS an\n * Organization, so a consumer reading this as one is still right.\n *\n * Shared by the standalone node and the nested `publisher`, which carry the\n * same `@id` and must therefore not disagree about what they are.\n */\nexport function siteEntitySchemaType(\n entity: HostSeoEntity | null | undefined,\n): 'Person' | 'Organization' | LocalBusinessType {\n const base = contentAuthorSchemaType(entity?.type)\n if (base === 'Person') return base\n return localBusinessType(entity?.businessType) ?? base\n}\n\n/**\n * `schema.org` JSON-LD for the SITE entity (`host.seo.entity`) — the value\n * `Article.publisher` and `WebSite.publisher` are built from.\n *\n * Lives beside {@link contentAuthorJsonLd} on purpose (AGL-2486): a site\n * entity and a post author answer the same question about two different\n * subjects, and the reason the Person branch was broken for two years is that\n * the answer was written inline at its one call site where nothing could\n * test it. One module, two entry points, one `Person`/`Organization`\n * decision — {@link contentAuthorSchemaType}.\n *\n * `logo` is emitted verbatim on BOTH branches, unchanged from what the tenant\n * has always published. It is `host.seo.entity.logo`, a plain URL field on\n * the Setup form rather than a media-picker target, and re-keying it to\n * `image` for a Person would change the publisher block on every page of\n * every site that set one — a separate decision from this one.\n *\n * Given the site's origin, the node carries the standalone entity's `@id`\n * (AGL-3398). Without it a consumer reads this name-only node as a SECOND\n * entity: Google's Rich Results Test listed a site's LocalBusiness twice, the\n * nested one missing telephone, address, price range and image. With it, the\n * two are one entity described in two places.\n */\nexport function hostSeoEntityJsonLd(\n entity: HostSeoEntity | null | undefined,\n context?: { origin?: string },\n): Record<string, unknown> | undefined {\n const name = text(entity?.name, 400)\n if (!name) return undefined\n const origin = context?.origin?.replace(/\\/+$/, '') ?? ''\n return {\n '@type': siteEntitySchemaType(entity),\n ...(origin ? { '@id': `${origin}/${SITE_ENTITY_FRAGMENT}` } : {}),\n name,\n }\n}\n\n/**\n * The site's publisher as a STANDALONE, fully populated `schema.org` node\n * (AGL-2716).\n *\n * ## Why this exists next to {@link hostSeoEntityJsonLd}\n *\n * That function builds the value `publisher` takes: a `@type` and a `name`,\n * nested inside a `WebSite` or an `Article`, gated on the author having filled\n * in the Entity form. It is deliberately narrow, and every call site nests it.\n *\n * A consumer asking \"who runs this site, and how do I reach them\" — an AI\n * assistant answering a contact question, a readiness audit checking whether a\n * business is identifiable — looks for a TOP-LEVEL node of type `Organization`\n * carrying `name`, `description`, `contactPoint` and `address`. A publisher\n * nested two levels inside a `WebSite` answers a different question, and a\n * publisher that is absent because nobody filled in a form answers none.\n *\n * So this one:\n *\n * - is emitted as its own `<script type=\"application/ld+json\">`, at the top\n * level, where it can be found without walking into another node;\n * - FALLS BACK to the site's own identity when the Entity form is empty, so\n * every site on the platform publishes a complete entity rather than only\n * the sites whose author found the form;\n * - carries the contact and address fields, which are what turn \"a name\" into\n * \"a business a consumer can verify\".\n *\n * ## Why the fallback is safe\n *\n * It changes nothing that already exists: `hostSeoEntityJsonLd` still gates on\n * `entity.name`, so `publisher` appears exactly where it appeared before. The\n * fallback only decides what THIS node says, and a site's display name is its\n * publisher's name on the overwhelming majority of sites — the two differ when\n * a company's trading name differs from its site's, which is precisely the case\n * the Entity form exists to express.\n *\n * ## `@id`\n *\n * Both this node and the nested `publisher` carry the same `@id` when an\n * origin is known, so a consumer merges them into one entity instead of\n * reading a site that names its publisher twice with different detail.\n *\n * Returns `undefined` only when there is no name to be had from anywhere —\n * a host document with no entity, no display name and no SEO title.\n */\nexport function siteEntityJsonLd(\n host: SiteEntityHost | null | undefined,\n context?: ContentAuthorImageContext,\n): Record<string, unknown> | undefined {\n const entity = host?.seo?.entity ?? undefined\n const name =\n text(entity?.name, 400) ||\n text(host?.displayName, 400) ||\n text(host?.seo?.title, 400)\n if (!name) return undefined\n\n const origin = context?.origin?.replace(/\\/+$/, '') ?? ''\n const description =\n text(entity?.description, 800) || text(host?.seo?.description, 800)\n const url = text(entity?.url, 800) || origin\n\n /*\n `sameAs` is de-duplicated and https-only, matching the author serializer:\n a profile URL that is not fetchable teaches a consumer nothing, and the\n same profile listed twice reads as two identities.\n\n Through `siteProfileUrls` (AGL-3148) so the site's rendered social links\n count as profiles it claims, rather than only the SEO field that no host\n on the platform had filled in.\n */\n const sameAs = siteProfileUrls(host)\n\n /*\n A contactPoint needs something to contact. `contactType` alone is a label\n on nothing, so the point is emitted only when an address or a number is\n present — `schema.org` requires neither, and a consumer that finds a\n ContactPoint with no channel has been told less than it would learn from\n its absence.\n */\n const email = text(entity?.email, 320)\n const telephone = text(entity?.telephone, 64)\n const contactType = text(entity?.contactType, 120) || 'customer support'\n const contactPoint =\n email || telephone\n ? {\n '@type': 'ContactPoint',\n contactType,\n ...(email ? { email } : {}),\n ...(telephone ? { telephone } : {}),\n }\n : undefined\n\n const addressFields = {\n streetAddress: text(entity?.address?.streetAddress, 200),\n addressLocality: text(entity?.address?.addressLocality, 120),\n addressRegion: text(entity?.address?.addressRegion, 120),\n postalCode: text(entity?.address?.postalCode, 40),\n addressCountry: text(entity?.address?.addressCountry, 120),\n }\n const address = Object.entries(addressFields).filter(([, value]) => value)\n const schemaType = siteEntitySchemaType(entity)\n const picture = hostSeoEntityImageJsonLd(entity, context)\n const business =\n schemaType !== 'Person' && schemaType !== 'Organization'\n ? localBusinessJsonLd(entity, telephone, picture.logo)\n : {}\n\n return {\n '@context': 'https://schema.org',\n '@type': schemaType,\n ...(origin ? { '@id': `${origin}/${SITE_ENTITY_FRAGMENT}` } : {}),\n name,\n ...(description ? { description } : {}),\n ...(url ? { url } : {}),\n // `logo` for an Organization, `image` for a Person — the one field whose\n // KEY the branch changes. Shared with the nested publisher so the two\n // nodes cannot describe the same entity with different pictures.\n ...picture,\n ...(sameAs.length ? { sameAs } : {}),\n ...(contactPoint ? { contactPoint } : {}),\n ...(address.length\n ? { address: { '@type': 'PostalAddress', ...Object.fromEntries(address) } }\n : {}),\n ...business,\n }\n}\n\n/**\n * The properties only a LocalBusiness carries (AGL-3383), spread after\n * everything an Organization publishes so an Organization's output is\n * unchanged key for key.\n *\n * - `telephone` on the node itself as well as on its `contactPoint`: a\n * LocalBusiness has the property directly, and it is where a local result\n * reads the number from.\n * - `areaServed` as named `City` places. A service-area business commonly has\n * no street address to publish, and this is what says where it works.\n * - `openingHoursSpecification` from the hours text, invalid lines dropped.\n * - `image`, the entity logo (AGL-3398): Google recommends a picture of a\n * LocalBusiness and reads `image`, not the Organization-only `logo`, which\n * stays as well.\n *\n * Every one of them is omitted when empty, never published as `[]` or `''`.\n */\nfunction localBusinessJsonLd(\n entity: HostSeoEntity | null | undefined,\n telephone: string,\n logo: string | undefined,\n): Record<string, unknown> {\n const areaServed = normalizeAreaServed(entity?.areaServed)\n const hours = parseOpeningHours(entity?.openingHours)\n const priceRange = text(entity?.priceRange, PRICE_RANGE_MAX_LENGTH)\n const paymentAccepted = text(\n entity?.paymentAccepted,\n PAYMENT_ACCEPTED_MAX_LENGTH,\n )\n return {\n ...(telephone ? { telephone } : {}),\n ...(areaServed.length\n ? { areaServed: areaServed.map((name) => ({ '@type': 'City', name })) }\n : {}),\n ...(hours.length\n ? {\n openingHoursSpecification: hours.map((row) => ({\n '@type': 'OpeningHoursSpecification',\n dayOfWeek: row.days,\n opens: row.opens,\n closes: row.closes,\n })),\n }\n : {}),\n ...(priceRange ? { priceRange } : {}),\n ...(paymentAccepted ? { paymentAccepted } : {}),\n ...(logo ? { image: logo } : {}),\n }\n}\n"],"names":["AUTHOR_NAME_MAX_LENGTH","SITE_ENTITY_FRAGMENT","contentAuthorSchemaType","hostSeoEntityImageJsonLd","siteProfileUrls","PAYMENT_ACCEPTED_MAX_LENGTH","PRICE_RANGE_MAX_LENGTH","localBusinessType","normalizeAreaServed","parseOpeningHours","text","value","max","trim","slice","siteEntitySchemaType","entity","base","type","businessType","hostSeoEntityJsonLd","context","name","undefined","origin","replace","siteEntityJsonLd","host","seo","displayName","title","description","url","sameAs","email","telephone","contactType","contactPoint","addressFields","streetAddress","address","addressLocality","addressRegion","postalCode","addressCountry","Object","entries","filter","schemaType","picture","business","localBusinessJsonLd","logo","length","fromEntries","areaServed","hours","openingHours","priceRange","paymentAccepted","map","openingHoursSpecification","row","dayOfWeek","days","opens","closes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AM,GACjB;QAAEE,YAAYA,WAAWK,GAAG,CAAC,CAACtC,OAAU,CAAA;gBAAE,SAAS;gBAAQA;YAAK,CAAA;IAAI,IACpE,CAAC,GACDkC,MAAMH,MAAM,GACZ;QACEQ,2BAA2BL,MAAMI,GAAG,CAAC,CAACE,MAAS,CAAA;gBAC7C,SAAS;gBACTC,WAAWD,IAAIE,IAAI;gBACnBC,OAAOH,IAAIG,KAAK;gBAChBC,QAAQJ,IAAII,MAAM;YACpB,CAAA;IACF,IACA,CAAC,GACDR,aAAa;QAAEA;IAAW,IAAI,CAAC,GAC/BC,kBAAkB;QAAEA;IAAgB,IAAI,CAAC,GACzCP,OAAO;QAAEe,OAAOf;IAAK,IAAI,CAAC;AAElC"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-entity-json-ld.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type ContentAuthorImageContext,\n type HostSeoEntity,\n type SiteEntityHost,\n AUTHOR_NAME_MAX_LENGTH,\n SITE_ENTITY_FRAGMENT,\n contentAuthorSchemaType,\n hostSeoEntityImageJsonLd,\n siteProfileUrls,\n} from './content-authors'\nimport { SITE_SLOGAN_MAX_LENGTH } from './business-details'\nimport { siteContactEmail } from './host-tokens'\nimport {\n type LocalBusinessType,\n PAYMENT_ACCEPTED_MAX_LENGTH,\n PRICE_RANGE_MAX_LENGTH,\n localBusinessType,\n normalizeAreaServed,\n parseOpeningHours,\n} from './local-business'\n\n/*\n * The SITE entity's JSON-LD: the nested `publisher` and the standalone node.\n *\n * ⛔ Kept apart from `content-authors`, which the compose pipeline reads and\n * therefore ships whole in the site runtime a published page downloads\n * (`check:tenant-wire-weight`). Only the tenant page's server render calls\n * these, and the LocalBusiness allow-list and hours parser they carry\n * (AGL-3383) have no business in a visitor's bundle. Reached through\n * `@aglyn/aglyn/server` only.\n */\n\n/** `content-authors`' trim-and-cap, for the fields this module reads. */\nconst text = (value: unknown, max = AUTHOR_NAME_MAX_LENGTH): string =>\n typeof value === 'string' ? value.trim().slice(0, max) : ''\n\n/**\n * The `@type` the SITE entity publishes under — {@link contentAuthorSchemaType}\n * with one refinement (AGL-3383): an entity that is not a Person and names a\n * business type on the allow-list publishes as that type.\n *\n * Person wins over a business type, because `schema.org` gives a Person none\n * of the properties a business type exists to carry. The stored `type` stays\n * Organization or Person either way; every LocalBusiness subtype IS an\n * Organization, so a consumer reading this as one is still right.\n *\n * Shared by the standalone node and the nested `publisher`, which carry the\n * same `@id` and must therefore not disagree about what they are.\n */\nexport function siteEntitySchemaType(\n entity: HostSeoEntity | null | undefined,\n): 'Person' | 'Organization' | LocalBusinessType {\n const base = contentAuthorSchemaType(entity?.type)\n if (base === 'Person') return base\n return localBusinessType(entity?.businessType) ?? base\n}\n\n/**\n * `schema.org` JSON-LD for the SITE entity (`host.seo.entity`) — the value\n * `Article.publisher` and `WebSite.publisher` are built from.\n *\n * Lives beside {@link contentAuthorJsonLd} on purpose (AGL-2486): a site\n * entity and a post author answer the same question about two different\n * subjects, and the reason the Person branch was broken for two years is that\n * the answer was written inline at its one call site where nothing could\n * test it. One module, two entry points, one `Person`/`Organization`\n * decision — {@link contentAuthorSchemaType}.\n *\n * `logo` is emitted verbatim on BOTH branches, unchanged from what the tenant\n * has always published. It is `host.seo.entity.logo`, a plain URL field on\n * the Setup form rather than a media-picker target, and re-keying it to\n * `image` for a Person would change the publisher block on every page of\n * every site that set one — a separate decision from this one.\n *\n * Given the site's origin, the node carries the standalone entity's `@id`\n * (AGL-3398). Without it a consumer reads this name-only node as a SECOND\n * entity: Google's Rich Results Test listed a site's LocalBusiness twice, the\n * nested one missing telephone, address, price range and image. With it, the\n * two are one entity described in two places.\n */\nexport function hostSeoEntityJsonLd(\n entity: HostSeoEntity | null | undefined,\n context?: { origin?: string },\n): Record<string, unknown> | undefined {\n const name = text(entity?.name, 400)\n if (!name) return undefined\n const origin = context?.origin?.replace(/\\/+$/, '') ?? ''\n return {\n '@type': siteEntitySchemaType(entity),\n ...(origin ? { '@id': `${origin}/${SITE_ENTITY_FRAGMENT}` } : {}),\n name,\n }\n}\n\n/**\n * The site's publisher as a STANDALONE, fully populated `schema.org` node\n * (AGL-2716).\n *\n * ## Why this exists next to {@link hostSeoEntityJsonLd}\n *\n * That function builds the value `publisher` takes: a `@type` and a `name`,\n * nested inside a `WebSite` or an `Article`, gated on the author having filled\n * in the Entity form. It is deliberately narrow, and every call site nests it.\n *\n * A consumer asking \"who runs this site, and how do I reach them\" — an AI\n * assistant answering a contact question, a readiness audit checking whether a\n * business is identifiable — looks for a TOP-LEVEL node of type `Organization`\n * carrying `name`, `description`, `contactPoint` and `address`. A publisher\n * nested two levels inside a `WebSite` answers a different question, and a\n * publisher that is absent because nobody filled in a form answers none.\n *\n * So this one:\n *\n * - is emitted as its own `<script type=\"application/ld+json\">`, at the top\n * level, where it can be found without walking into another node;\n * - FALLS BACK to the site's own identity when the Entity form is empty, so\n * every site on the platform publishes a complete entity rather than only\n * the sites whose author found the form;\n * - carries the contact and address fields, which are what turn \"a name\" into\n * \"a business a consumer can verify\".\n *\n * ## Why the fallback is safe\n *\n * It changes nothing that already exists: `hostSeoEntityJsonLd` still gates on\n * `entity.name`, so `publisher` appears exactly where it appeared before. The\n * fallback only decides what THIS node says, and a site's display name is its\n * publisher's name on the overwhelming majority of sites — the two differ when\n * a company's trading name differs from its site's, which is precisely the case\n * the Entity form exists to express.\n *\n * ## `@id`\n *\n * Both this node and the nested `publisher` carry the same `@id` when an\n * origin is known, so a consumer merges them into one entity instead of\n * reading a site that names its publisher twice with different detail.\n *\n * Returns `undefined` only when there is no name to be had from anywhere —\n * a host document with no entity, no display name and no SEO title.\n */\nexport function siteEntityJsonLd(\n host: SiteEntityHost | null | undefined,\n context?: ContentAuthorImageContext,\n): Record<string, unknown> | undefined {\n const entity = host?.seo?.entity ?? undefined\n const name =\n text(entity?.name, 400) ||\n text(host?.displayName, 400) ||\n text(host?.seo?.title, 400)\n if (!name) return undefined\n\n const origin = context?.origin?.replace(/\\/+$/, '') ?? ''\n const description =\n text(entity?.description, 800) || text(host?.seo?.description, 800)\n const url = text(entity?.url, 800) || origin\n\n /*\n `sameAs` is de-duplicated and https-only, matching the author serializer:\n a profile URL that is not fetchable teaches a consumer nothing, and the\n same profile listed twice reads as two identities.\n\n Through `siteProfileUrls` (AGL-3148) so the site's rendered social links\n count as profiles it claims, rather than only the SEO field that no host\n on the platform had filled in.\n */\n const sameAs = siteProfileUrls(host)\n\n /*\n A contactPoint needs something to contact. `contactType` alone is a label\n on nothing, so the point is emitted only when an address or a number is\n present — `schema.org` requires neither, and a consumer that finds a\n ContactPoint with no channel has been told less than it would learn from\n its absence.\n\n The email is the site's one email (AGL-4136): what Setup → Business\n profile saves to the entity, else the older one-block copy, so a site\n whose email lives only there still says how to reach it.\n */\n // `SiteEntityHost` names only the social links under `business`; the host\n // document handed here is the whole document, older email copy included.\n const email = text(\n siteContactEmail(host as Parameters<typeof siteContactEmail>[0]) ?? '',\n 320,\n )\n const telephone = text(entity?.telephone, 64)\n const contactType = text(entity?.contactType, 120) || 'customer support'\n const contactPoint =\n email || telephone\n ? {\n '@type': 'ContactPoint',\n contactType,\n ...(email ? { email } : {}),\n ...(telephone ? { telephone } : {}),\n }\n : undefined\n\n const addressFields = {\n streetAddress: text(entity?.address?.streetAddress, 200),\n addressLocality: text(entity?.address?.addressLocality, 120),\n addressRegion: text(entity?.address?.addressRegion, 120),\n postalCode: text(entity?.address?.postalCode, 40),\n addressCountry: text(entity?.address?.addressCountry, 120),\n }\n const address = Object.entries(addressFields).filter(([, value]) => value)\n const schemaType = siteEntitySchemaType(entity)\n const picture = hostSeoEntityImageJsonLd(entity, context)\n /*\n The business's slogan from Setup → Business profile (AGL-4136). `slogan` is an\n Organization property, which every LocalBusiness type inherits; a Person\n has none, so a site published by a person never carries it.\n */\n const slogan =\n schemaType === 'Person' ? '' : text(entity?.slogan, SITE_SLOGAN_MAX_LENGTH)\n const business =\n schemaType !== 'Person' && schemaType !== 'Organization'\n ? localBusinessJsonLd(entity, telephone, picture.logo)\n : {}\n\n return {\n '@context': 'https://schema.org',\n '@type': schemaType,\n ...(origin ? { '@id': `${origin}/${SITE_ENTITY_FRAGMENT}` } : {}),\n name,\n ...(description ? { description } : {}),\n ...(slogan ? { slogan } : {}),\n ...(url ? { url } : {}),\n // `logo` for an Organization, `image` for a Person — the one field whose\n // KEY the branch changes. Shared with the nested publisher so the two\n // nodes cannot describe the same entity with different pictures.\n ...picture,\n ...(sameAs.length ? { sameAs } : {}),\n ...(contactPoint ? { contactPoint } : {}),\n ...(address.length\n ? { address: { '@type': 'PostalAddress', ...Object.fromEntries(address) } }\n : {}),\n ...business,\n }\n}\n\n/**\n * The properties only a LocalBusiness carries (AGL-3383), spread after\n * everything an Organization publishes so an Organization's output is\n * unchanged key for key.\n *\n * - `telephone` on the node itself as well as on its `contactPoint`: a\n * LocalBusiness has the property directly, and it is where a local result\n * reads the number from.\n * - `areaServed` as named `City` places. A service-area business commonly has\n * no street address to publish, and this is what says where it works.\n * - `openingHoursSpecification` from the hours text, invalid lines dropped.\n * - `image`, the entity logo (AGL-3398): Google recommends a picture of a\n * LocalBusiness and reads `image`, not the Organization-only `logo`, which\n * stays as well.\n *\n * Every one of them is omitted when empty, never published as `[]` or `''`.\n */\nfunction localBusinessJsonLd(\n entity: HostSeoEntity | null | undefined,\n telephone: string,\n logo: string | undefined,\n): Record<string, unknown> {\n const areaServed = normalizeAreaServed(entity?.areaServed)\n const hours = parseOpeningHours(entity?.openingHours)\n const priceRange = text(entity?.priceRange, PRICE_RANGE_MAX_LENGTH)\n const paymentAccepted = text(\n entity?.paymentAccepted,\n PAYMENT_ACCEPTED_MAX_LENGTH,\n )\n return {\n ...(telephone ? { telephone } : {}),\n ...(areaServed.length\n ? { areaServed: areaServed.map((name) => ({ '@type': 'City', name })) }\n : {}),\n ...(hours.length\n ? {\n openingHoursSpecification: hours.map((row) => ({\n '@type': 'OpeningHoursSpecification',\n dayOfWeek: row.days,\n opens: row.opens,\n closes: row.closes,\n })),\n }\n : {}),\n ...(priceRange ? { priceRange } : {}),\n ...(paymentAccepted ? { paymentAccepted } : {}),\n ...(logo ? { image: logo } : {}),\n }\n}\n"],"names":["AUTHOR_NAME_MAX_LENGTH","SITE_ENTITY_FRAGMENT","contentAuthorSchemaType","hostSeoEntityImageJsonLd","siteProfileUrls","SITE_SLOGAN_MAX_LENGTH","siteContactEmail","PAYMENT_ACCEPTED_MAX_LENGTH","PRICE_RANGE_MAX_LENGTH","localBusinessType","normalizeAreaServed","parseOpeningHours","text","value","max","trim","slice","siteEntitySchemaType","entity","base","type","businessType","hostSeoEntityJsonLd","context","name","undefined","origin","replace","siteEntityJsonLd","host","seo","displayName","title","description","url","sameAs","email","telephone","contactType","contactPoint","addressFields","streetAddress","address","addressLocality","addressRegion","postalCode","addressCountry","Object","entries","filter","schemaType","picture","slogan","business","localBusinessJsonLd","logo","length","fromEntries","areaServed","hours","openingHours","priceRange","paymentAccepted","map","openingHoursSpecification","row","dayOfWeek","days","opens","closes","image"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAIEA,sBAAsB,EACtBC,oBAAoB,EACpBC,uBAAuB,EACvBC,wBAAwB,EACxBC,eAAe,QACV,uBAAmB;AAC1B,SAASC,sBAAsB,QAAQ,wBAAoB;AAC3D,SAASC,gBAAgB,QAAQ,mBAAe;AAChD,SAEEC,2BAA2B,EAC3BC,sBAAsB,EACtBC,iBAAiB,EACjBC,mBAAmB,EACnBC,iBAAiB,QACZ,sBAAkB;AAEzB;;;;;;;;;CASC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AE,SAAS;gBAAQA;YAAK,CAAA;IAAI,IACpE,CAAC,GACDmC,MAAMH,MAAM,GACZ;QACEQ,2BAA2BL,MAAMI,GAAG,CAAC,CAACE,MAAS,CAAA;gBAC7C,SAAS;gBACTC,WAAWD,IAAIE,IAAI;gBACnBC,OAAOH,IAAIG,KAAK;gBAChBC,QAAQJ,IAAII,MAAM;YACpB,CAAA;IACF,IACA,CAAC,GACDR,aAAa;QAAEA;IAAW,IAAI,CAAC,GAC/BC,kBAAkB;QAAEA;IAAgB,IAAI,CAAC,GACzCP,OAAO;QAAEe,OAAOf;IAAK,IAAI,CAAC;AAElC"}
@@ -76,11 +76,19 @@ export declare function figureStat(table: PluginFigureTable, row: PluginFigureRo
76
76
  many: string;
77
77
  };
78
78
  }): PluginFigureSummaryStat;
79
- /** The named rows with the most of `key`, as ranked rows; `[]` when none has any. */
79
+ /** The named rows with the most of `key`, as ranked rows with their change; `[]` when none has any. */
80
80
  export declare function figureRanked(table: PluginFigureTable, nameKey: string, key: string, rows?: readonly PluginFigureRow[]): Array<{
81
81
  label: string;
82
82
  value: string;
83
+ change?: number;
83
84
  }>;
85
+ /** A table of days as a chart, oldest first, the busiest marked; `[]` for a week with nothing in it. */
86
+ export declare function figureBars(table: PluginFigureTable, dayKey: string, key: string): NonNullable<PluginFigureSummaryPart['bars']>;
87
+ /** A row's label as a person reads it, and the page it names, when it names one. */
88
+ export declare function weeklySummaryRowLink(label: string, siteUrl: string | null): {
89
+ label: string;
90
+ url: string | null;
91
+ };
84
92
  /** "1 order", "18 orders". */
85
93
  export declare function figurePlural(count: number, one: string, many: string): string;
86
94
  /** One site's figures for the week. */
@@ -149,7 +157,7 @@ export interface WeeklySummarySectionBar {
149
157
  display: string;
150
158
  marked: boolean;
151
159
  }
152
- /** One topic of an AI digest, told once: what stood out, and the figures behind it. */
160
+ /** One topic of a weekly email, told once: what stood out, and the figures behind it. */
153
161
  export interface WeeklySummarySection {
154
162
  title: string;
155
163
  /** Where the figures can be seen in full. */
@@ -162,13 +170,14 @@ export interface WeeklySummarySection {
162
170
  headline: string | null;
163
171
  text: string | null;
164
172
  }>;
173
+ stats?: readonly PluginFigureSummaryStat[];
165
174
  rows?: readonly WeeklySummarySectionRow[];
166
175
  bars?: readonly WeeklySummarySectionBar[];
167
176
  }
168
177
  /** Tiles on their own, for an email that leads with its headline figures. */
169
178
  export declare function weeklySummaryTilesHtml(stats: readonly PluginFigureSummaryStat[], colors: WeeklySummaryColors): string;
170
- /** An AI digest's topics, a hairline between them. */
171
- export declare function weeklySummarySectionsHtml(sections: readonly WeeklySummarySection[], colors: WeeklySummaryColors): string;
179
+ /** A weekly email's topics, a hairline between them; `following` when something already sits above the first. */
180
+ export declare function weeklySummarySectionsHtml(sections: readonly WeeklySummarySection[], colors: WeeklySummaryColors, following?: boolean): string;
172
181
  /** The small print under the button, with its one link. */
173
182
  export declare function weeklySummaryFootnoteHtml(text: string, link: {
174
183
  label: string;
@@ -183,6 +192,8 @@ export interface WeeklySummaryEmail {
183
192
  period: string;
184
193
  /** The figures, drawn. */
185
194
  html: string;
195
+ /** The small print under the button. */
196
+ footnote: string;
186
197
  /** The whole email as plain text, closing line included. */
187
198
  text: string;
188
199
  buttonLabel: string;
@@ -105,15 +105,38 @@ const ISO_DAY = /\b\d{4}-\d{2}-\d{2}\b/g;
105
105
  }, options.total)
106
106
  } : {});
107
107
  }
108
- /** The named rows with the most of `key`, as ranked rows; `[]` when none has any. */ export function figureRanked(table, nameKey, key, rows = table.rows) {
108
+ /** The named rows with the most of `key`, as ranked rows with their change; `[]` when none has any. */ export function figureRanked(table, nameKey, key, rows = table.rows) {
109
109
  return rows.filter((row)=>typeof row[nameKey] === 'string' && figureCount(row[key]) > 0).slice(0, WEEKLY_SUMMARY_TOP_ROWS).map((row)=>{
110
110
  var _row_key;
111
- return {
111
+ const change = row['change'];
112
+ return _extends({
112
113
  label: String(row[nameKey]),
113
114
  value: pluginFigureCellText(table, key, (_row_key = row[key]) != null ? _row_key : 0)
115
+ }, typeof change === 'number' ? {
116
+ change
117
+ } : {});
118
+ });
119
+ }
120
+ /** A table of days as a chart, oldest first, the busiest marked; `[]` for a week with nothing in it. */ export function figureBars(table, dayKey, key) {
121
+ const most = Math.max(...table.rows.map((row)=>figureCount(row[key])), 0);
122
+ if (!most) return [];
123
+ return table.rows.map((row)=>{
124
+ var _row_key;
125
+ return {
126
+ label: weeklySummaryWeekday(String(row[dayKey])),
127
+ value: figureCount(row[key]),
128
+ display: pluginFigureCellText(table, key, (_row_key = row[key]) != null ? _row_key : 0),
129
+ marked: figureCount(row[key]) === most
114
130
  };
115
131
  });
116
132
  }
133
+ /** A row's label as a person reads it, and the page it names, when it names one. */ export function weeklySummaryRowLink(label, siteUrl) {
134
+ const page = label.startsWith('/');
135
+ return {
136
+ label: label === '/' ? 'Home' : label,
137
+ url: page && siteUrl ? `${siteUrl}${label === '/' ? '' : label}` : null
138
+ };
139
+ }
117
140
  /** "1 order", "18 orders". */ export function figurePlural(count, one, many) {
118
141
  return `${count.toLocaleString('en-US')} ${count === 1 ? one : many}`;
119
142
  }
@@ -218,10 +241,6 @@ function changeHtml(change, colors) {
218
241
  });
219
242
  return `<table role="presentation" style="width:100%;border-collapse:separate;border-spacing:0;table-layout:fixed;">${rows.join('')}</table>`;
220
243
  }
221
- /** A ranked list: the label left, its figure right, a hairline between. */ function rowsHtml(rows, colors) {
222
- const trs = rows.map((row, index)=>`<tr>` + `<td style="font-family:${FONT};font-size:14px;line-height:1.4;color:${colors.text};padding:8px 12px 8px 0;` + `${index < rows.length - 1 ? `border-bottom:1px solid ${colors.border};` : ''}word-break:break-word;">${unlinked(row.label)}</td>` + `<td style="font-family:${FONT};font-size:14px;line-height:1.4;font-weight:600;color:${colors.text};padding:8px 0;text-align:right;white-space:nowrap;` + `${index < rows.length - 1 ? `border-bottom:1px solid ${colors.border};` : ''}">${esc(row.value)}</td>` + `</tr>`);
223
- return `<table role="presentation" style="width:100%;border-collapse:collapse;">${trs.join('')}</table>`;
224
- }
225
244
  function sectionTitleHtml(title, colors) {
226
245
  return `<div style="font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;` + `text-transform:uppercase;color:${colors.muted};padding:0 0 8px;">${esc(title)}</div>`;
227
246
  }
@@ -259,20 +278,36 @@ function sectionRowsHtml(rows, colors) {
259
278
  return `<table role="presentation" style="width:100%;border-collapse:collapse;margin-top:8px;">${trs.join('')}</table>`;
260
279
  }
261
280
  function sectionHtml(section, colors, first) {
262
- var _section_rows, _section_bars;
281
+ var _section_stats, _section_rows, _section_bars;
263
282
  const link = section.link ? `<td style="padding:0;text-align:right;vertical-align:baseline;white-space:nowrap;">` + `<a href="${esc(section.link.url)}" style="font-family:${FONT};font-size:13px;line-height:1.4;font-weight:600;color:${colors.link};text-decoration:none;">${esc(section.link.label)}&nbsp;→</a>` + `</td>` : '';
264
283
  const points = section.points.map((point)=>`<div style="padding:6px 0 0;">` + (point.headline ? `<div style="font-family:${FONT};font-size:16px;line-height:1.35;font-weight:700;color:${colors.text};">${unlinked(point.headline)}</div>` : '') + (point.text ? `<div style="font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.muted};">${figuresHtml(point.text, colors)}</div>` : '') + `</div>`);
265
- return `<div style="padding:${first ? '8px' : '18px'} 0 18px;${first ? '' : `border-top:1px solid ${colors.border};`}">` + `<table role="presentation" style="width:100%;border-collapse:collapse;"><tr>` + `<td style="font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:${colors.muted};padding:0;">${esc(section.title)}</td>` + link + `</tr></table>` + points.join('') + (((_section_rows = section.rows) == null ? void 0 : _section_rows.length) ? sectionRowsHtml(section.rows, colors) : '') + (((_section_bars = section.bars) == null ? void 0 : _section_bars.length) ? sectionBarsHtml(section.bars, colors) : '') + `</div>`;
284
+ return `<div style="padding:${first ? '8px' : '18px'} 0 18px;${first ? '' : `border-top:1px solid ${colors.border};`}">` + `<table role="presentation" style="width:100%;border-collapse:collapse;"><tr>` + `<td style="font-family:${FONT};font-size:12px;line-height:1.4;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:${colors.muted};padding:0;">${esc(section.title)}</td>` + link + `</tr></table>` + points.join('') + (((_section_stats = section.stats) == null ? void 0 : _section_stats.length) ? `<div style="padding:8px 0 0;">${tilesHtml(section.stats, colors)}</div>` : '') + (((_section_rows = section.rows) == null ? void 0 : _section_rows.length) ? sectionRowsHtml(section.rows, colors) : '') + (((_section_bars = section.bars) == null ? void 0 : _section_bars.length) ? sectionBarsHtml(section.bars, colors) : '') + `</div>`;
266
285
  }
267
- /** An AI digest's topics, a hairline between them. */ export function weeklySummarySectionsHtml(sections, colors) {
268
- return sections.map((section, index)=>sectionHtml(section, colors, index === 0)).join('');
286
+ /** A weekly email's topics, a hairline between them; `following` when something already sits above the first. */ export function weeklySummarySectionsHtml(sections, colors, following = false) {
287
+ return sections.map((section, index)=>sectionHtml(section, colors, index === 0 && !following)).join('');
269
288
  }
270
289
  /** The small print under the button, with its one link. */ export function weeklySummaryFootnoteHtml(text, link, colors) {
271
290
  return `<div style="font-family:${FONT};font-size:12px;line-height:1.5;color:${colors.muted};padding:12px 0 0;">` + esc(text) + (link ? ` <a href="${esc(link.url)}" style="color:${colors.link};text-decoration:underline;">${esc(link.label)}</a>` : '') + `</div>`;
272
291
  }
273
- function partHtml(part, colors) {
274
- var _part_stats, _part_rows;
275
- return `<div style="padding:16px 0 8px;">` + sectionTitleHtml(part.title, colors) + (part.note ? `<div style="font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:0 0 8px;">${esc(part.note)}</div>` : '') + (((_part_stats = part.stats) == null ? void 0 : _part_stats.length) ? tilesHtml(part.stats, colors) : '') + (((_part_rows = part.rows) == null ? void 0 : _part_rows.length) ? rowsHtml(part.rows, colors) : '') + `</div>`;
292
+ /** A reader's part as a section of the email, its page rows linked to the site. */ function partSection(part, siteUrl) {
293
+ var _part_link;
294
+ var _part_stats, _part_rows, _part_bars;
295
+ return _extends({
296
+ title: part.title,
297
+ link: (_part_link = part.link) != null ? _part_link : null,
298
+ points: part.note ? [
299
+ {
300
+ headline: null,
301
+ text: part.note
302
+ }
303
+ ] : []
304
+ }, ((_part_stats = part.stats) == null ? void 0 : _part_stats.length) ? {
305
+ stats: part.stats
306
+ } : {}, ((_part_rows = part.rows) == null ? void 0 : _part_rows.length) ? {
307
+ rows: part.rows.map((row)=>_extends({}, row, weeklySummaryRowLink(row.label, siteUrl)))
308
+ } : {}, ((_part_bars = part.bars) == null ? void 0 : _part_bars.length) ? {
309
+ bars: part.bars
310
+ } : {});
276
311
  }
277
312
  /** "aglyn.com · Aglyn LLC": which site, linked, and whose. */ function addressHtml(site, workspaceName, colors) {
278
313
  const address = site.address ? `<a href="${esc(site.address.url)}" style="color:${colors.link};text-decoration:underline;font-weight:600;">${esc(site.address.label)}</a>` : `<span style="font-weight:600;">${esc(site.name)}</span>`;
@@ -282,7 +317,7 @@ function insightsHtml(url, colors) {
282
317
  return `<div style="margin:16px 0 0;background-color:${colors.surface};border-left:3px solid ${colors.accent};border-radius:4px;padding:14px 16px;">` + `<div style="font-family:${FONT};font-size:14px;line-height:1.5;font-weight:700;color:${colors.text};">Want to know why the numbers moved?</div>` + `<div style="font-family:${FONT};font-size:14px;line-height:1.5;color:${colors.text};">` + `AI weekly insights explain each site's week in a few plain sentences. ` + `<a href="${esc(url)}" style="color:${colors.link};text-decoration:underline;">Turn them on from Ask about your numbers</a>.` + `</div></div>`;
283
318
  }
284
319
  function partText(part) {
285
- var _part_stats, _part_rows;
320
+ var _part_stats, _part_rows, _part_bars;
286
321
  const lines = [
287
322
  part.title.toUpperCase()
288
323
  ];
@@ -291,9 +326,20 @@ function partText(part) {
291
326
  const said = weeklySummaryChange(stat.change);
292
327
  lines.push(`${stat.label}: ${stat.value}${said ? ` (${said.text})` : ''}`);
293
328
  }
294
- for (const row of (_part_rows = part.rows) != null ? _part_rows : [])lines.push(`- ${row.label}: ${row.value}`);
329
+ for (const row of (_part_rows = part.rows) != null ? _part_rows : []){
330
+ const said = weeklySummaryChange(row.change);
331
+ lines.push(`- ${row.label}: ${row.value}${said ? ` (${said.text})` : ''}`);
332
+ }
333
+ for (const bar of (_part_bars = part.bars) != null ? _part_bars : [])lines.push(`- ${bar.label}: ${bar.display}`);
334
+ if (part.link) lines.push(`${part.link.label}: ${part.link.url}`);
295
335
  return lines;
296
336
  }
337
+ function footnote(input) {
338
+ return weeklySummaryFootnoteHtml('', {
339
+ label: 'Change what you are emailed about',
340
+ url: input.settingsUrl
341
+ }, input.colors);
342
+ }
297
343
  function closing(input) {
298
344
  return [
299
345
  '',
@@ -305,16 +351,21 @@ function closing(input) {
305
351
  * carries the workspace's own parts when this site's email stands in for the
306
352
  * overview, in a workspace with one active site.
307
353
  */ export function composeWeeklySummarySiteEmail(input) {
308
- var _input_workspace, _input_site_url;
354
+ var _input_workspace, _ref, _input_site_url;
355
+ var _input_site_address;
309
356
  const workspace = (_input_workspace = input.workspace) != null ? _input_workspace : [];
310
357
  if (!weeklySummaryHasNews(input.site) && !workspace.length) return null;
311
358
  const lead = headline([
312
359
  input.site
313
360
  ]);
314
361
  const subject = lead ? `${input.site.name} last week: ${lead}` : `${input.site.name} last week`;
315
- const html = addressHtml(input.site, input.workspaceName, input.colors) + input.site.parts.map((part)=>partHtml(part, input.colors)).join('') + (workspace.length ? `<div style="border-top:1px solid ${input.colors.border};margin:16px 0 0;"></div>` + workspace.map((part)=>partHtml(_extends({}, part, {
316
- title: `${input.workspaceName} · ${part.title}`
317
- }), input.colors)).join('') : '') + (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, input.colors) : '');
362
+ const siteUrl = (_ref = (_input_site_address = input.site.address) == null ? void 0 : _input_site_address.url) != null ? _ref : null;
363
+ const html = addressHtml(input.site, input.workspaceName, input.colors) + weeklySummarySectionsHtml([
364
+ ...input.site.parts.map((part)=>partSection(part, siteUrl)),
365
+ ...workspace.map((part)=>partSection(_extends({}, part, {
366
+ title: `${input.workspaceName} · ${part.title}`
367
+ }), null))
368
+ ], input.colors) + (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, input.colors) : '');
318
369
  const text = [
319
370
  `${input.site.name} last week, ${input.periodLabel}. A change in brackets is against the week before.`,
320
371
  `Site: ${input.site.address ? `${input.site.address.label} (${input.site.address.url})` : input.site.name} · ${input.workspaceName}`,
@@ -343,6 +394,7 @@ function closing(input) {
343
394
  title: `${input.site.name} last week`,
344
395
  period: `${input.periodLabel}, compared with the week before`,
345
396
  html,
397
+ footnote: footnote(input),
346
398
  text,
347
399
  buttonLabel: `Open ${input.site.name}`,
348
400
  url: (_input_site_url = input.site.url) != null ? _input_site_url : ''
@@ -376,14 +428,16 @@ function closing(input) {
376
428
  }).join(' · ');
377
429
  const quietCount = input.sites.length - active.length;
378
430
  const quiet = quietCount ? `${figurePlural(quietCount, 'other site', 'other sites')} had nothing to report.` : '';
379
- const sitesHtml = active.length ? `<div style="padding:16px 0 8px;">` + sectionTitleHtml('Your sites', colors) + `<table role="presentation" style="width:100%;border-collapse:collapse;">` + active.map((site, index)=>{
431
+ const sitesHtml = active.length ? `<div style="padding:18px 0 8px;${totalsPart ? `border-top:1px solid ${colors.border};` : ''}">` + sectionTitleHtml('Your sites', colors) + `<table role="presentation" style="width:100%;border-collapse:collapse;">` + active.map((site, index)=>{
380
432
  const border = index < active.length - 1 ? `border-bottom:1px solid ${colors.border};` : '';
381
433
  const name = site.url ? `<a href="${esc(site.url)}" style="color:${colors.link};text-decoration:none;font-weight:700;">${esc(site.name)}</a>` : `<span style="font-weight:700;">${esc(site.name)}</span>`;
382
434
  const line = siteLine(site);
383
435
  const address = site.address ? ` <a href="${esc(site.address.url)}" style="color:${colors.muted};text-decoration:underline;font-size:13px;font-weight:400;">${esc(site.address.label)}</a>` : '';
384
436
  return `<tr><td style="font-family:${FONT};font-size:15px;line-height:1.4;color:${colors.text};padding:10px 0;${border}">` + name + address + (line ? `<div style="font-size:13px;line-height:1.5;color:${colors.muted};">${esc(line)}</div>` : '') + `</td></tr>`;
385
437
  }).join('') + `</table>` + (quiet ? `<div style="font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:4px 0 0;">${esc(quiet)}</div>` : '') + `</div>` : '';
386
- const html = (totalsPart ? partHtml(totalsPart, colors) : '') + sitesHtml + input.workspace.map((part)=>partHtml(part, colors)).join('') + (active.length > 1 ? `<div style="font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:8px 0 0;">Each site's own summary arrives beside this one.</div>` : '') + (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, colors) : '');
438
+ const html = (totalsPart ? weeklySummarySectionsHtml([
439
+ partSection(totalsPart, null)
440
+ ], colors) : '') + sitesHtml + weeklySummarySectionsHtml(input.workspace.map((part)=>partSection(part, null)), colors, Boolean(totalsPart || sitesHtml)) + (active.length > 1 ? `<div style="font-family:${FONT};font-size:13px;line-height:1.5;color:${colors.muted};padding:8px 0 0;">Each site's own summary arrives beside this one.</div>` : '') + (input.aiInsightsUrl ? insightsHtml(input.aiInsightsUrl, colors) : '');
387
441
  const text = [
388
442
  `Here is how ${input.workspaceName} did last week, ${input.periodLabel}. A change in brackets is against the week before.`,
389
443
  ...totalsPart ? [
@@ -413,6 +467,7 @@ function closing(input) {
413
467
  title: `${input.workspaceName} last week`,
414
468
  period: `${input.periodLabel}, compared with the week before`,
415
469
  html,
470
+ footnote: footnote(input),
416
471
  text,
417
472
  buttonLabel: `Open ${input.workspaceName}`,
418
473
  url: input.url