collection:projects:)

This commit is contained in:
lovebird 2025-03-11 23:15:32 +01:00
parent be5f321bac
commit 05ecfbf384
7 changed files with 476 additions and 11 deletions

View File

@ -0,0 +1,429 @@
{
"$ref": "#/definitions/projects",
"definitions": {
"projects": {
"type": "object",
"properties": {
"cart_id": {
"type": "string"
},
"code": {
"type": "string"
},
"price": {
"type": "number"
},
"cscartCats": {
"type": "array",
"items": {
"type": "number"
}
},
"cscartId": {
"type": "number"
},
"vendorId": {
"type": "number"
},
"shipping": {
"type": "object",
"properties": {
"price": {
"type": "number"
},
"transit": {
"type": "number"
},
"handling": {
"type": "number"
}
},
"additionalProperties": false,
"default": {
"price": 0,
"transit": 12,
"handling": 2
}
},
"manufacturing": {
"type": "object",
"properties": {
"lead_time": {
"type": "number"
}
},
"additionalProperties": false
},
"replaced_by": {
"type": "string"
},
"alternatives": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"url": {
"type": "string"
},
"type": {
"type": "string"
}
},
"required": [
"name",
"url",
"type"
],
"additionalProperties": false
}
},
"used_by": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/alternatives/items"
}
},
"image": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"url": {
"type": "string"
},
"thumb": {
"type": "string"
},
"responsive": {
"type": "string"
},
"meta": {},
"keywords": {
"type": "array",
"items": {
"type": "string"
}
},
"description": {
"type": "string"
},
"alt": {
"type": "string"
},
"title": {
"type": "string"
},
"height": {
"type": "number"
},
"width": {
"type": "number"
},
"order": {
"type": "number"
},
"exif": {
"type": "object",
"properties": {
"file": {},
"jfif": {},
"exif": {},
"gps": {}
},
"additionalProperties": false
}
},
"required": [
"url"
],
"additionalProperties": false
},
"name": {
"type": "string"
},
"flags": {
"type": "number"
},
"edrawings": {
"type": "string"
},
"cad": {
"type": "array",
"items": {
"type": "object",
"properties": {
"file": {
"type": "string"
},
"name": {
"type": "string"
},
"configuration": {
"type": "string"
},
"step": {
"type": "string"
},
"model": {
"type": "string"
},
"html": {
"type": "string"
}
},
"required": [
"file",
"name",
"configuration"
],
"additionalProperties": false
},
"default": []
},
"showDimensions": {
"type": "boolean"
},
"showParts": {
"type": "boolean"
},
"slug": {
"type": "string"
},
"keywords": {
"type": "string"
},
"meta_keywords": {
"type": "string"
},
"version": {
"type": "string"
},
"versions": {
"type": "object",
"properties": {
"version": {
"type": "string"
},
"up": {
"type": "string"
},
"down": {
"type": "string"
},
"family": {
"type": "string"
},
"sheet": {
"type": "string"
}
},
"additionalProperties": false
},
"status": {
"type": "string"
},
"authors": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"url": {
"type": "string"
}
},
"required": [
"name",
"url"
],
"additionalProperties": false
}
},
"assets": {
"type": "object",
"properties": {
"gallery": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/image"
}
},
"renderings": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/image"
}
},
"components": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/image"
}
},
"configurations": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/image"
}
},
"showcase": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/image"
}
},
"samples": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/image"
}
}
},
"additionalProperties": false,
"default": {
"gallery": [],
"renderings": [],
"components": [],
"configurations": [],
"showcase": [],
"samples": []
}
},
"resources": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/alternatives/items"
},
"default": []
},
"tests": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/alternatives/items"
},
"default": []
},
"download": {
"type": "boolean"
},
"gallery": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"glob": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"glob"
],
"additionalProperties": false
},
"default": {
"renderings": {
"glob": [
"*.+(JPG|jpg|png|PNG|gif)"
]
},
"gallery": {
"glob": [
"*.+(JPG|jpg|png|PNG|gif)"
]
},
"components": {
"glob": [
"*.+(JPG|jpg|png|PNG|gif)"
]
},
"configurations": {
"glob": [
"*.+(JPG|jpg|png|PNG|gif)"
]
},
"showcase": {
"glob": [
"*.+(JPG|jpg|png|PNG|gif)"
]
},
"samples": {
"glob": [
"*.+(JPG|jpg|png|PNG|gif)"
]
}
}
},
"Preview3d": {
"type": "boolean"
},
"howto_categories": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"steps": {},
"sourceLanguage": {
"type": "string"
},
"category": {
"type": "string"
},
"product_dimensions": {
"type": "string"
},
"production": {
"type": "object",
"properties": {
"fusion-folder": {
"type": "string"
},
"nc-folder": {
"type": "string"
},
"cam": {
"type": "array",
"items": {
"$ref": "#/definitions/projects/properties/authors/items"
}
}
},
"required": [
"fusion-folder",
"nc-folder",
"cam"
],
"additionalProperties": false
},
"score": {
"type": "number"
}
},
"required": [
"code",
"manufacturing",
"name",
"slug",
"category"
],
"additionalProperties": true
}
},
"$schema": "http://json-schema.org/draft-07/schema#"
}

