local assets 1/2

This commit is contained in:
lovebird 2025-03-17 18:16:44 +01:00
parent 32b7d4bfed
commit 5720a69acf
13 changed files with 389 additions and 393 deletions

View File

@ -2,6 +2,6 @@
export default new Map([
["src/content/infopages/community.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fcommunity.mdx&astroContentModuleFlag=true")],
["src/content/infopages/contact.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fcontact.mdx&astroContentModuleFlag=true")],
["src/content/infopages/software.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fsoftware.mdx&astroContentModuleFlag=true")],
["src/content/infopages/resources.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fresources.mdx&astroContentModuleFlag=true")]]);
["src/content/infopages/resources.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fresources.mdx&astroContentModuleFlag=true")],
["src/content/infopages/software.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fsoftware.mdx&astroContentModuleFlag=true")]]);

View File

@ -9,15 +9,13 @@ import getBackgroundStyles from "./utils/getBackgroundStyles.js";
export default async function renderImg(props) {
const type = "Img";
if (props.src === undefined) {
props.src = 'https://picsum.photos/640/640'
console.error("The 'src' attribute is required for the 'Img' component.", props)
}
const { filteredProps, transformConfigs } = getFilteredProps(type, props);
const {
src,
alt,
@ -37,8 +35,8 @@ export default async function renderImg(props) {
const artDirectives = [],
fallbackFormat = format,
fadeInTransition = false,
includeSourceFormat = false;
fadeInTransition = true,
includeSourceFormat = true;
const {
img: imgAttributes = {},

View File

@ -33,7 +33,7 @@ export default async function ({
const { path, base, rest, image, imageWidth, imageHeight, imageFormat } =
await getProcessedImage(src, transformConfigs);
await delay(100);
await delay(250);
src = path;
rest.aspect = `${imageWidth / imageHeight}`;
@ -81,23 +81,19 @@ export default async function ({
// Ensure artDirectedImages is an array
const images = Array.isArray(artDirectedImages) ? [...artDirectedImages, mainImage] : [mainImage];
const uuid = crypto.randomBytes(4).toString("hex").toUpperCase();
const returnObject = {
uuid,
images,
};
imagesData.set(hash, returnObject);
//const end = performance.now();
//console.log( `Responsive Image sets generated for ${type} at ${args[0].src} in ${end - start}ms`);
return returnObject;
} catch (error) {
console.error("Error processing images:", error);
debugger
throw error;
}
}

View File

@ -3,7 +3,6 @@ import path from "node:path";
// To strip off params when checking for file on disk.
const paramPattern = /\?.*/;
/**
* getSrcPath allows the use of `src` attributes relative to either the public folder or project root.
*

View File

@ -1,6 +1,5 @@
// @ts-check
import { getSrcPath } from "./getSrcPath.js";
export default async function getSrcset(
src,
base,
@ -15,7 +14,6 @@ export default async function getSrcset(
};
const keys = Object.keys(options);
const params = keys.length
? keys
.map((key) =>
@ -26,14 +24,14 @@ export default async function getSrcset(
.join("")
: "";
const id = `${src}?${params.slice(1)}`;
const id = `${src}?${params.slice(1)}`
const fullPath = await getSrcPath(id);
const { default: load } = await import("../../plugin/hooks/load.js");
// @ts-ignore
const srcset = (await load(fullPath, base)).slice(16, -1);
//console.log("get source set", fullPath, src, id);
const loaded = await load(fullPath, base)
if (!loaded) {
return "";
}
const srcset = loaded.slice(16, -1)
return srcset;
}

View File

@ -1,4 +1,5 @@
// @ts-check
import fs from "node:fs";
import {
builtins,
loadImage,
@ -9,6 +10,9 @@ export {
loadImage
} from "imagetools-core";
export async function getImageDetails(path, width, height, aspect) {
if (!fs.existsSync(path)) {
return null
}
const loadedImage = loadImage(path);
if (aspect && !width && !height) {

View File

@ -65,11 +65,9 @@ export default async function load(id) {
if (raw) {
const testConfig = { ...config };
delete testConfig.raw;
delete testConfig.inline;
delete testConfig.base64;
if (Object.keys(testConfig).length > 0) {
throw new Error(
"If raw is set, no other options can be set except inline and base64"

View File

@ -34,6 +34,10 @@ export const PRODUCT_HUGO_TEMPLATE = './osr/hugo/root.html'
export const PRODUCTS_TARGET_SRC = './src/content/en/retail'
export const PRODUCTS_TARGET = (lang) => `./content/${lang}/products`
// Product assets
export const ASSETS_LOCALE = false
// OSRL - Language
export const IS_DEV = true
export const OSRL_ENV = 'astro-release'

View File

@ -14,7 +14,7 @@ import { sync as mv } from '@polymech/fs/move'
import { logger } from '@/base/index.js'
import { removeArrayValues, removeArrays, removeBufferValues, removeEmptyObjects } from '@/base/objects.js'
import { ITEM_ASSET_URL, PRODUCT_CONFIG, PRODUCT_ROOT, DEFAULT_IMAGE_URL } from '../app/config.js'
import { ITEM_ASSET_URL, PRODUCT_CONFIG, PRODUCT_ROOT, DEFAULT_IMAGE_URL, ASSETS_LOCALE } from '../app/config.js'
import { GalleryImage, MetaJSON } from './images.js'
import { validateFilename, sanitizeFilename } from "@polymech/fs/utils"
@ -42,11 +42,11 @@ export const default_sort = (files: string[]): string[] => {
})
}
export const default_sanitize = (paths: string[]): string[] =>{
export const default_sanitize = (paths: string[]): string[] => {
return paths.map((filePath) => {
const dir = path.dirname(filePath);
const originalFilename = path.basename(filePath);
const sanitizedFilename = sanitizeFilename(originalFilename, { lowercase: false, whitespace: true });
const sanitizedFilename = sanitizeFilename(originalFilename)
if (originalFilename === sanitizedFilename) {
return filePath;
}
@ -75,6 +75,10 @@ export const default_filter = async (url: string) => {
return true
}
export const default_filter_locale = async (url: string) => {
return url && exists(url)
}
export const image_url = async (src, fallback = DEFAULT_IMAGE_URL) => {
let safeSrc = src
try {
@ -133,9 +137,14 @@ export const gallery = async (
))
}
if (!ASSETS_LOCALE) {
galleryFiles = await pMap(galleryFiles, async (f) => (await default_filter(assetUrl(f))) ? f : null, { concurrency: 5 })
galleryFiles = galleryFiles.filter((f) => f !== null)
galleryFiles = default_sort(galleryFiles)
} else {
galleryFiles = galleryFiles.filter(default_filter_locale)
galleryFiles = default_sort(galleryFiles)
}
return await pMap(galleryFiles, async (file: string) => {
const parts = path.parse(file)
@ -171,7 +180,7 @@ export const gallery = async (
delete imageMeta.exif.icc
delete imageMeta.exif.xmp
delete imageMeta.exif.iptc
const src = await image_url(assetUrl(file))
const src = ASSETS_LOCALE ? filePath : await image_url(assetUrl(file))
const ret: GalleryImage =
{
name: path.parse(file).name,

View File

@ -150,17 +150,6 @@ const tracking = config?.tracking?.googleAnalytics
</script>
)}
{ REDIRECT && <script>
const currentPath = window.location.pathname;
if (!/^\/[a-z]{2}(\/|$)/i.test(currentPath)) {
let language = navigator.language
language = language.split('-')[0]
language = "en"
window.location.href = `/${language}`;
}
</script>
<link rel="sitemap" href="/sitemap-index.xml" />
}

View File

@ -5,6 +5,7 @@ import StoreEntries from "@/components/store/StoreEntries.astro"
import CtaTwo from "@/components/cta/CtaTwo.astro"
const allProducts = await getCollection("store")
const locale = Astro.currentLocale || "en"
const REDIRECT = false
---
<BaseLayout>
<CtaTwo />
@ -31,7 +32,7 @@ const locale = Astro.currentLocale || "en"
</div>
</section>
{ <script>
{ REDIRECT && <script>
const currentPath = window.location.pathname;
if (!/^\/[a-z]{2}(\/|$)/i.test(currentPath)) {
let language = navigator.language