merchant | jsonld | image urlR

This commit is contained in:
lovebird 2026-02-01 13:46:09 +01:00
parent 21d9543dcd
commit 5ff3ce3d55
10 changed files with 36 additions and 18 deletions

View File

@ -53,8 +53,7 @@
"keyv-file": "^5.1.3",
"object-hash": "3.0.0",
"p-map": "^7.0.3",
"p-timeout": "^6.1.4",
"sharp": "^0.34.1"
"p-timeout": "^6.1.4"
},
"devDependencies": {
"vitest": "^3.2.4"

View File

@ -4,6 +4,7 @@ import {
applyTransforms,
generateTransforms,
} from "imagetools-core";
import sharp from "sharp";
export const getLoadedImage = async (src) => {

View File

@ -35,15 +35,19 @@
"@polymech/i18n": "file:../../../polymech-mono/packages/i18n",
"@polymech/kbot-d": "file:../../../polymech-mono/packages/kbot",
"@polymech/log": "file:../../../polymech-mono/packages/log",
"@types/html-escaper": "^3.0.0",
"@types/yargs": "^17.0.35",
"astro": "^5.13.2",
"exifreader": "^4.31.1",
"find-up": "^7.0.0",
"flowbite": "^3.1.2",
"github-slugger": "^2.0.0",
"glob": "^11.0.3",
"hast-util-select": "^6.0.4",
"hast-util-to-string": "^3.0.1",
"html-entities": "^2.5.2",
"html-escaper": "^3.0.3",
"html-validate": "^8.18.2",
"imagetools": "file:../imagetools_3",
"marked": "^16.1.2",
"mdast-util-to-string": "^4.0.0",
@ -58,14 +62,10 @@
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.2",
"showdown": "^2.1.0",
"tailwindcss": "^4.0.7",
"tslog": "^4.9.3",
"unified": "^11.0.5",
"unist-util-visit": "^5.0.0",
"tailwindcss": "^4.0.7",
"flowbite": "^3.1.2",
"yargs": "^18.0.0",
"html-escaper": "^3.0.3",
"html-validate": "^8.18.2",
"@types/html-escaper": "^3.0.0"
"yargs": "^18.0.0"
}
}
}

View File

@ -22,6 +22,7 @@ export interface ImageSEOData {
export interface GalleryImage {
name?: string
url?: string
urlR?: string
src: string
thumb?: string
responsive?: string

View File

@ -17,7 +17,7 @@ import { sync as read } from '@polymech/fs/read'
import { logger } from './index.js'
import { removeArrayValues, removeArrays, removeBufferValues, removeEmptyObjects } from './objects.js'
import { ITEM_ASSET_URL, PRODUCT_CONFIG, PRODUCT_ROOT, DEFAULT_IMAGE_URL, FILE_SERVER_DEV } from '../app/config.js'
import { ITEM_ASSET_URL, PRODUCT_CONFIG, PRODUCT_ROOT, DEFAULT_IMAGE_URL, FILE_SERVER_DEV, ITEM_ASSET_URL_R } from '../app/config.js'
import { GalleryImage, MetaJSON } from './images.js'
import { env } from './index.js'
@ -320,13 +320,27 @@ export const gallery = async (
))
}
const assetUrlR = (filePath) => {
return sanitizeUri(ITEM_ASSET_URL_R(
{
FILE_SERVER_DEV,
assetPath,
filePath,
ITEM_REL: product,
...profile.variables
}
))
}
const fileBuffer = readFileSync(filePath);
const hash = createHash('md5').update(fileBuffer).digest('hex').substring(0, 8);
const fileBuffer = readFileSync(filePath)
const hash = createHash('md5').update(fileBuffer).digest('hex').substring(0, 8)
const urlR = (await image_url(assetUrlR(file)) || '').replace('/products', '/machines')
const ret: GalleryImage =
{
name: path.parse(file).name,
url: await image_url(assetUrl(file)),
urlR,
src: await image_url(assetUrl(file)),
thumb: assetUrl(`/${parts.name}-thumb.webp`),
responsive: assetUrl(`/webp/${parts.name}.webp`),

View File

@ -16,6 +16,8 @@ const itemData = frontmatter ? await get("json-ld", {} as any, frontmatter,
const meta = config.metadata || { }
let data = itemData || {
"@context": "https://schema.org",
"@type": "Article",

View File

@ -197,13 +197,13 @@ const onItem = async (item: IStoreItem, ctx: ILoaderContextEx) => {
src: data.assets.renderings[0].thumb
})
data.assets.gallery = await gallery('media/gallery', data.rel) as []
data.assets.main_image = (data.assets.gallery as any[]).find((item: any) => item.src.endsWith('latest.jpg'))
data.image = data.assets.main_image || data.assets.gallery[0] || data.assets.renderings[0]
data.assets.showcase = await gallery('media/showcase', data.rel) as []
data.assets.samples = await gallery('media/samples', data.rel) as []
data.assets.screenshots = await gallery('media/screenshots', data.rel) as []
}
export function loader(branch: string): Loader {
const load = async ({

View File

@ -1,5 +1,6 @@
import type { IComponentNode, IComponentConfig } from '@polymech/commons'
import { PolymechInstance } from '../registry.js';
import { ITEM_ASSET_URL_R } from '@/app/config.js';
const config = () => PolymechInstance.getConfig();
interface ProductJsonLD {
@ -36,15 +37,15 @@ export const get = async (node: IComponentNode, component: IComponentConfig, opt
name: config().ecommerce?.brand || config().site.title
}
}
if (component.image?.url) {
jsonLD.image = [component.image.url]
if (component.image?.urlR) {
jsonLD.image = component.image?.urlR
}
if (component.price) {
jsonLD.offers = {
'@type': 'Offer',
price: component.price,
priceCurrency: config().ecommerce?.currencyCode || 'EU',
priceCurrency: config().ecommerce?.currencyCode || 'EUR',
availability: 'https://schema.org/InStock',
url: opts.url || config().site.base_url
}

View File

@ -22,7 +22,7 @@ export const get = async (node: IComponentNode, config: IComponentConfig, opts:
description: config.keywords,
link: node.path,
image_link: config.image?.url,
price: config.price?.toString() + ' USD',
price: config.price?.toString() + ' EUR',
availability: 'in_stock',
brand: 'Polymech',
condition: 'new'

View File

@ -2,7 +2,7 @@
import { get as handleMerchant } from './merchant.js'
import { get as handleJsonLd } from './json-ld.js'
import type { IComponentNode, IComponentConfig } from '@polymech/commons/'
import type { IComponentNode, IComponentConfig } from '@polymech/commons'
export type Handler = (node: IComponentNode, config: IComponentConfig, opts: { url?: string }) => Promise<any>