8
.astro/content.d.ts vendored
View File

@ -178,6 +178,14 @@ declare module 'astro:content' {
rendered?: RenderedContent;
filePath?: string;
}>;
"projects": Record<string, {
id: string;
body?: string;
collection: "projects";
data: InferEntrySchema<"projects">;
rendered?: RenderedContent;
filePath?: string;
}>;
"resources": Record<string, {
id: string;
render(): Render[".md"];

File diff suppressed because one or more lines are too long

View File

@ -60,6 +60,7 @@ export const TASK_LOG_DIRECTORY = './logs/'
// Task - Retail Config
export const REGISTER_PRODUCT_TASKS = true
export const RETAIL_PRODUCT_BRANCH = 'site'
export const PROJECTS_BRANCH = 'projects'
export const RETAIL_COMPILE_CACHE = false
export const RETAIL_MEDIA_CACHE = true
export const RETAIL_LOG_LEVEL_I18N_PRODUCT_ASSETS = 'info'

View File

@ -1,10 +1,16 @@
import { defineCollection, z } from "astro:content"
import { loader } from './model/component.js'
import { ComponentConfigSchema } from '@polymech/commons/component'
import { RETAIL_PRODUCT_BRANCH, PROJECTS_BRANCH } from 'config/config.js'
import { glob } from 'astro/loaders'
const store = defineCollection({
loader: loader() as any,
loader: loader(RETAIL_PRODUCT_BRANCH) as any,
schema: ComponentConfigSchema.passthrough(),
})
const projects = defineCollection({
loader: loader(PROJECTS_BRANCH) as any,
schema: ComponentConfigSchema.passthrough(),
})
const helpcenter = defineCollection({
@ -35,8 +41,9 @@ const resources = defineCollection({
});
export const collections = {
store: store,
helpcenter: helpcenter,
infopages: infopages,
resources
store,
projects,
resources,
helpcenter,
infopages
};

View File

@ -9,6 +9,7 @@ import { ICADNodeSchema, IComponentConfig } from '@polymech/commons/component'
import { ContentEntryRenderFunction, ContentEntryType } from 'astro'
import { RenderedContent, DataEntry } from "astro:content"
import type { Loader, LoaderContext } from 'astro/loaders'
import {
@ -51,8 +52,7 @@ let loaderCtx: ILoaderContextEx
const renderFunctionByContentType = new WeakMap<ContentEntryType, ContentEntryRenderFunction>();
const filterBranch = (items: { rel: string, config, path }[],
branch: string = RETAIL_PRODUCT_BRANCH) => {
const filterBranch = (items: { rel: string, config, path }[], branch: string) => {
if (!PRODUCT_BRANCHES) {
return items
}
@ -63,7 +63,9 @@ const filterBranch = (items: { rel: string, config, path }[],
return items.filter((item) => branchItems.includes(item.rel))
}
export const items = (opts: {}) => filterBranch(get(`${PRODUCT_ROOT()}/${PRODUCT_GLOB}`, PRODUCT_ROOT(), PFilterValid.marketplace_component))
export const items = (branch: string) =>
filterBranch(get(`${PRODUCT_ROOT()}/${PRODUCT_GLOB}`,
PRODUCT_ROOT(), PFilterValid.marketplace_component), branch)
const onComponent = async (item: IStoreItem, ctx: ILoaderContextEx) => {
@ -261,7 +263,8 @@ const onItem = async (item: IStoreItem, ctx: ILoaderContextEx) => {
data.assets.samples = await gallery('media/samples', data.rel) as []
}
export function loader(): Loader {
export function loader(branch: string): Loader {
const load = async ({
config,
logger,
@ -272,7 +275,7 @@ export function loader(): Loader {
entryTypes }: ILoaderContextEx) => {
store.clear();
let products = items({})
let products = items(branch)
for (const item of products) {
const product: any = item.config
const id = product.slug;

17
sync-polycraft.json Normal file
View File

@ -0,0 +1,17 @@
{
"debug": true,
"matching": [
"src/**",
"*.md",
"*.json",
"*.cjs",
"docs",
"packages/imagetools/**",
"scripts",
"meta/**",
"tests/**",
"*.mjs",
"!node_modules/**",
"!ref/**"
]
}